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
090831d3
Commit
090831d3
authored
Feb 20, 2015
by
Roman S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to REST API plugin version 1.0.1
parent
4c2804b6
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
5219 additions
and
4962 deletions
+5219
-4962
changelog.html
src/plugins/restAPI/changelog.html
+68
-59
plugin.xml
src/plugins/restAPI/plugin.xml
+21
-21
readme.html
src/plugins/restAPI/readme.html
+3702
-3752
JustMarriedController.java
...penfire/plugin/rest/controller/JustMarriedController.java
+259
-0
MUCRoomController.java
...re/openfire/plugin/rest/controller/MUCRoomController.java
+519
-504
UserServiceController.java
...penfire/plugin/rest/controller/UserServiceController.java
+511
-495
ExceptionType.java
...ftware/openfire/plugin/rest/exceptions/ExceptionType.java
+41
-39
JerseyWrapper.java
...esoftware/openfire/plugin/rest/service/JerseyWrapper.java
+6
-0
UserRosterService.java
...tware/openfire/plugin/rest/service/UserRosterService.java
+92
-92
No files found.
src/plugins/restAPI/changelog.html
View file @
090831d3
...
...
@@ -44,6 +44,15 @@
REST API Plugin Changelog
</h1>
<p><b>
1.0.1
</b>
-- February 20th, 2015
</p>
<ul>
<li>
Added possibility to rename a user (Thanks to JustMarried plugin)
</li>
<li>
Adjusted HTTP Codes by conflict to HTTP CODE: 409
</li>
<li>
Added subject to Chat room
</li>
<li>
Disabled jersey logging on startup
</li>
<li>
By create a new chat room the chat room service will be created if it was not there
</li>
</ul>
<p><b>
1.0.0
</b>
-- February 3rd, 2015
</p>
<ul>
<li>
UserService plugin and MUC Service plugin are merged to the REST API plugin.
</li>
...
...
src/plugins/restAPI/plugin.xml
View file @
090831d3
...
...
@@ -5,8 +5,8 @@
<name>
REST API
</name>
<description>
Allows administration over a RESTful API.
</description>
<author>
Roman Soldatow
</author>
<version>
1.0.
0
</version>
<date>
02/
03/2015
</date>
<version>
1.0.
1
</version>
<date>
02/
20/2015
</date>
<minServerVersion>
3.9.0
</minServerVersion>
<adminconsole>
...
...
src/plugins/restAPI/readme.html
View file @
090831d3
This diff is collapsed.
Click to expand it.
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/JustMarriedController.java
0 → 100644
View file @
090831d3
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
controller
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.dom4j.Element
;
import
org.jivesoftware.openfire.SessionManager
;
import
org.jivesoftware.openfire.SharedGroupException
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.auth.AuthFactory
;
import
org.jivesoftware.openfire.group.Group
;
import
org.jivesoftware.openfire.group.GroupManager
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException
;
import
org.jivesoftware.openfire.roster.Roster
;
import
org.jivesoftware.openfire.roster.RosterItem
;
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.jivesoftware.openfire.vcard.VCardManager
;
import
org.xmpp.packet.StreamError
;
/**
* The Class JustMarriedController.
*/
public
class
JustMarriedController
{
/**
* Change name.
*
* @param currentUserName
* the current user name
* @param newUserName
* the new user name
* @param deleteOldUser
* the delete old user
* @param newEmail
* the new email
* @param newRealName
* the new real name
* @return true, if successful
* @throws ServiceException
* the service exception
*/
public
static
boolean
changeName
(
String
currentUserName
,
String
newUserName
,
boolean
deleteOldUser
,
String
newEmail
,
String
newRealName
)
throws
ServiceException
{
UserManager
userManager
=
UserManager
.
getInstance
();
try
{
User
currentUser
=
userManager
.
getUser
(
currentUserName
);
// Old user found, create new one
String
password
=
AuthFactory
.
getPassword
(
currentUserName
);
String
newName
=
(
newRealName
==
null
||
newRealName
.
length
()
==
0
)
?
currentUser
.
getName
()
:
newRealName
;
String
newMail
=
(
newEmail
==
null
||
newEmail
.
length
()
==
0
)
?
currentUser
.
getEmail
()
:
newEmail
;
User
newUser
=
userManager
.
createUser
(
newUserName
,
password
,
currentUser
.
getName
(),
newMail
);
newUser
.
setName
(
newName
);
newUser
.
setNameVisible
(
currentUser
.
isNameVisible
());
newUser
.
setEmailVisible
(
currentUser
.
isEmailVisible
());
newUser
.
setCreationDate
(
currentUser
.
getCreationDate
());
copyRoster
(
currentUser
,
newUser
,
currentUserName
);
copyProperties
(
currentUser
,
newUser
);
copyToGroups
(
currentUserName
,
newUserName
);
copyVCard
(
currentUserName
,
newUserName
);
if
(
deleteOldUser
)
{
deleteUser
(
currentUser
);
}
}
catch
(
UserNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not find user"
,
currentUserName
,
ExceptionType
.
USER_NOT_FOUND_EXCEPTION
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create new user"
,
newUserName
,
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
,
e
);
}
return
true
;
}
/**
* Copy v card.
*
* @param currentUserName
* the current user name
* @param newUserName
* the new user name
* @throws ServiceException
* the service exception
*/
private
static
void
copyVCard
(
String
currentUserName
,
String
newUserName
)
throws
ServiceException
{
VCardManager
vcardManager
=
VCardManager
.
getInstance
();
Element
vcard
=
vcardManager
.
getVCard
(
currentUserName
);
if
(
vcard
!=
null
)
{
try
{
vcardManager
.
setVCard
(
newUserName
,
vcard
);
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"Could not copy vcard to new user"
,
newUserName
,
ExceptionType
.
ILLEGAL_ARGUMENT_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
}
}
}
/**
* Copy to groups.
*
* @param currentUser
* the current user
* @param newUser
* the new user
*/
private
static
void
copyToGroups
(
String
currentUser
,
String
newUser
)
{
GroupManager
groupManager
=
GroupManager
.
getInstance
();
for
(
Group
group
:
groupManager
.
getGroups
())
{
if
(
group
.
isUser
(
currentUser
))
{
group
.
getMembers
().
add
(
XMPPServer
.
getInstance
().
createJID
(
newUser
,
null
));
}
}
}
/**
* Delete user.
*
* @param oldUser
* the old user
*/
private
static
void
deleteUser
(
User
oldUser
)
{
UserManager
.
getInstance
().
deleteUser
(
oldUser
);
final
StreamError
error
=
new
StreamError
(
StreamError
.
Condition
.
not_authorized
);
for
(
ClientSession
sess
:
SessionManager
.
getInstance
().
getSessions
(
oldUser
.
getUsername
()))
{
sess
.
deliverRawText
(
error
.
toXML
());
sess
.
close
();
}
}
/**
* Copy properties.
*
* @param currentUser
* the current user
* @param newUser
* the new user
*/
private
static
void
copyProperties
(
User
currentUser
,
User
newUser
)
{
for
(
String
key
:
currentUser
.
getProperties
().
keySet
())
{
newUser
.
getProperties
().
put
(
key
,
User
.
getPropertyValue
(
currentUser
.
getUsername
(),
key
));
}
}
/**
* Copy roster.
*
* @param currentUser
* the current user
* @param newUser
* the new user
* @param currentUserName
* the current user name
* @throws ServiceException
* the service exception
*/
private
static
void
copyRoster
(
User
currentUser
,
User
newUser
,
String
currentUserName
)
throws
ServiceException
{
Roster
newRoster
=
newUser
.
getRoster
();
Roster
currentRoster
=
currentUser
.
getRoster
();
for
(
RosterItem
item
:
currentRoster
.
getRosterItems
())
{
try
{
List
<
String
>
groups
=
item
.
getGroups
();
RosterItem
justCreated
=
newRoster
.
createRosterItem
(
item
.
getJid
(),
item
.
getNickname
(),
groups
,
true
,
true
);
justCreated
.
setAskStatus
(
item
.
getAskStatus
());
justCreated
.
setRecvStatus
(
item
.
getRecvStatus
());
justCreated
.
setSubStatus
(
item
.
getSubStatus
());
for
(
Group
gr
:
item
.
getSharedGroups
())
{
justCreated
.
addSharedGroup
(
gr
);
}
for
(
Group
gr
:
item
.
getInvisibleSharedGroups
())
{
justCreated
.
addInvisibleSharedGroup
(
gr
);
}
newRoster
.
updateRosterItem
(
justCreated
);
addNewUserToOthersRoster
(
newUser
,
item
,
currentUserName
);
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create roster item for user "
,
newUser
.
getUsername
(),
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
,
e
);
}
catch
(
SharedGroupException
e
)
{
throw
new
ServiceException
(
"Could not create roster item, because it is a contact from a shared group"
,
newUser
.
getUsername
(),
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
}
catch
(
UserNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not update roster item for user "
+
newUser
.
getUsername
()
+
" because it was not properly created."
,
newUser
.
getUsername
(),
ExceptionType
.
USER_NOT_FOUND_EXCEPTION
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
}
}
/**
* Adds the new user to others roster.
*
* @param newUser
* the new user
* @param otherItem
* the other item
* @param currentUser
* the current user
* @throws ServiceException
* the service exception
*/
private
static
void
addNewUserToOthersRoster
(
User
newUser
,
RosterItem
otherItem
,
String
currentUser
)
throws
ServiceException
{
otherItem
.
getJid
();
UserManager
userManager
=
UserManager
.
getInstance
();
// Is this user registered with our OF server?
String
username
=
otherItem
.
getJid
().
getNode
();
if
(
username
!=
null
&&
username
.
length
()
>
0
&&
userManager
.
isRegisteredUser
(
username
)
&&
XMPPServer
.
getInstance
().
isLocal
(
XMPPServer
.
getInstance
().
createJID
(
currentUser
,
null
)))
{
try
{
User
otherUser
=
userManager
.
getUser
(
username
);
Roster
otherRoster
=
otherUser
.
getRoster
();
RosterItem
oldUserOnOthersRoster
=
otherRoster
.
getRosterItem
(
XMPPServer
.
getInstance
().
createJID
(
currentUser
,
null
));
try
{
if
(!
oldUserOnOthersRoster
.
isOnlyShared
())
{
RosterItem
justCreated
=
otherRoster
.
createRosterItem
(
XMPPServer
.
getInstance
().
createJID
(
newUser
.
getUsername
(),
null
),
oldUserOnOthersRoster
.
getNickname
(),
oldUserOnOthersRoster
.
getGroups
(),
true
,
true
);
justCreated
.
setAskStatus
(
oldUserOnOthersRoster
.
getAskStatus
());
justCreated
.
setRecvStatus
(
oldUserOnOthersRoster
.
getRecvStatus
());
justCreated
.
setSubStatus
(
oldUserOnOthersRoster
.
getSubStatus
());
otherRoster
.
updateRosterItem
(
justCreated
);
}
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create roster item for user "
,
newUser
.
getUsername
(),
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
,
e
);
}
catch
(
SharedGroupException
e
)
{
throw
new
ServiceException
(
"Could not create roster item, because it is a contact from a shared group"
,
newUser
.
getUsername
(),
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
}
}
catch
(
UserNotFoundException
e
)
{
throw
new
ServiceException
(
"Could not create roster item for user "
+
newUser
.
getUsername
()
+
" because it is a contact from a shared group."
,
newUser
.
getUsername
(),
ExceptionType
.
USER_NOT_FOUND_EXCEPTION
,
Response
.
Status
.
NOT_FOUND
,
e
);
}
}
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/MUCRoomController.java
View file @
090831d3
...
...
@@ -22,6 +22,7 @@ import org.jivesoftware.openfire.muc.MUCRoom;
import
org.jivesoftware.openfire.muc.NotAllowedException
;
import
org.jivesoftware.openfire.plugin.rest.utils.MUCRoomUtils
;
import
org.jivesoftware.openfire.plugin.rest.utils.UserUtils
;
import
org.jivesoftware.util.AlreadyExistsException
;
import
org.xmpp.packet.JID
;
/**
...
...
@@ -139,7 +140,10 @@ public class MUCRoomController {
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
}
catch
(
ConflictException
e
)
{
throw
new
ServiceException
(
"Could not create the channel"
,
mucRoomEntity
.
getRoomName
(),
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
CONFLICT
,
e
);
}
catch
(
AlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create the channel"
,
mucRoomEntity
.
getRoomName
(),
ExceptionType
.
ALREADY_EXISTS
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
...
...
@@ -170,7 +174,10 @@ public class MUCRoomController {
}
catch
(
ForbiddenException
e
)
{
throw
new
ServiceException
(
"Could not update the channel"
,
roomName
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
}
catch
(
ConflictException
e
)
{
throw
new
ServiceException
(
"Could not update the channel"
,
roomName
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
throw
new
ServiceException
(
"Could not update the channel"
,
roomName
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
CONFLICT
,
e
);
}
catch
(
AlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not update the channel"
,
mucRoomEntity
.
getRoomName
(),
ExceptionType
.
ALREADY_EXISTS
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
...
...
@@ -187,9 +194,10 @@ public class MUCRoomController {
* the forbidden exception
* @throws ConflictException
* the conflict exception
* @throws AlreadyExistsException
*/
private
void
createRoom
(
MUCRoomEntity
mucRoomEntity
,
String
serviceName
)
throws
NotAllowedException
,
ForbiddenException
,
ConflictException
{
ForbiddenException
,
ConflictException
,
AlreadyExistsException
{
// Set owner
JID
owner
=
XMPPServer
.
getInstance
().
createJID
(
"admin"
,
null
);
...
...
@@ -201,6 +209,12 @@ public class MUCRoomController {
mucRoomEntity
.
setOwners
(
owners
);
}
// Check if chat service is available, if not create a new one
boolean
serviceRegistered
=
XMPPServer
.
getInstance
().
getMultiUserChatManager
().
isServiceRegistered
(
serviceName
);
if
(!
serviceRegistered
)
{
XMPPServer
.
getInstance
().
getMultiUserChatManager
().
createMultiUserChatService
(
serviceName
,
serviceName
,
false
);
}
MUCRoom
room
=
XMPPServer
.
getInstance
().
getMultiUserChatManager
().
getMultiUserChatService
(
serviceName
)
.
getChatRoom
(
mucRoomEntity
.
getRoomName
().
toLowerCase
(),
owner
);
...
...
@@ -295,6 +309,7 @@ public class MUCRoomController {
MUCRoomEntity
mucRoomEntity
=
new
MUCRoomEntity
(
room
.
getNaturalLanguageName
(),
room
.
getName
(),
room
.
getDescription
());
mucRoomEntity
.
setSubject
(
room
.
getSubject
());
mucRoomEntity
.
setCanAnyoneDiscoverJID
(
room
.
canAnyoneDiscoverJID
());
mucRoomEntity
.
setCanChangeNickname
(
room
.
canChangeNickname
());
mucRoomEntity
.
setCanOccupantsChangeSubject
(
room
.
canOccupantsChangeSubject
());
...
...
@@ -403,7 +418,7 @@ public class MUCRoomController {
}
catch
(
ForbiddenException
e
)
{
throw
new
ServiceException
(
"Could not add admin"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
}
catch
(
ConflictException
e
)
{
throw
new
ServiceException
(
"Could not add admin"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
throw
new
ServiceException
(
"Could not add admin"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
...
...
@@ -475,7 +490,7 @@ public class MUCRoomController {
}
catch
(
ForbiddenException
e
)
{
throw
new
ServiceException
(
"Could not add outcast"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
}
catch
(
ConflictException
e
)
{
throw
new
ServiceException
(
"Could not add outcast"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
throw
new
ServiceException
(
"Could not add outcast"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
...
...
@@ -499,7 +514,7 @@ public class MUCRoomController {
}
catch
(
ForbiddenException
e
)
{
throw
new
ServiceException
(
"Could not delete affiliation"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
}
catch
(
ConflictException
e
)
{
throw
new
ServiceException
(
"Could not delete affiliation"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
FORBIDDEN
,
e
);
throw
new
ServiceException
(
"Could not delete affiliation"
,
jid
,
ExceptionType
.
NOT_ALLOWED
,
Response
.
Status
.
CONFLICT
,
e
);
}
}
}
\ No newline at end of file
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/UserServiceController.java
View file @
090831d3
...
...
@@ -8,6 +8,12 @@ import javax.ws.rs.core.Response;
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.RosterEntities
;
import
org.jivesoftware.openfire.plugin.rest.entity.RosterItemEntity
;
import
org.jivesoftware.openfire.plugin.rest.entity.UserEntities
;
...
...
@@ -16,12 +22,7 @@ import org.jivesoftware.openfire.plugin.rest.entity.UserGroupsEntity;
import
org.jivesoftware.openfire.plugin.rest.entity.UserProperty
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException
;
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.utils.UserUtils
;
import
org.jivesoftware.openfire.roster.Roster
;
import
org.jivesoftware.openfire.roster.RosterItem
;
import
org.jivesoftware.openfire.roster.RosterManager
;
...
...
@@ -29,7 +30,6 @@ 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.jivesoftware.openfire.plugin.rest.utils.UserUtils
;
import
org.xmpp.packet.JID
;
/**
...
...
@@ -85,9 +85,9 @@ public class UserServiceController {
userEntity
.
getEmail
());
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
"Could not create new user"
,
userEntity
.
getUsername
(),
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
);
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
);
}
addProperties
(
userEntity
);
addProperties
(
userEntity
.
getUsername
(),
userEntity
.
getProperties
());
}
}
...
...
@@ -103,6 +103,16 @@ public class UserServiceController {
*/
public
void
updateUser
(
String
username
,
UserEntity
userEntity
)
throws
ServiceException
{
if
(
userEntity
!=
null
&&
!
username
.
isEmpty
())
{
// Payload contains another username than provided over path
// parameter
if
(
userEntity
.
getUsername
()
!=
null
)
{
if
(!
userEntity
.
getUsername
().
equals
(
username
))
{
JustMarriedController
.
changeName
(
username
,
userEntity
.
getUsername
(),
true
,
userEntity
.
getEmail
(),
userEntity
.
getName
());
addProperties
(
userEntity
.
getUsername
(),
userEntity
.
getProperties
());
return
;
}
}
User
user
=
getAndCheckUser
(
username
);
if
(
userEntity
.
getPassword
()
!=
null
)
{
user
.
setPassword
(
userEntity
.
getPassword
());
...
...
@@ -114,7 +124,7 @@ public class UserServiceController {
user
.
setEmail
(
userEntity
.
getEmail
());
}
addProperties
(
user
Entity
);
addProperties
(
user
name
,
userEntity
.
getProperties
());
}
}
...
...
@@ -143,8 +153,9 @@ public class UserServiceController {
* @return the user entities
* @throws ServiceException
*/
public
UserEntities
getUserEntities
(
String
userSearch
,
String
propertyKey
,
String
propertyValue
)
throws
ServiceException
{
if
(
propertyKey
!=
null
)
{
public
UserEntities
getUserEntities
(
String
userSearch
,
String
propertyKey
,
String
propertyValue
)
throws
ServiceException
{
if
(
propertyKey
!=
null
)
{
return
getUserEntitiesByProperty
(
propertyKey
,
propertyValue
);
}
UserEntities
userEntities
=
new
UserEntities
();
...
...
@@ -339,9 +350,12 @@ public class UserServiceController {
/**
* Adds the user to group.
*
* @param username the username
* @param userGroupsEntity the user groups entity
* @throws ServiceException the service exception
* @param username
* the username
* @param userGroupsEntity
* the user groups entity
* @throws ServiceException
* the service exception
*/
public
void
addUserToGroups
(
String
username
,
UserGroupsEntity
userGroupsEntity
)
throws
ServiceException
{
if
(
userGroupsEntity
!=
null
)
{
...
...
@@ -420,11 +434,11 @@ public class UserServiceController {
* @throws ServiceException
* the service exception
*/
private
void
addProperties
(
UserEntity
userEntity
)
throws
ServiceException
{
User
user
=
getAndCheckUser
(
user
Entity
.
getUsername
());
private
void
addProperties
(
String
username
,
List
<
UserProperty
>
properties
)
throws
ServiceException
{
User
user
=
getAndCheckUser
(
user
name
);
user
.
getProperties
().
clear
();
if
(
userEntity
.
getProperties
()
!=
null
)
{
for
(
UserProperty
property
:
userEntity
.
getProperties
())
{
if
(
properties
!=
null
)
{
for
(
UserProperty
property
:
properties
)
{
user
.
getProperties
().
put
(
property
.
getKey
(),
property
.
getValue
());
}
}
...
...
@@ -433,9 +447,11 @@ public class UserServiceController {
/**
* Creates the group.
*
* @param groupName the group name
* @param groupName
* the group name
* @return the group
* @throws ServiceException the service exception
* @throws ServiceException
* the service exception
*/
private
Group
createGroup
(
String
groupName
)
throws
ServiceException
{
Group
group
=
null
;
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/exceptions/ExceptionType.java
View file @
090831d3
...
...
@@ -31,6 +31,8 @@ public final class ExceptionType {
/** The Constant NOT_ALLOWED. */
public
static
final
String
NOT_ALLOWED
=
"NotAllowedException"
;
/** The Constant ALREADY_EXISTS. */
public
static
final
String
ALREADY_EXISTS
=
"AlreadyExistsException"
;
/**
* Instantiates a new exception type.
*/
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/JerseyWrapper.java
View file @
090831d3
...
...
@@ -2,6 +2,8 @@ package org.jivesoftware.openfire.plugin.rest.service;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.servlet.ServletConfig
;
import
javax.servlet.ServletException
;
...
...
@@ -44,7 +46,11 @@ public class JerseyWrapper extends ServletContainer {
/** The prc. */
private
static
PackagesResourceConfig
prc
;
/** The Constant JERSEY_LOGGER. */
private
final
static
Logger
JERSEY_LOGGER
=
Logger
.
getLogger
(
"com.sun.jersey"
);
static
{
JERSEY_LOGGER
.
setLevel
(
Level
.
SEVERE
);
config
=
new
HashMap
<
String
,
Object
>();
config
.
put
(
RESOURCE_CONFIG_CLASS_KEY
,
RESOURCE_CONFIG_CLASS
);
prc
=
new
PackagesResourceConfig
(
SCAN_PACKAGE_DEFAULT
);
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/UserRosterService.java
View file @
090831d3
...
...
@@ -50,7 +50,7 @@ public class UserRosterService {
Response
.
Status
.
NOT_FOUND
,
e
);
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
COULD_NOT_CREATE_ROSTER_ITEM
,
""
,
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
Response
.
Status
.
CONFLICT
,
e
);
}
catch
(
SharedGroupException
e
)
{
throw
new
ServiceException
(
COULD_NOT_CREATE_ROSTER_ITEM
,
""
,
ExceptionType
.
SHARED_GROUP_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
...
...
@@ -85,7 +85,7 @@ public class UserRosterService {
Response
.
Status
.
BAD_REQUEST
,
e
);
}
catch
(
UserAlreadyExistsException
e
)
{
throw
new
ServiceException
(
COULD_NOT_UPDATE_THE_ROSTER
,
rosterJid
,
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
BAD_REQUEST
,
e
);
ExceptionType
.
USER_ALREADY_EXISTS_EXCEPTION
,
Response
.
Status
.
CONFLICT
,
e
);
}
return
Response
.
status
(
Response
.
Status
.
OK
).
build
();
}
...
...
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