Search in sources :

Example 6 with User

use of org.apache.atlas.web.model.User in project incubator-atlas by apache.

the class UserDaoTest method testUserDaowithValidUserLoginAndPassword.

@Test
public void testUserDaowithValidUserLoginAndPassword() {
    Properties userLogins = new Properties();
    userLogins.put("admin", "ADMIN::admin123");
    UserDao user = new UserDao();
    user.setUserLogins(userLogins);
    User userBean = user.loadUserByUsername("admin");
    assertTrue(userBean.getPassword().equals("admin123"));
    Collection<? extends GrantedAuthority> authorities = userBean.getAuthorities();
    String role = "";
    for (GrantedAuthority gauth : authorities) {
        role = gauth.getAuthority();
    }
    assertTrue("ADMIN".equals(role));
}
Also used : User(org.apache.atlas.web.model.User) UserDao(org.apache.atlas.web.dao.UserDao) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 7 with User

use of org.apache.atlas.web.model.User in project incubator-atlas by apache.

the class AtlasLdapAuthenticationProvider method getLdapBindAuthentication.

private Authentication getLdapBindAuthentication(Authentication authentication) {
    try {
        if (isDebugEnabled) {
            LOG.debug("==> AtlasLdapAuthenticationProvider getLdapBindAuthentication");
        }
        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }
        LdapContextSource ldapContextSource = getLdapContextSource();
        DefaultLdapAuthoritiesPopulator defaultLdapAuthoritiesPopulator = getDefaultLdapAuthoritiesPopulator(ldapContextSource);
        if (ldapUserSearchFilter == null || ldapUserSearchFilter.trim().isEmpty()) {
            ldapUserSearchFilter = "(uid={0})";
        }
        FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch(ldapBase, ldapUserSearchFilter, ldapContextSource);
        userSearch.setSearchSubtree(true);
        BindAuthenticator bindAuthenticator = getBindAuthenticator(userSearch, ldapContextSource);
        LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator, defaultLdapAuthoritiesPopulator);
        if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);
            final UserDetails principal = new User(userName, userPassword, grantedAuths);
            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
            authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
            if (groupsFromUGI) {
                authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
            }
            return authentication;
        } else {
            LOG.error("LDAP Authentication::userName or userPassword is null or empty for userName " + userName);
        }
    } catch (Exception e) {
        LOG.error(" getLdapBindAuthentication LDAP Authentication Failed:", e);
    }
    if (isDebugEnabled) {
        LOG.debug("<== AtlasLdapAuthenticationProvider getLdapBindAuthentication");
    }
    return authentication;
}
Also used : BindAuthenticator(org.springframework.security.ldap.authentication.BindAuthenticator) User(org.apache.atlas.web.model.User) LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) DefaultLdapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationException(org.springframework.security.core.AuthenticationException) UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) FilterBasedLdapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider)

Aggregations

User (org.apache.atlas.web.model.User)7 GrantedAuthority (org.springframework.security.core.GrantedAuthority)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Authentication (org.springframework.security.core.Authentication)4 UserDetails (org.springframework.security.core.userdetails.UserDetails)4 LdapContextSource (org.springframework.ldap.core.support.LdapContextSource)3 BindAuthenticator (org.springframework.security.ldap.authentication.BindAuthenticator)3 LdapAuthenticationProvider (org.springframework.security.ldap.authentication.LdapAuthenticationProvider)3 Properties (java.util.Properties)2 UserDao (org.apache.atlas.web.dao.UserDao)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 ActiveDirectoryLdapAuthenticationProvider (org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider)2 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)2 DefaultLdapAuthoritiesPopulator (org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 AtlasAuthenticationException (org.apache.atlas.web.security.AtlasAuthenticationException)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1