use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class CrowdVCardProvider method loadVCard.
/**
* @see org.jivesoftware.openfire.vcard.DefaultVCardProvider#loadVCard(java.lang.String)
*/
@Override
public Element loadVCard(String username) {
if (LOG.isDebugEnabled()) {
LOG.debug("loadvcard:" + username);
}
if (MUTEX.containsKey(username)) {
// preventing looping
return null;
}
try {
MUTEX.put(username, username);
Element vcard = super.loadVCard(username);
if (vcard == null) {
CrowdUserProvider userProvider = (CrowdUserProvider) UserManager.getUserProvider();
try {
User user = userProvider.getCrowdUser(username);
String str = VCARD_TEMPLATE.replace("@displayname@", user.displayName).replace("@lastname@", user.lastName).replace("@firstname@", user.firstName).replace("@email@", user.email).replace("@nickname@", username);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
vcard = xmlReader.read(new StringReader(str)).getRootElement();
} catch (UserNotFoundException unfe) {
LOG.error("Unable to find user:" + String.valueOf(username) + " for loading its vcard", unfe);
return null;
} catch (DocumentException de) {
LOG.error("vcard parsing error", de);
return null;
}
if (LOG.isDebugEnabled()) {
LOG.debug(vcard != null ? vcard.asXML() : "vcard is null");
}
// store this new vcard
if (vcard != null) {
try {
createVCard(username, vcard);
} catch (AlreadyExistsException aee) {
LOG.error("Unable to create and store a new vcard for user:" + username + "; one already exists", aee);
}
}
}
return vcard;
} catch (RuntimeException re) {
LOG.error("Failure occured when loading a vcard for user:" + username, re);
throw re;
} finally {
MUTEX.remove(username);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class CrowdVCardProvider method updateVCard.
/**
* @see org.jivesoftware.openfire.vcard.DefaultVCardProvider#updateVCard(java.lang.String, org.dom4j.Element)
*/
@Override
public Element updateVCard(String username, Element vCard) throws NotFoundException {
// make sure some properties have not been overridden
Element nickNameNode = vCard.element("NICKNAME");
Element displayNameNode = vCard.element("FN");
Element nameNode = vCard.element("N");
Element lastNameNode = nameNode.element("FAMILY");
Element firstnameNode = nameNode.element("GIVEN");
Element emailNode = vCard.element("EMAIL").element("USERID");
CrowdUserProvider userProvider = (CrowdUserProvider) UserManager.getUserProvider();
try {
User user = userProvider.getCrowdUser(username);
nickNameNode.setText(username);
displayNameNode.setText(user.displayName);
lastNameNode.setText(user.lastName);
firstnameNode.setText(user.firstName);
emailNode.setText(user.email);
} catch (UserNotFoundException unfe) {
LOG.error("Unable to find user:" + String.valueOf(username) + " for updating its vcard", unfe);
}
if (LOG.isDebugEnabled()) {
LOG.debug("updatevcard:" + vCard.asXML());
}
return super.updateVCard(username, vCard);
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class AuthenticateUser method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
JID account;
try {
account = new JID(data.getData().get("accountjid").get(0));
} catch (NullPointerException ne) {
note.addAttribute("type", "error");
note.setText("JID required parameter.");
return;
}
if (!XMPPServer.getInstance().isLocal(account)) {
note.addAttribute("type", "error");
note.setText("Cannot authenticate remote user.");
return;
}
String password = data.getData().get("password").get(0);
// Get requested user
User user;
try {
user = UserManager.getInstance().getUser(account.getNode());
} catch (UserNotFoundException e) {
// User not found
note.addAttribute("type", "error");
note.setText("User does not exists.");
return;
}
try {
AuthFactory.authenticate(user.getUsername(), password);
} catch (UnauthorizedException | ConnectionException | InternalUnauthenticatedException e) {
// Auth failed
note.addAttribute("type", "error");
note.setText("Authentication failed.");
return;
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully.");
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class UserDeleting method execute.
@Override
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Gets the username
String username;
try {
username = get(data, "username", 0);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Sends the event
User user;
try {
// Gets current user
user = UserManager.getInstance().getUser(username);
Map<String, Object> params = Collections.emptyMap();
UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_deleting, params);
} catch (UserNotFoundException e) {
// It's ok, user doesn't exist, so deleting it is nothing
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class UserModified method execute.
@Override
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the username
String username;
try {
username = get(data, "username", 0);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Get the modification type
String type;
try {
type = get(data, "changeType", 0);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Change type required parameter.");
return;
}
// Identifies the value variable
String valueVariable = null;
String valueVariableName = null;
if ("nameModified".equals(type) || "emailModified".equals(type) || "creationDateModified".equals(type) || "modificationDateModified".equals(type)) {
valueVariable = "originalValue";
valueVariableName = "Original value";
} else if ("propertyModified".equals(type) || "propertyAdded".equals(type) || "propertyDeleted".equals(type)) {
valueVariable = "propertyKey";
valueVariableName = "Property key";
}
// Creates event params.
Map<String, Object> params = new HashMap<>();
// Gets the value of the change if it exist
String value;
if (valueVariable != null) {
try {
// Gets the value
value = get(data, valueVariable, 0);
// Adds it to the event params
params.put(valueVariable, value);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText(valueVariableName + " required parameter.");
return;
}
}
// Adds the type of change
params.put("type", type);
// Sends the event
User user;
try {
// Loads the updated user
user = UserManager.getUserProvider().loadUser(username);
// Fire event.
UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_modified, params);
} 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");
}
Aggregations