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
de468799
Commit
de468799
authored
Apr 25, 2014
by
Tom Evans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OF-569: DeleteUser ad hoc command
Per patch submitted by John Georgiadis
parent
5cb46ba0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
0 deletions
+140
-0
AdHocCommandHandler.java
...g/jivesoftware/openfire/commands/AdHocCommandHandler.java
+2
-0
DeleteUser.java
...jivesoftware/openfire/commands/admin/user/DeleteUser.java
+138
-0
No files found.
src/java/org/jivesoftware/openfire/commands/AdHocCommandHandler.java
View file @
de468799
...
...
@@ -27,6 +27,7 @@ import org.jivesoftware.openfire.auth.UnauthorizedException;
import
org.jivesoftware.openfire.commands.admin.*
;
import
org.jivesoftware.openfire.commands.admin.group.*
;
import
org.jivesoftware.openfire.commands.admin.user.AddUser
;
import
org.jivesoftware.openfire.commands.admin.user.DeleteUser
;
import
org.jivesoftware.openfire.commands.admin.user.AuthenticateUser
;
import
org.jivesoftware.openfire.commands.admin.user.ChangeUserPassword
;
import
org.jivesoftware.openfire.commands.admin.user.UserProperties
;
...
...
@@ -213,6 +214,7 @@ public class AdHocCommandHandler extends IQHandler
addCommand
(
new
UpdateGroup
());
addCommand
(
new
DeleteGroup
());
addCommand
(
new
AddUser
());
addCommand
(
new
DeleteUser
());
addCommand
(
new
AuthenticateUser
());
addCommand
(
new
ChangeUserPassword
());
addCommand
(
new
UserProperties
());
...
...
src/java/org/jivesoftware/openfire/commands/admin/user/DeleteUser.java
0 → 100644
View file @
de468799
/**
* $RCSfile$
* $Revision: 3144 $
* $Date: 2005-12-01 14:20:11 -0300 (Thu, 01 Dec 2005) $
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
jivesoftware
.
openfire
.
commands
.
admin
.
user
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
org.dom4j.Element
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.commands.AdHocCommand
;
import
org.jivesoftware.openfire.commands.SessionData
;
import
org.jivesoftware.openfire.component.InternalComponentManager
;
import
org.jivesoftware.openfire.user.User
;
import
org.jivesoftware.openfire.user.UserManager
;
import
org.jivesoftware.openfire.user.UserNotFoundException
;
import
org.xmpp.forms.DataForm
;
import
org.xmpp.forms.FormField
;
import
org.xmpp.packet.JID
;
/**
* Delete a user from Openfire if the provider is not read-only. See
* <a href="http://www.xmpp.org/extensions/xep-0133.html#delete-user">Service Administration:
* Delete User</a>
*
* @author John Georgiadis
*/
public
class
DeleteUser
extends
AdHocCommand
{
@Override
public
String
getCode
()
{
return
"http://jabber.org/protocol/admin#delete-user"
;
}
@Override
public
String
getDefaultLabel
()
{
return
"Delete a User"
;
}
@Override
public
int
getMaxStages
(
SessionData
data
)
{
return
1
;
}
@Override
public
void
execute
(
SessionData
sessionData
,
Element
command
)
{
Element
note
=
command
.
addElement
(
"note"
);
// Check if users cannot be modified (backend is read-only)
if
(
UserManager
.
getUserProvider
().
isReadOnly
())
{
note
.
addAttribute
(
"type"
,
"error"
);
note
.
setText
(
"User provider is read only. Users cannot be deleted."
);
return
;
}
Map
<
String
,
List
<
String
>>
data
=
sessionData
.
getData
();
// Let's create the jid and check that they are a local user
JID
account
;
try
{
account
=
new
JID
(
get
(
data
,
"accountjid"
,
0
));
}
catch
(
NullPointerException
npe
)
{
note
.
addAttribute
(
"type"
,
"error"
);
note
.
setText
(
"JID required parameter."
);
return
;
}
if
(!
XMPPServer
.
getInstance
().
isLocal
(
account
))
{
note
.
addAttribute
(
"type"
,
"error"
);
note
.
setText
(
"Cannot delete remote user."
);
return
;
}
try
{
User
user
=
UserManager
.
getInstance
().
getUser
(
account
.
getNode
());
UserManager
.
getInstance
().
deleteUser
(
user
);
}
catch
(
UserNotFoundException
e
)
{
note
.
addAttribute
(
"type"
,
"error"
);
note
.
setText
(
"User not found."
);
return
;
}
// Answer that the operation was successful
note
.
addAttribute
(
"type"
,
"info"
);
note
.
setText
(
"Operation finished successfully"
);
}
@Override
protected
void
addStageInformation
(
SessionData
data
,
Element
command
)
{
DataForm
form
=
new
DataForm
(
DataForm
.
Type
.
form
);
form
.
setTitle
(
"Deleting a user"
);
form
.
addInstruction
(
"Fill out this form to delete a user."
);
FormField
field
=
form
.
addField
();
field
.
setType
(
FormField
.
Type
.
hidden
);
field
.
setVariable
(
"FORM_TYPE"
);
field
.
addValue
(
"http://jabber.org/protocol/admin"
);
field
=
form
.
addField
();
field
.
setType
(
FormField
.
Type
.
jid_single
);
field
.
setLabel
(
"The Jabber ID for the account to be deleted"
);
field
.
setVariable
(
"accountjid"
);
field
.
setRequired
(
true
);
// Add the form to the command
command
.
add
(
form
.
getElement
());
}
@Override
protected
List
<
Action
>
getActions
(
SessionData
data
)
{
return
Arrays
.
asList
(
AdHocCommand
.
Action
.
complete
);
}
@Override
protected
AdHocCommand
.
Action
getExecuteAction
(
SessionData
data
)
{
return
AdHocCommand
.
Action
.
complete
;
}
@Override
public
boolean
hasPermission
(
JID
requester
)
{
return
(
super
.
hasPermission
(
requester
)
||
InternalComponentManager
.
getInstance
().
hasComponent
(
requester
))
&&
!
UserManager
.
getUserProvider
().
isReadOnly
();
}
}
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