use of org.jivesoftware.openfire.crowd.jaxb.User 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.crowd.jaxb.User 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);
vcard = SAXReaderUtil.readRootElement(str);
} catch (UserNotFoundException unfe) {
LOG.error("Unable to find user '{}' for loading its vcard", username, unfe);
return null;
} catch (ExecutionException e) {
LOG.error("VCard parsing error", e);
return null;
} catch (InterruptedException e) {
LOG.error("VCard parsing interrupted", e);
Thread.currentThread().interrupt();
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.crowd.jaxb.User in project Openfire by igniterealtime.
the class CrowdManager method getGroupMembers.
/**
* Get the members of the given group
* @param groupName the name of the group
* @return a List of String with the usernames members of the given group
* @throws RemoteException if an exception occurred communicating with the crowd server
*/
public List<String> getGroupMembers(String groupName) throws RemoteException {
LOG.debug("Get all members for group:" + groupName);
int maxResults = 100;
int startIndex = 0;
List<String> results = new ArrayList<>();
StringBuilder request = new StringBuilder("group/user/nested?groupname=").append(urlEncode(groupName)).append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
final HttpUriRequest getRequest = RequestBuilder.get(crowdServer.resolve(request.toString() + startIndex)).setConfig(requestConfig).addHeader(HEADER_ACCEPT_APPLICATION_XML).addHeader(HEADER_ACCEPT_CHARSET_UTF8).build();
try (final CloseableHttpResponse response = client.execute(getRequest, clientContext)) {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
handleHTTPError(response);
}
final Users users = JAXB.unmarshal(response.getEntity().getContent(), Users.class);
if (users != null && users.user != null) {
for (final User user : users.user) {
results.add(JID.escapeNode(user.name));
}
if (users.user.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
use of org.jivesoftware.openfire.crowd.jaxb.User in project Openfire by igniterealtime.
the class CrowdManager method getAllUsers.
/**
* Get all the users from Crowd
* @return a List of User containing all the users stored in Crowd
* @throws RemoteException if an exception occurred communicating with the crowd server
*/
public List<User> getAllUsers() throws RemoteException {
LOG.debug("fetching all crowd users");
int maxResults = 100;
int startIndex = 0;
List<User> results = new ArrayList<>();
StringBuilder request = new StringBuilder("search?entity-type=user&expand=user&restriction=active%3dtrue").append("&max-results=").append(maxResults).append("&start-index=");
try {
while (true) {
final HttpUriRequest getRequest = RequestBuilder.get(crowdServer.resolve(request.toString() + startIndex)).setConfig(requestConfig).addHeader(HEADER_ACCEPT_APPLICATION_XML).addHeader(HEADER_ACCEPT_CHARSET_UTF8).build();
try (final CloseableHttpResponse response = client.execute(getRequest, clientContext)) {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
handleHTTPError(response);
}
final Users users = JAXB.unmarshal(response.getEntity().getContent(), Users.class);
if (users != null && users.user != null) {
for (final User user : users.user) {
user.name = JID.escapeNode(user.name);
results.add(user);
}
if (users.user.size() != maxResults) {
break;
} else {
startIndex += maxResults;
}
} else {
break;
}
}
}
} catch (IOException ioe) {
handleError(ioe);
}
return results;
}
Aggregations