Java Code Examples for org.jivesoftware.openfire.user.UserManager#getInstance()

The following examples show how to use org.jivesoftware.openfire.user.UserManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProperties.java    From Openfire with Apache License 2.0 6 votes vote down vote up
private void populateResponseFields(DataForm form, List<String> accounts) {
    FormField jidField = form.addField();
    jidField.setVariable("accountjids");

    FormField emailField = form.addField();
    emailField.setVariable("email");

    FormField nameField = form.addField();
    nameField.setVariable("name");

    UserManager manager = UserManager.getInstance();
    for(String account : accounts) {
        User user;
        try {
            JID jid = new JID(account);
            user = manager.getUser(jid.getNode());
        }
        catch (Exception ex) {
            continue;
        }

        jidField.addValue(account);
        emailField.addValue(user.getEmail());
        nameField.addValue(user.getName());
    }
}
 
Example 2
Source File: JDBCAuthProvider.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if the user exists; if not, a new user is created.
 *
 * @param username the username.
 */
// @VisibleForTesting
protected void createUser(String username) {
    // See if the user exists in the database. If not, automatically create them.
    UserManager userManager = UserManager.getInstance();
    try {
        userManager.getUser(username);
    }
    catch (UserNotFoundException unfe) {
        try {
            Log.debug("JDBCAuthProvider: Automatically creating new user account for " + username);
            UserManager.getUserProvider().createUser(username, StringUtils.randomString(8),
                    null, null);
        }
        catch (UserAlreadyExistsException uaee) {
            // Ignore.
        }
    }
}
 
Example 3
Source File: LdapGroupProvider.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new LDAP group provider.
 */
public LdapGroupProvider() {
    manager = LdapManager.getInstance();
    userManager = UserManager.getInstance();
    standardAttributes = new String[3];
    standardAttributes[0] = manager.getGroupNameField();
    standardAttributes[1] = manager.getGroupDescriptionField();
    standardAttributes[2] = manager.getGroupMemberField();
}
 
Example 4
Source File: FlattenNestedGroupsTest.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Test
public void testConnection() throws Exception {
    initLdapManager(false, false);

    LdapManager ldapManager = LdapManager.getInstance();
    assertEquals("cn=admins,ou=groups,dc=mobikat,dc=net", ldapManager.findGroupAbsoluteDN("admins").toString());

    UserManager userManager = UserManager.getInstance();

    User user = userManager.getUser("j.bond");
    assertNotNull(user);
    assertEquals("James Bond", user.getName());
}
 
Example 5
Source File: NativeAuthProvider.java    From Openfire with Apache License 2.0 4 votes vote down vote up
@Override
public void authenticate(String username, String password) throws UnauthorizedException {
    if (username.contains("@")) {
        // Check that the specified domain matches the server's domain
        int index = username.indexOf("@");
        String domain = username.substring(index + 1);
        if (domain.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
            username = username.substring(0, index);
        } else {
            // Unknown domain. Return authentication failed.
            throw new UnauthorizedException();
        }
    }
    try {
        // Some native authentication mechanisms appear to not handle high load
        // very well. Therefore, synchronize access to Shaj to throttle auth checks.
        synchronized (this) {
            if (!Shaj.checkPassword(domain, username, password)) {
                throw new UnauthorizedException();
            }
        }
    }
    catch (UnauthorizedException ue) {
        throw ue;
    }
    catch (Exception e) {
        throw new UnauthorizedException(e);
    }

    // See if the user exists in the database. If not, automatically create them.
    UserManager userManager = UserManager.getInstance();
    try {
        userManager.getUser(username);
    }
    catch (UserNotFoundException unfe) {
        try {
            Log.debug("Automatically creating new user account for " + username);
            // Create user; use a random password for better safety in the future.
            // Note that we have to go to the user provider directly -- because the
            // provider is read-only, UserManager will usually deny access to createUser.
            UserProvider provider = UserManager.getUserProvider();
            if (!(provider instanceof NativeUserProvider)) {
                Log.error("Error: not using NativeUserProvider so authentication with " +
                        "NativeAuthProvider will likely fail. Using: " +
                        provider.getClass().getName());
            }
            UserManager.getUserProvider().createUser(username, StringUtils.randomString(8),
                    null, null);
        }
        catch (UserAlreadyExistsException uaee) {
            // Ignore.
        }
    }
}
 
Example 6
Source File: XMPPServer.java    From Openfire with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the <code>UserManager</code> registered with this server. The
 * <code>UserManager</code> was registered with the server as a module while starting up
 * the server.
 *
 * @return the <code>UserManager</code> registered with this server.
 */
public UserManager getUserManager() {
    return UserManager.getInstance();
}