Search in sources :

Example 6 with UsernamePrincipal

use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.

the class ExampleLoginModule method doCommit.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.auth.jaas.AbstractLoginModule#doCommit()
     */
@Override
protected boolean doCommit() throws Exception {
    // Associate the username and the admin group with the subject.
    getSubject().getPrincipals().add(new UsernamePrincipal(this.username));
    getSubject().getPrincipals().add(new GroupPrincipal("admin"));
    return true;
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal)

Example 7 with UsernamePrincipal

use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.

the class ExampleLoginModule method doAbort.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.auth.jaas.AbstractLoginModule#doAbort()
     */
@Override
protected boolean doAbort() throws Exception {
    // Since it is possible for login to still be aborted even after this module was told to commit,
    // remove the principals we may have added to the subject.
    getSubject().getPrincipals().remove(new UsernamePrincipal(this.username));
    getSubject().getPrincipals().remove(new GroupPrincipal("admin"));
    return true;
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal)

Example 8 with UsernamePrincipal

use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.

the class ActiveDirectoryLoginModule 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);
    if (this.authProvider.isUsingServiceCredentials()) {
        handle(nameCallback);
        passwordCallback.setPassword("".toCharArray());
    } else {
        handle(nameCallback, passwordCallback);
    }
    if (nameCallback.getName() == null) {
        throw new AccountException("No username provided for authentication");
    }
    Principal userPrincipal = new UsernamePrincipal(nameCallback.getName());
    char[] password = passwordCallback.getPassword();
    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userPrincipal, password);
    log.debug("Authenticating: {}", userPrincipal);
    Authentication authenticated = this.authProvider.authenticate(authentication);
    log.debug("Successfully Authenticated: {}", userPrincipal);
    setUserPrincipal(userPrincipal);
    for (GrantedAuthority grant : authenticated.getAuthorities()) {
        String groupName = grant.getAuthority();
        log.debug("Found group for {}: {}", userPrincipal, groupName);
        if (groupName != null) {
            addNewGroupPrincipal(groupName);
        }
    }
    return true;
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) NameCallback(javax.security.auth.callback.NameCallback) AccountException(javax.security.auth.login.AccountException) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) PasswordCallback(javax.security.auth.callback.PasswordCallback) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) Principal(java.security.Principal)

Example 9 with UsernamePrincipal

use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.

the class ActiveDirectoryLoginModuleTest method testLoginTest.

// @Test
public void testLoginTest() throws Exception {
    Subject subject = login("test", "Th1nkb1g!");
    assertThat(subject.getPrincipals()).hasSize(3).contains(new UsernamePrincipal("test"), new GroupPrincipal("Admin"), new GroupPrincipal("Developer"));
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) Subject(javax.security.auth.Subject)

Example 10 with UsernamePrincipal

use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.

the class LdapLoginModuleTest method testLoginTest.

@Test
public void testLoginTest() throws Exception {
    Subject subject = login("test", "user");
    assertThat(subject.getPrincipals()).hasSize(3).contains(new UsernamePrincipal("test"), new GroupPrincipal("admin"), new GroupPrincipal("developer"));
}
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