gnu.inet.encoding.StringprepException Java Examples

The following examples show how to use gnu.inet.encoding.StringprepException. 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: UserManager.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes a user (optional operation).
 *
 * @param user the user to delete.
 */
public void deleteUser(final User user) {
    if (provider.isReadOnly()) {
        throw new UnsupportedOperationException("User provider is read-only.");
    }

    final String username = user.getUsername();
    // Make sure that the username is valid.
    try {
        /*username =*/ Stringprep.nodeprep(username);
    }
    catch (final StringprepException se) {
        throw new IllegalArgumentException("Invalid username: " + username,  se);
    }

    // Fire event.
    final Map<String,Object> params = Collections.emptyMap();
    UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_deleting, params);

    provider.deleteUser(user.getUsername());
    // Remove the user from cache.
    userCache.remove(user.getUsername());
}
 
Example #2
Source File: UserManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new User. Required values are username and password. The email address
 * and name can optionally be {@code null}, unless the UserProvider deems that
 * either of them are required.
 *
 * @param username the new and unique username for the account.
 * @param password the password for the account (plain text).
 * @param name the name of the user, which can be {@code null} unless the UserProvider
 *      deems that it's required.
 * @param email the email address to associate with the new account, which can
 *      be {@code null}, unless the UserProvider deems that it's required.
 * @return a new User.
 * @throws UserAlreadyExistsException if the username already exists in the system.
 * @throws UnsupportedOperationException if the provider does not support the
 *      operation.
 */
public User createUser(String username, final String password, final String name, final String email)
        throws UserAlreadyExistsException
{
    if (provider.isReadOnly()) {
        throw new UnsupportedOperationException("User provider is read-only.");
    }
    if (username == null || username.isEmpty()) {
        throw new IllegalArgumentException("Null or empty username.");
    }
    if (password == null || password.isEmpty()) {
        throw new IllegalArgumentException("Null or empty password.");
    }
    // Make sure that the username is valid.
    try {
        username = Stringprep.nodeprep(username);
    }
    catch (final StringprepException se) {
        throw new IllegalArgumentException("Invalid username: " + username,  se);
    }
    if (provider.isNameRequired() && (name == null || name.matches("\\s*"))) {
        throw new IllegalArgumentException("Invalid or empty name specified with provider that requires name. User: "
                                            + username + " Name: " + name);
    }
    if (provider.isEmailRequired() && !StringUtils.isValidEmailAddress(email)) {
        throw new IllegalArgumentException("Invalid or empty email address specified with provider that requires email address. User: "
                                            + username + " Email: " + email);
    }
    final User user = provider.createUser(username, password, name, email);
    userCache.put(username, user);

    // Fire event.
    final Map<String,Object> params = Collections.emptyMap();
    UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_created, params);

    return user;
}
 
Example #3
Source File: LibIdnXmppStringprep.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Override
public String localprep(String string) throws XmppStringprepException {
	try {
		// Allow unassigned codepoints as of RFC6122 A.2
		return Stringprep.nodeprep(string, true);
	} catch (StringprepException e) {
		throw new XmppStringprepException(string, e);
	}
}
 
Example #4
Source File: LibIdnXmppStringprep.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Override
public String domainprep(String string) throws XmppStringprepException {
	try {
		// Don't allow unassigned because this is a "stored string". See
		// RFC3453 7, RFC3490 4 1) and RFC6122 2.2
		return Stringprep.nameprep(string);
	} catch (StringprepException e) {
		throw new XmppStringprepException(string, e);
	}
}
 
Example #5
Source File: LibIdnXmppStringprep.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Override
public String resourceprep(String string) throws XmppStringprepException {
	try {
		// Allow unassigned codepoints as of RFC6122 B.2
		return Stringprep.resourceprep(string, true);
	} catch (StringprepException e) {
		throw new XmppStringprepException(string, e);
	}
}