Commit 2c650829 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Fixed CS lock out provider's interactions with clearspace.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9948 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8aecdf80
...@@ -22,6 +22,8 @@ import org.dom4j.Element; ...@@ -22,6 +22,8 @@ import org.dom4j.Element;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import java.util.List;
/** /**
* The ClearspaceLockOutProvider uses the UserService web service inside of Clearspace * The ClearspaceLockOutProvider uses the UserService web service inside of Clearspace
* to retrieve user properties from Clearspace. One of these properties refers to whether * to retrieve user properties from Clearspace. One of these properties refers to whether
...@@ -64,12 +66,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -64,12 +66,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
* @see org.jivesoftware.openfire.lockout.LockOutProvider#setDisabledStatus(org.jivesoftware.openfire.lockout.LockOutFlag) * @see org.jivesoftware.openfire.lockout.LockOutProvider#setDisabledStatus(org.jivesoftware.openfire.lockout.LockOutFlag)
*/ */
public void setDisabledStatus(LockOutFlag flag) { public void setDisabledStatus(LockOutFlag flag) {
try { setEnabledStatus(flag.getUsername(), false);
setUserData(setEnabledStatus(getUserByUsername(flag.getUsername()), false));
}
catch (UserNotFoundException e) {
Log.error("Unable to set disabled status for Clearspace user: "+flag.getUsername());
}
} }
/** /**
...@@ -77,12 +74,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -77,12 +74,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
* @see org.jivesoftware.openfire.lockout.LockOutProvider#unsetDisabledStatus(String) * @see org.jivesoftware.openfire.lockout.LockOutProvider#unsetDisabledStatus(String)
*/ */
public void unsetDisabledStatus(String username) { public void unsetDisabledStatus(String username) {
try { setEnabledStatus(username, true);
setUserData(setEnabledStatus(getUserByUsername(username), true));
}
catch (UserNotFoundException e) {
Log.error("Unable to set enabled status for Clearspace user: "+username);
}
} }
/** /**
...@@ -110,22 +102,52 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -110,22 +102,52 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
} }
/** /**
* Modifies the XML returned about a user to indicate whether they are enabled or disabled. * Looks up and modifies a user's CS properties to indicate whether they are enabled or disabled.
* It is important for this to incorporate the existing user data and only tweak the field * It is important for this to incorporate the existing user data and only tweak the field
* that we want to change. * that we want to change.
* *
* @param responseNode The node returned from user data request. * @param username Username of user to set status of.
* @param enabled Whether the account should be enabled or disabled. * @param enabled Whether the account should be enabled or disabled.
* @return A modified user data node with appropriate settings for whether they are disabled or enabled.
*/ */
private Node setEnabledStatus(Node responseNode, Boolean enabled) { private void setEnabledStatus(String username, Boolean enabled) {
Node userNode = responseNode.selectSingleNode("return"); try {
Element user = getUserByUsername(username);
Element modifiedUser = modifyUser(user.element("return"), "enabled", enabled ? "true" : "false");
// Sets the enabled status String path = USER_URL_PREFIX + "users";
userNode.selectSingleNode("enabled").setText(enabled ? "true" : "false"); manager.executeRequest(PUT, path, modifiedUser.asXML());
}
catch (UserNotFoundException e) {
Log.error("User with name " + username + " not found.", e);
}
catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
throw new UnsupportedOperationException("Unexpected error", e);
}
}
// Returns the modified node. /**
return userNode; * Modifies user properties XML by replacing a particular attribute setting to something new.
*
* @param user User data XML.
* @param attributeName Name of attribute to replace.
* @param newValue New value for attribute.
* @return Modified element.
*/
private Element modifyUser(Element user, String attributeName, String newValue) {
Document groupDoc = DocumentHelper.createDocument();
Element rootE = groupDoc.addElement("updateUser");
Element newUser = rootE.addElement("user");
List userAttributes = user.elements();
for (Object userAttributeObj : userAttributes) {
Element userAttribute = (Element)userAttributeObj;
if (userAttribute.getName().equals(attributeName)) {
newUser.addElement(userAttribute.getName()).setText(newValue);
} else {
newUser.addElement(userAttribute.getName()).setText(userAttribute.getText());
}
}
return rootE;
} }
/** /**
...@@ -137,6 +159,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -137,6 +159,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
* @throws NotLockedOutException if the user is not currently locked out. * @throws NotLockedOutException if the user is not currently locked out.
*/ */
private LockOutFlag checkUserDisabled(Node responseNode) throws NotLockedOutException { private LockOutFlag checkUserDisabled(Node responseNode) throws NotLockedOutException {
try {
Node userNode = responseNode.selectSingleNode("return"); Node userNode = responseNode.selectSingleNode("return");
// Gets the username // Gets the username
...@@ -153,6 +176,12 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -153,6 +176,12 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
return new LockOutFlag(username, null, null); return new LockOutFlag(username, null, null);
} }
} }
catch (Exception e) {
// Hrm. This is not good. We have to opt on the side of positive.
Log.error("Error while looking up user's disabled status from Clearspace: ", e);
throw new NotLockedOutException();
}
}
/** /**
* Retrieves user properties for a Clearspace user in XML format. * Retrieves user properties for a Clearspace user in XML format.
...@@ -170,30 +199,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider { ...@@ -170,30 +199,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
} }
catch (Exception e) { catch (Exception e) {
// It is not supported exception, wrap it into an UserNotFoundException // It is not supported exception, wrap it into an UserNotFoundException
throw new UserNotFoundException("Error loading the user", e); throw new UserNotFoundException("Error loading the user from Clearspace: ", e);
}
}
/**
* Sets user properties data for a Clearspace user.
*
* @param node XML data to send to Clearspace REST service.
*/
private void setUserData(Node node) {
try {
// Requests the user
String path = USER_URL_PREFIX + "users";
// Creates the XML with the data
Document userDoc = DocumentHelper.createDocument();
Element rootE = userDoc.addElement("updateUser");
rootE.add(node);
manager.executeRequest(PUT, path, userDoc.asXML());
}
catch (Exception e) {
// Error while setting properties?
Log.error("Unable to set user data via REST service in Clearspace:", e);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment