Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
6a72aa1b
Commit
6a72aa1b
authored
Mar 03, 2015
by
Roman S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to REST API plugin version 1.0.2
parent
090831d3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
686 additions
and
30 deletions
+686
-30
changelog.html
src/plugins/restAPI/changelog.html
+6
-0
plugin.xml
src/plugins/restAPI/plugin.xml
+2
-2
readme.html
src/plugins/restAPI/readme.html
+313
-1
GroupController.java
...ware/openfire/plugin/rest/controller/GroupController.java
+150
-0
UserServiceController.java
...penfire/plugin/rest/controller/UserServiceController.java
+22
-27
GroupEntities.java
...vesoftware/openfire/plugin/rest/entity/GroupEntities.java
+51
-0
GroupEntity.java
...jivesoftware/openfire/plugin/rest/entity/GroupEntity.java
+79
-0
GroupService.java
...vesoftware/openfire/plugin/rest/service/GroupService.java
+61
-0
JerseyWrapper.java
...esoftware/openfire/plugin/rest/service/JerseyWrapper.java
+2
-0
No files found.
src/plugins/restAPI/changelog.html
View file @
6a72aa1b
...
...
@@ -44,6 +44,12 @@
REST API Plugin Changelog
</h1>
<p><b>
1.0.2
</b>
-- March 3rd, 2015
</p>
<ul>
<li>
User will be kicked by a lockout (ban)
</li>
<li>
Added: new endpoints for groups (Get overview over all or specific group and to create, update or delete a group)
</li>
</ul>
<p><b>
1.0.1
</b>
-- February 20th, 2015
</p>
<ul>
<li>
Added possibility to rename a user (Thanks to JustMarried plugin)
</li>
...
...
src/plugins/restAPI/plugin.xml
View file @
6a72aa1b
...
...
@@ -5,8 +5,8 @@
<name>
REST API
</name>
<description>
Allows administration over a RESTful API.
</description>
<author>
Roman Soldatow
</author>
<version>
1.0.
1
</version>
<date>
0
2/20
/2015
</date>
<version>
1.0.
2
</version>
<date>
0
3/03
/2015
</date>
<minServerVersion>
3.9.0
</minServerVersion>
<adminconsole>
...
...
src/plugins/restAPI/readme.html
View file @
6a72aa1b
...
...
@@ -1278,6 +1278,7 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a
href=
"#possible-parameters-3"
>
Possible parameters
</a></li>
<li><a
href=
"#examples-4"
>
Examples
</a><ul>
<li><a
href=
"#xml-example"
>
XML Example
</a></li>
<li><a
href=
"#rename-example"
>
Rename Example
</a></li>
<li><a
href=
"#json-example"
>
JSON Example
</a></li>
</ul>
</li>
...
...
@@ -1400,6 +1401,32 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
</li>
</ul>
</li>
<li><a
href=
"#group-related-rest-endpoints"
>
Group related REST Endpoints
</a><ul>
<li><a
href=
"#retrieve-all-groups"
>
Retrieve all groups
</a><ul>
<li><a
href=
"#examples-26"
>
Examples
</a></li>
</ul>
</li>
<li><a
href=
"#retrieve-a-group"
>
Retrieve a group
</a><ul>
<li><a
href=
"#possible-parameters-24"
>
Possible parameters
</a></li>
<li><a
href=
"#examples-27"
>
Examples
</a></li>
</ul>
</li>
<li><a
href=
"#create-a-group"
>
Create a group
</a><ul>
<li><a
href=
"#examples-28"
>
Examples
</a></li>
</ul>
</li>
<li><a
href=
"#delete-a-group"
>
Delete a group
</a><ul>
<li><a
href=
"#possible-parameters-25"
>
Possible parameters
</a></li>
<li><a
href=
"#examples-29"
>
Examples
</a></li>
</ul>
</li>
<li><a
href=
"#update-a-group"
>
Update a group
</a><ul>
<li><a
href=
"#possible-parameters-26"
>
Possible parameters
</a></li>
<li><a
href=
"#examples-30"
>
Examples
</a></li>
</ul>
</li>
</ul>
</li>
<li><a
href=
"#deprecated-user-service-plugin-readme"
>
(Deprecated) User Service Plugin Readme
</a><ul>
<li><a
href=
"#overview"
>
Overview
</a></li>
<li><a
href=
"#installation-1"
>
Installation
</a></li>
...
...
@@ -1419,6 +1446,7 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<ul>
<li>
Get overview over all or specific user and to create, update or delete a user
</li>
<li>
Get overview over all or specific group and to create, update or delete a group
</li>
<li>
Get overview over all user roster entries and to add, update or delete a roster entry
</li>
<li>
Add user to a group and remove a user from a group
</li>
<li>
Lockout or unlock the user (enable / disable)
</li>
...
...
@@ -1715,6 +1743,8 @@ If you want to create a resource with JSON data format, please add “<strong>Co
</tbody></table>
<h3
id=
"system-property"
>
System Property
</h3>
<table>
...
...
@@ -2001,6 +2031,8 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<p><strong>
Payload:
</strong>
User
<br>
<strong>
Return value:
</strong>
HTTP status 200 (OK)
</p>
<h3
id=
"possible-parameters-3"
>
Possible parameters
</h3>
<table>
...
...
@@ -2063,6 +2095,8 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<p><strong>
Payload:
</strong></p>
<pre
class=
"prettyprint"
><code
class=
" hljs xml"
><span
class=
"hljs-pi"
>
<
?xml version="1.0" encoding="UTF-8" standalone="yes"?
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
user
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
username
</span>
>
</span>
newUsername
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
username
</span>
>
</span>
...
...
@@ -2073,6 +2107,8 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
properties
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
user
</span>
>
</span></code></pre>
<h4
id=
"json-example"
>
JSON Example
</h4>
<blockquote>
...
...
@@ -2259,7 +2295,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h2
id=
"lockout-a-user"
>
Lockout a user
</h2>
<p>
Endpoint to lockout / ban the user from the chat server
</p>
<p>
Endpoint to lockout / ban the user from the chat server
. The user will be kicked if the user is online.
</p>
<blockquote>
<p><strong>
POST
</strong>
/lockouts/{username}
</p>
...
...
@@ -2843,6 +2879,8 @@ Payload Example 1 (required parameters):</p>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
outcasts
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
chatRoom
</span>
>
</span></code></pre>
<h3
id=
"json-examples-1"
>
JSON Examples
</h3>
<blockquote>
...
...
@@ -2916,6 +2954,8 @@ Payload Example 1 (required parameters):</p>
}
}
</code></pre>
<h2
id=
"delete-a-chat-room"
>
Delete a chat room
</h2>
<p>
Endpoint to delete a chat room.
</p>
...
...
@@ -3058,6 +3098,8 @@ Payload Example 1 (required parameters):</p>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
outcasts
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
chatRoom
</span>
>
</span></code></pre>
<h2
id=
"add-user-with-role-to-chat-room"
>
Add user with role to chat room
</h2>
<p>
Endpoint to add a new user with role to a room.
</p>
...
...
@@ -3392,6 +3434,211 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h1
id=
"group-related-rest-endpoints"
>
Group related REST Endpoints
</h1>
<h2
id=
"retrieve-all-groups"
>
Retrieve all groups
</h2>
<p>
Endpoint to get all groups
</p>
<blockquote>
<p><strong>
GET
</strong>
/groups
</p>
</blockquote>
<p><strong>
Payload:
</strong>
none
<br>
<strong>
Return value:
</strong>
Groups
</p>
<h3
id=
"examples-26"
>
Examples
</h3>
<blockquote>
<p><strong>
Header
</strong>
: Authorization: Basic YWRtaW46MTIzNDU=
</p>
<p><strong>
GET
</strong>
<a
href=
"http://example.org:9090/plugins/restapi/v1/groups"
>
http://example.org:9090/plugins/restapi/v1/groups
</a></p>
</blockquote>
<h2
id=
"retrieve-a-group"
>
Retrieve a group
</h2>
<p>
Endpoint to get information over specific group
</p>
<blockquote>
<p><strong>
GET
</strong>
/groups/{groupName}
</p>
</blockquote>
<p><strong>
Payload:
</strong>
none
<br>
<strong>
Return value:
</strong>
Group
</p>
<h3
id=
"possible-parameters-24"
>
Possible parameters
</h3>
<table>
<thead>
<tr>
<th>
Parameter
</th>
<th>
Parameter Type
</th>
<th>
Description
</th>
<th>
Default value
</th>
</tr>
</thead>
<tbody><tr>
<td>
groupName
</td>
<td>
@Path
</td>
<td>
The name of the group
</td>
<td></td>
</tr>
</tbody></table>
<h3
id=
"examples-27"
>
Examples
</h3>
<p><strong>
Header:
</strong>
Authorization: Basic YWRtaW46MTIzNDU=
</p>
<p><strong>
GET
</strong>
<a
href=
"http://example.org:9090/plugins/restapi/v1/groups/moderators"
>
http://example.org:9090/plugins/restapi/v1/groups/moderators
</a></p>
<h2
id=
"create-a-group"
>
Create a group
</h2>
<p>
Endpoint to create a new group
</p>
<blockquote>
<p><strong>
POST
</strong>
/groups
</p>
</blockquote>
<p><strong>
Payload:
</strong>
Group
<br>
<strong>
Return value:
</strong>
HTTP status 201 (Created)
</p>
<h3
id=
"examples-28"
>
Examples
</h3>
<blockquote>
<p><strong>
Header:
</strong>
Authorization: Basic YWRtaW46MTIzNDU=
<br>
<strong>
Header:
</strong>
Content-Type: application/xml
</p>
<p><strong>
POST
</strong>
<a
href=
"http://example.org:9090/plugins/restapi/v1/groups"
>
http://example.org:9090/plugins/restapi/v1/groups
</a></p>
</blockquote>
<p><strong>
Payload Example:
</strong></p>
<pre
class=
"prettyprint"
><code
class=
" hljs xml"
><span
class=
"hljs-pi"
>
<
?xml version="1.0" encoding="UTF-8" standalone="yes"?
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
group
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
name
</span>
>
</span>
GroupName
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
name
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
description
</span>
>
</span>
Some description
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
description
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
group
</span>
>
</span></code></pre>
<h2
id=
"delete-a-group"
>
Delete a group
</h2>
<p>
Endpoint to delete a group
</p>
<blockquote>
<p><strong>
DELETE
</strong>
/groups/{groupName}
</p>
</blockquote>
<p><strong>
Payload:
</strong>
none
<br>
<strong>
Return value:
</strong>
HTTP status 200 (OK)
</p>
<h3
id=
"possible-parameters-25"
>
Possible parameters
</h3>
<table>
<thead>
<tr>
<th>
Parameter
</th>
<th>
Parameter Type
</th>
<th>
Description
</th>
<th>
Default value
</th>
</tr>
</thead>
<tbody><tr>
<td>
groupName
</td>
<td>
@Path
</td>
<td>
The name of the group
</td>
<td></td>
</tr>
</tbody></table>
<h3
id=
"examples-29"
>
Examples
</h3>
<blockquote>
<p><strong>
Header:
</strong>
Authorization: Basic YWRtaW46MTIzNDU=
</p>
<p><strong>
DELETE
</strong>
<a
href=
"http://example.org:9090/plugins/restapi/v1/groups/groupToDelete"
>
http://example.org:9090/plugins/restapi/v1/groups/groupToDelete
</a></p>
</blockquote>
<h2
id=
"update-a-group"
>
Update a group
</h2>
<p>
Endpoint to update / overwrite a group
</p>
<blockquote>
<p><strong>
PUT
</strong>
/groups/{groupName}
</p>
</blockquote>
<p><strong>
Payload:
</strong>
Group
<br>
<strong>
Return value:
</strong>
HTTP status 200 (OK)
</p>
<h3
id=
"possible-parameters-26"
>
Possible parameters
</h3>
<table>
<thead>
<tr>
<th>
Parameter
</th>
<th>
Parameter Type
</th>
<th>
Description
</th>
<th>
Default value
</th>
</tr>
</thead>
<tbody><tr>
<td>
groupName
</td>
<td>
@Path
</td>
<td>
The name of the group
</td>
<td></td>
</tr>
</tbody></table>
<h3
id=
"examples-30"
>
Examples
</h3>
<blockquote>
<p><strong>
Header:
</strong>
Authorization: Basic YWRtaW46MTIzNDU=
<br>
<strong>
Header:
</strong>
Content-Type application/xml
</p>
<p><strong>
PUT
</strong>
<a
href=
"http://example.org:9090/plugins/restapi/v1/groups/groupNameToUpdate"
>
http://example.org:9090/plugins/restapi/v1/groups/groupNameToUpdate
</a></p>
</blockquote>
<p><strong>
Payload:
</strong></p>
<pre
class=
"prettyprint"
><code
class=
" hljs xml"
><span
class=
"hljs-pi"
>
<
?xml version="1.0" encoding="UTF-8" standalone="yes"?
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
group
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
name
</span>
>
</span>
groupNameToUpdate
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
name
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
<span
class=
"hljs-title"
>
description
</span>
>
</span>
New description
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
description
</span>
>
</span>
<span
class=
"hljs-tag"
>
<
/
<span
class=
"hljs-title"
>
group
</span>
>
</span></code></pre>
<h1
id=
"deprecated-user-service-plugin-readme"
>
(Deprecated) User Service Plugin Readme
</h1>
...
...
@@ -3678,6 +3925,71 @@ If the strings are encoded incorrectly, double byte characters will look garbele
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/GroupController.java
0 → 100644
View file @
6a72aa1b
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
controller
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.jivesoftware.openfire.group.Group
;
import
org.jivesoftware.openfire.group.GroupAlreadyExistsException
;
import
org.jivesoftware.openfire.group.GroupManager
;
import
org.jivesoftware.openfire.group.GroupNotFoundException
;
import
org.jivesoftware.openfire.plugin.rest.entity.GroupEntity
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException
;
/**
* The Class GroupController.
*/
public
class
GroupController
{
/** The Constant INSTANCE. */
public
static
final
GroupController
INSTANCE
=
new
GroupController
();
/**
* Gets the single instance of GroupController.
*
* @return single instance of GroupController
*/
public
static
GroupController
getInstance
()
{
return
INSTANCE
;
}
/**
* Gets the groups.
*
* @return the groups
* @throws ServiceException
* the service exception
*/
public
List
<
GroupEntity
>
getGroups
()
throws
ServiceException
{
Collection
<
Group
>
groups
=
GroupManager
.
getInstance
().
getGroups
();
List
<
GroupEntity
>
groupEntities
=
new
ArrayList
<
GroupEntity
>();
for
(
Group
group
:
groups
)
{
GroupEntity
groupEntity
=
new
GroupEntity
(
group
.
getName
(),
group
.
getDescription
());
groupEntities
.
add
(
groupEntity
);
}
return
groupEntities
;
}
/**
* Gets the group.
*
* @param groupName
* the group name
* @return the group
* @throws ServiceException
* the service exception
*/
public
GroupEntity
getGroup
(
String
groupName
)
throws
ServiceException
{
Group
group
;
try
{
group
=
GroupManager
.
getInstance
().
getGroup
(
groupName
);
}
catch
(
GroupNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not find group"
,
groupName
,
ExceptionType
.
GROUP_NOT_FOUND
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
GroupEntity
groupEntity
=
new
GroupEntity
(
group
.
getName
(),
group
.
getDescription
());
return
groupEntity
;
}
/**
* Creates the group.
*
* @param groupEntity
* the group entity
* @return the group
* @throws ServiceException
* the service exception
*/
public
Group
createGroup
(
GroupEntity
groupEntity
)
throws
ServiceException
{
Group
group
;
if
(
groupEntity
!=
null
&&
!
groupEntity
.
getName
().
isEmpty
())
{
try
{
group
=
GroupManager
.
getInstance
().
createGroup
(
groupEntity
.
getName
());
group
.
setDescription
(
groupEntity
.
getDescription
());
group
.
getProperties
().
put
(
"sharedRoster.showInRoster"
,
"onlyGroup"
);
group
.
getProperties
().
put
(
"sharedRoster.displayName"
,
groupEntity
.
getName
());
group
.
getProperties
().
put
(
"sharedRoster.groupList"
,
""
);
}
catch
(
GroupAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create a group"
,
groupEntity
.
getName
(),
ExceptionType
.
GROUP_ALREADY_EXISTS
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
else
{
throw
new
ServiceException
(
"Could not create new group"
,
"groups"
,
ExceptionType
.
ILLEGAL_ARGUMENT_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
);
}
return
group
;
}
/**
* Update group.
*
* @param groupName the group name
* @param groupEntity the group entity
* @return the group
* @throws ServiceException the service exception
*/
public
Group
updateGroup
(
String
groupName
,
GroupEntity
groupEntity
)
throws
ServiceException
{
Group
group
;
if
(
groupEntity
!=
null
&&
!
groupEntity
.
getName
().
isEmpty
())
{
if
(
groupName
.
equals
(
groupEntity
.
getName
()))
{
try
{
group
=
GroupManager
.
getInstance
().
getGroup
(
groupName
);
group
.
setDescription
(
groupEntity
.
getDescription
());
}
catch
(
GroupNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not find group"
,
groupName
,
ExceptionType
.
GROUP_NOT_FOUND
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
}
else
{
throw
new
ServiceException
(
"Could not update the group. The group name is different to the payload group name."
,
groupName
+
" != "
+
groupEntity
.
getName
(),
ExceptionType
.
ILLEGAL_ARGUMENT_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
);
}
}
else
{
throw
new
ServiceException
(
"Could not update new group"
,
"groups"
,
ExceptionType
.
ILLEGAL_ARGUMENT_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
);
}
return
group
;
}
/**
* Delete group.
*
* @param groupName
* the group name
* @throws ServiceException
* the service exception
*/
public
void
deleteGroup
(
String
groupName
)
throws
ServiceException
{
try
{
Group
group
=
GroupManager
.
getInstance
().
getGroup
(
groupName
);
GroupManager
.
getInstance
().
deleteGroup
(
group
);
}
catch
(
GroupNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not find group"
,
groupName
,
ExceptionType
.
GROUP_NOT_FOUND
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
}
}
\ No newline at end of file
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java
View file @
6a72aa1b
...
...
@@ -6,14 +6,15 @@ import java.util.List;
import
javax.ws.rs.core.Response
;
import
org.jivesoftware.openfire.SessionManager
;
import
org.jivesoftware.openfire.SharedGroupException
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.group.Group
;
import
org.jivesoftware.openfire.group.GroupAlreadyExistsException
;
import
org.jivesoftware.openfire.group.GroupManager
;
import
org.jivesoftware.openfire.group.GroupNotFoundException
;
import
org.jivesoftware.openfire.lockout.LockOutManager
;
import
org.jivesoftware.openfire.plugin.rest.dao.PropertyDAO
;
import
org.jivesoftware.openfire.plugin.rest.entity.GroupEntity
;
import
org.jivesoftware.openfire.plugin.rest.entity.RosterEntities
;
import
org.jivesoftware.openfire.plugin.rest.entity.RosterItemEntity
;
import
org.jivesoftware.openfire.plugin.rest.entity.UserEntities
;
...
...
@@ -26,11 +27,13 @@ import org.jivesoftware.openfire.plugin.rest.utils.UserUtils;
import
org.jivesoftware.openfire.roster.Roster
;
import
org.jivesoftware.openfire.roster.RosterItem
;
import
org.jivesoftware.openfire.roster.RosterManager
;
import
org.jivesoftware.openfire.session.ClientSession
;
import
org.jivesoftware.openfire.user.User
;
import
org.jivesoftware.openfire.user.UserAlreadyExistsException
;
import
org.jivesoftware.openfire.user.UserManager
;
import
org.jivesoftware.openfire.user.UserNotFoundException
;
import
org.xmpp.packet.JID
;
import
org.xmpp.packet.StreamError
;
/**
* The Class UserServiceController.
...
...
@@ -47,6 +50,9 @@ public class UserServiceController {
/** The server. */
private
XMPPServer
server
;
/** The lock out manager. */
private
LockOutManager
lockOutManager
;
/**
* Gets the single instance of UserServiceController.
...
...
@@ -64,6 +70,7 @@ public class UserServiceController {
server
=
XMPPServer
.
getInstance
();
userManager
=
server
.
getUserManager
();
rosterManager
=
server
.
getRosterManager
();
lockOutManager
=
server
.
getLockOutManager
();
}
/**
...
...
@@ -88,6 +95,9 @@ public class UserServiceController {
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
);
}
addProperties
(
userEntity
.
getUsername
(),
userEntity
.
getProperties
());
}
else
{
throw
new
ServiceException
(
"Could not create new user"
,
"users"
,
ExceptionType
.
ILLEGAL_ARGUMENT_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
);
}
}
...
...
@@ -186,7 +196,7 @@ public class UserServiceController {
*/
public
void
enableUser
(
String
username
)
throws
ServiceException
{
getAndCheckUser
(
username
);
LockOutManager
.
getInstance
()
.
enableAccount
(
username
);
lockOutManager
.
enableAccount
(
username
);
}
/**
...
...
@@ -199,7 +209,15 @@ public class UserServiceController {
*/
public
void
disableUser
(
String
username
)
throws
ServiceException
{
getAndCheckUser
(
username
);
LockOutManager
.
getInstance
().
disableAccount
(
username
,
null
,
null
);
lockOutManager
.
disableAccount
(
username
,
null
,
null
);
if
(
lockOutManager
.
isAccountDisabled
(
username
))
{
final
StreamError
error
=
new
StreamError
(
StreamError
.
Condition
.
not_authorized
);
for
(
ClientSession
sess
:
SessionManager
.
getInstance
().
getSessions
(
username
))
{
sess
.
deliverRawText
(
error
.
toXML
());
sess
.
close
();
}
}
}
/**
...
...
@@ -367,7 +385,7 @@ public class UserServiceController {
group
=
GroupManager
.
getInstance
().
getGroup
(
groupName
);
}
catch
(
GroupNotFoundException
e
)
{
// Create this group
group
=
createGroup
(
groupName
);
group
=
GroupController
.
getInstance
().
createGroup
(
new
GroupEntity
(
groupName
,
""
)
);
}
groups
.
add
(
group
);
}
...
...
@@ -444,29 +462,6 @@ public class UserServiceController {
}
}
/**
* Creates the group.
*
* @param groupName
* the group name
* @return the group
* @throws ServiceException
* the service exception
*/
private
Group
createGroup
(
String
groupName
)
throws
ServiceException
{
Group
group
=
null
;
try
{
group
=
GroupManager
.
getInstance
().
createGroup
(
groupName
);
group
.
getProperties
().
put
(
"sharedRoster.showInRoster"
,
"onlyGroup"
);
group
.
getProperties
().
put
(
"sharedRoster.displayName"
,
groupName
);
group
.
getProperties
().
put
(
"sharedRoster.groupList"
,
""
);
}
catch
(
GroupAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create group"
,
groupName
,
ExceptionType
.
GROUP_ALREADY_EXISTS
,
Response
.
Status
.
BAD_REQUEST
,
e
);
}
return
group
;
}
/**
* Gets the and check user.
*
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/entity/GroupEntities.java
0 → 100644
View file @
6a72aa1b
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
entity
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
* The Class GroupEntities.
*/
@XmlRootElement
(
name
=
"groups"
)
public
class
GroupEntities
{
/** The groups. */
List
<
GroupEntity
>
groups
;
/**
* Instantiates a new group entities.
*/
public
GroupEntities
()
{
}
/**
* Instantiates a new group entities.
*
* @param groups the groups
*/
public
GroupEntities
(
List
<
GroupEntity
>
groups
)
{
this
.
groups
=
groups
;
}
/**
* Gets the groups.
*
* @return the groups
*/
@XmlElement
(
name
=
"group"
)
public
List
<
GroupEntity
>
getGroups
()
{
return
groups
;
}
/**
* Sets the groups.
*
* @param groups the new groups
*/
public
void
setGroups
(
List
<
GroupEntity
>
groups
)
{
this
.
groups
=
groups
;
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/entity/GroupEntity.java
0 → 100644
View file @
6a72aa1b
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
entity
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlType
;
/**
* The Class GroupEntity.
*/
@XmlRootElement
(
name
=
"group"
)
@XmlType
(
propOrder
=
{
"name"
,
"description"
})
public
class
GroupEntity
{
/** The name. */
private
String
name
;
/** The description. */
private
String
description
;
/**
* Instantiates a new group entity.
*/
public
GroupEntity
()
{
}
/**
* Instantiates a new group entity.
*
* @param name
* the name
* @param description
* the description
*/
public
GroupEntity
(
String
name
,
String
description
)
{
this
.
name
=
name
;
this
.
description
=
description
;
}
/**
* Gets the name.
*
* @return the name
*/
@XmlElement
public
String
getName
()
{
return
name
;
}
/**
* Sets the name.
*
* @param name
* the new name
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* Gets the description.
*
* @return the description
*/
@XmlElement
public
String
getDescription
()
{
return
description
;
}
/**
* Sets the description.
*
* @param description
* the new description
*/
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/GroupService.java
0 → 100644
View file @
6a72aa1b
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
service
;
import
javax.annotation.PostConstruct
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
org.jivesoftware.openfire.plugin.rest.controller.GroupController
;
import
org.jivesoftware.openfire.plugin.rest.entity.GroupEntities
;
import
org.jivesoftware.openfire.plugin.rest.entity.GroupEntity
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException
;
@Path
(
"restapi/v1/groups"
)
public
class
GroupService
{
private
GroupController
groupController
;
@PostConstruct
public
void
init
()
{
groupController
=
GroupController
.
getInstance
();
}
@GET
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
GroupEntities
getGroups
()
throws
ServiceException
{
return
new
GroupEntities
(
groupController
.
getGroups
());
}
@POST
public
Response
createGroup
(
GroupEntity
groupEntity
)
throws
ServiceException
{
groupController
.
createGroup
(
groupEntity
);
return
Response
.
status
(
Response
.
Status
.
CREATED
).
build
();
}
@GET
@Path
(
"/{groupName}"
)
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
GroupEntity
getGroup
(
@PathParam
(
"groupName"
)
String
groupName
)
throws
ServiceException
{
return
groupController
.
getGroup
(
groupName
);
}
@PUT
@Path
(
"/{groupName}"
)
public
Response
updateGroup
(
@PathParam
(
"groupName"
)
String
groupName
,
GroupEntity
groupEntity
)
throws
ServiceException
{
groupController
.
updateGroup
(
groupName
,
groupEntity
);
return
Response
.
status
(
Response
.
Status
.
OK
).
build
();
}
@DELETE
@Path
(
"/{groupName}"
)
public
Response
deleteUserFromGroups
(
@PathParam
(
"groupName"
)
String
groupName
)
throws
ServiceException
{
groupController
.
deleteGroup
(
groupName
);
return
Response
.
status
(
Response
.
Status
.
OK
).
build
();
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/JerseyWrapper.java
View file @
6a72aa1b
...
...
@@ -71,6 +71,8 @@ public class JerseyWrapper extends ServletContainer {
prc
.
getClasses
().
add
(
UserGroupService
.
class
);
prc
.
getClasses
().
add
(
UserLockoutService
.
class
);
prc
.
getClasses
().
add
(
GroupService
.
class
);
prc
.
getClasses
().
add
(
RESTExceptionMapper
.
class
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment