Search in sources :

Example 6 with UserNotFoundException

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);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.crowd.jaxb.User) AlreadyExistsException(org.jivesoftware.util.AlreadyExistsException) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader)

Example 7 with UserNotFoundException

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);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.crowd.jaxb.User) Element(org.dom4j.Element)

Example 8 with UserNotFoundException

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.");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) InternalUnauthenticatedException(org.jivesoftware.openfire.auth.InternalUnauthenticatedException) ConnectionException(org.jivesoftware.openfire.auth.ConnectionException)

Example 9 with UserNotFoundException

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");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) Element(org.dom4j.Element) List(java.util.List)

Example 10 with UserNotFoundException

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");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) HashMap(java.util.HashMap) Element(org.dom4j.Element) List(java.util.List)

Aggregations

UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)118 JID (org.xmpp.packet.JID)50 Element (org.dom4j.Element)28 Roster (org.jivesoftware.openfire.roster.Roster)27 RosterItem (org.jivesoftware.openfire.roster.RosterItem)26 User (org.jivesoftware.openfire.user.User)25 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)23 IQ (org.xmpp.packet.IQ)15 ArrayList (java.util.ArrayList)14 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)12 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)11 Group (org.jivesoftware.openfire.group.Group)10 UserManager (org.jivesoftware.openfire.user.UserManager)10 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)10 Presence (org.xmpp.packet.Presence)10 NotFoundException (org.jivesoftware.util.NotFoundException)9 SQLException (java.sql.SQLException)8 List (java.util.List)8 IOException (java.io.IOException)7 Connection (java.sql.Connection)7