use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class AuthServiceLoginModule method doLogin.
@Override
public boolean doLogin() throws Exception {
NameCallback nameCb = new NameCallback("username");
PasswordCallback passwordCb = new PasswordCallback("password", false);
handle(nameCb, passwordCb);
if (this.authService.authenticate(nameCb.getName(), passwordCb.getPassword())) {
log.debug("Login success for: {}", nameCb.getName());
this.user = new UsernamePrincipal(nameCb.getName());
} else {
log.debug("Login failure for: {}", nameCb.getName());
}
passwordCb.clearPassword();
return true;
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class AbstractLoginModule method addNewUserPrincipal.
protected UsernamePrincipal addNewUserPrincipal(String username) {
UsernamePrincipal user = new UsernamePrincipal(username);
setUserPrincipal(user);
return user;
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class LdapLoginModule method doLogin.
/* (non-Javadoc)
* @see com.thinkbiganalytics.auth.jaas.AbstractLoginModule#doLogin()
*/
@Override
protected boolean doLogin() throws Exception {
final NameCallback nameCallback = new NameCallback("Username: ");
final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
handle(nameCallback, passwordCallback);
if (nameCallback.getName() == null) {
throw new AccountException("No username provided for authentication");
}
Principal userPrincipal = new UsernamePrincipal(nameCallback.getName());
String password = new String(passwordCallback.getPassword());
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userPrincipal, password);
try {
log.debug("Authenticating: {}", userPrincipal);
DirContextOperations dirContext = this.authenticator.authenticate(authentication);
log.debug("Successfully Authenticated: {}", userPrincipal);
setUserPrincipal(userPrincipal);
for (GrantedAuthority grant : this.authoritiesPopulator.getGrantedAuthorities(dirContext, nameCallback.getName())) {
String groupName = grant.getAuthority();
log.debug("Found group for {}: {}", userPrincipal, groupName);
if (groupName != null) {
addNewGroupPrincipal(groupName);
}
}
return true;
} catch (BadCredentialsException e) {
throw new CredentialException(e.getMessage());
}
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class ActiveDirectoryLoginModuleTest method testLoginAdmin.
// @Test
public void testLoginAdmin() throws Exception {
Subject subject = login("dladmin", "Th1nkb1g!");
assertThat(subject.getPrincipals()).contains(new UsernamePrincipal("dladmin"), new GroupPrincipal("Admin"));
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class LdapLoginModuleTest method testLoginAdmin.
@Test
public void testLoginAdmin() throws Exception {
Subject subject = login("dladmin", "thinkbig");
assertThat(subject.getPrincipals()).hasSize(2).contains(new UsernamePrincipal("dladmin"), new GroupPrincipal("admin"));
}
Aggregations