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;
}
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;
}
Aggregations