Search in sources :

Example 11 with UsernamePrincipal

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;
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 12 with UsernamePrincipal

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;
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal)

Example 13 with UsernamePrincipal

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());
    }
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) NameCallback(javax.security.auth.callback.NameCallback) AccountException(javax.security.auth.login.AccountException) DirContextOperations(org.springframework.ldap.core.DirContextOperations) CredentialException(javax.security.auth.login.CredentialException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) PasswordCallback(javax.security.auth.callback.PasswordCallback) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Principal(java.security.Principal)

Example 14 with UsernamePrincipal

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"));
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) Subject(javax.security.auth.Subject)

Example 15 with UsernamePrincipal

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"));
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

UsernamePrincipal (com.thinkbiganalytics.security.UsernamePrincipal)20 GroupPrincipal (com.thinkbiganalytics.security.GroupPrincipal)9 Principal (java.security.Principal)5 Subject (javax.security.auth.Subject)5 Project (com.thinkbiganalytics.metadata.api.project.Project)3 JcrProject (com.thinkbiganalytics.metadata.modeshape.project.JcrProject)3 NameCallback (javax.security.auth.callback.NameCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)2 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)2 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)2 List (java.util.List)2 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 Session (javax.jcr.Session)2 Test (org.testng.annotations.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 MetadataException (com.thinkbiganalytics.metadata.api.MetadataException)1 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)1