Search in sources :

Example 6 with CredentialException

use of javax.security.auth.login.CredentialException in project kylo by Teradata.

the class KyloLoginModule method doLogin.

@Override
protected boolean doLogin() throws Exception {
    // Get username and password
    final NameCallback nameCallback = new NameCallback("Username: ");
    final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
    if (requirePassword) {
        handle(nameCallback, passwordCallback);
    } else {
        handle(nameCallback);
    }
    // Authenticate user
    metadata.read(() -> {
        Optional<User> user = userProvider.findUserBySystemName(nameCallback.getName());
        if (user.isPresent()) {
            if (!user.get().isEnabled()) {
                throw new AccountLockedException("The account \"" + nameCallback.getName() + "\" is currently disabled");
            } else if (requirePassword && !passwordEncoder.matches(new String(passwordCallback.getPassword()), user.get().getPassword())) {
                throw new CredentialException("The username and/or password combination do not match");
            }
            addPrincipal(user.get().getPrincipal());
            addAllPrincipals(user.get().getAllGroupPrincipals());
        } else {
            throw new AccountNotFoundException("No account exists with name name \"" + nameCallback.getName() + "\"");
        }
    }, MetadataAccess.SERVICE);
    return true;
}
Also used : AccountLockedException(javax.security.auth.login.AccountLockedException) NameCallback(javax.security.auth.callback.NameCallback) User(com.thinkbiganalytics.metadata.api.user.User) CredentialException(javax.security.auth.login.CredentialException) PasswordCallback(javax.security.auth.callback.PasswordCallback) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException)

Example 7 with CredentialException

use of javax.security.auth.login.CredentialException in project kylo by Teradata.

the class ExampleLoginModule method doLogin.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.auth.jaas.AbstractLoginModule#doLogin()
     */
@Override
protected boolean doLogin() throws Exception {
    // This method performs authentication and returns true if successful
    // or throws a LoginException (or subclass) on failure.  Returning false
    // means that this module should not participate in this login attempt.
    // In this example we'll just use whatever username and password (if present) were provided as
    // configuration options to match the credentials of the current authenticating user.
    // Ask the system for the username/password to be authenticated using callbacks.
    final NameCallback nameCallback = new NameCallback("Username: ");
    final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
    // Have the system fill in the requested values (username/password) by setting them in each callback.
    handle(nameCallback, passwordCallback);
    if (!this.username.equals(nameCallback.getName())) {
        throw new CredentialException("The username and/or password are invalid");
    }
    if (this.password.length > 0 && !Arrays.equals(this.password, passwordCallback.getPassword())) {
        throw new CredentialException("The username and/or password are invalid");
    }
    return true;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) CredentialException(javax.security.auth.login.CredentialException) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Aggregations

CredentialException (javax.security.auth.login.CredentialException)7 NameCallback (javax.security.auth.callback.NameCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 Buffer (io.vertx.core.buffer.Buffer)2 ArrayList (java.util.ArrayList)2 AccountLockedException (javax.security.auth.login.AccountLockedException)2 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)2 User (com.thinkbiganalytics.metadata.api.user.User)1 UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)1 User (com.thinkbiganalytics.security.rest.model.User)1 Principal (java.security.Principal)1 AccountException (javax.security.auth.login.AccountException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ClientErrorException (org.eclipse.hono.client.ClientErrorException)1 DirContextOperations (org.springframework.ldap.core.DirContextOperations)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1