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
Expand all
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
This diff is collapsed.
Click to expand it.
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