Search in sources :

Example 1 with AtlasAuthenticationException

use of org.apache.atlas.web.security.AtlasAuthenticationException in project incubator-atlas by apache.

the class UserDao method getSha256Hash.

public static String getSha256Hash(String base) throws AtlasAuthenticationException {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(base.getBytes("UTF-8"));
        StringBuffer hexString = new StringBuffer();
        for (byte aHash : hash) {
            String hex = Integer.toHexString(0xff & aHash);
            if (hex.length() == 1)
                hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    } catch (Exception ex) {
        throw new AtlasAuthenticationException("Exception while encoding password.", ex);
    }
}
Also used : MessageDigest(java.security.MessageDigest) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 2 with AtlasAuthenticationException

use of org.apache.atlas.web.security.AtlasAuthenticationException in project atlas by apache.

the class UserDao method loadUserByUsername.

public User loadUserByUsername(final String username) throws AuthenticationException {
    String userdetailsStr = userLogins.getProperty(username);
    if (userdetailsStr == null || userdetailsStr.isEmpty()) {
        throw new UsernameNotFoundException("Username not found." + username);
    }
    String password = "";
    String role = "";
    String[] dataArr = userdetailsStr.split("::");
    if (dataArr != null && dataArr.length == 2) {
        role = dataArr[0];
        password = dataArr[1];
    } else {
        LOG.error("User role credentials is not set properly for {}", username);
        throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
    }
    List<GrantedAuthority> grantedAuths = new ArrayList<>();
    if (StringUtils.hasText(role)) {
        grantedAuths.add(new SimpleGrantedAuthority(role));
    } else {
        LOG.error("User role credentials is not set properly for {}", username);
        throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
    }
    User userDetails = new User(username, password, grantedAuths);
    return userDetails;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.apache.atlas.web.model.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException)

Example 3 with AtlasAuthenticationException

use of org.apache.atlas.web.security.AtlasAuthenticationException in project atlas by apache.

the class UserDao method getSha256Hash.

public static String getSha256Hash(String base) throws AtlasAuthenticationException {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(base.getBytes("UTF-8"));
        StringBuffer hexString = new StringBuffer();
        for (byte aHash : hash) {
            String hex = Integer.toHexString(0xff & aHash);
            if (hex.length() == 1)
                hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    } catch (Exception ex) {
        throw new AtlasAuthenticationException("Exception while encoding password.", ex);
    }
}
Also used : MessageDigest(java.security.MessageDigest) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 4 with AtlasAuthenticationException

use of org.apache.atlas.web.security.AtlasAuthenticationException in project incubator-atlas by apache.

the class UserDao method loadUserByUsername.

public User loadUserByUsername(final String username) throws AuthenticationException {
    String userdetailsStr = userLogins.getProperty(username);
    if (userdetailsStr == null || userdetailsStr.isEmpty()) {
        throw new UsernameNotFoundException("Username not found." + username);
    }
    String password = "";
    String role = "";
    String[] dataArr = userdetailsStr.split("::");
    if (dataArr != null && dataArr.length == 2) {
        role = dataArr[0];
        password = dataArr[1];
    } else {
        LOG.error("User role credentials is not set properly for {}", username);
        throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
    }
    List<GrantedAuthority> grantedAuths = new ArrayList<>();
    if (StringUtils.hasText(role)) {
        grantedAuths.add(new SimpleGrantedAuthority(role));
    } else {
        LOG.error("User role credentials is not set properly for {}", username);
        throw new AtlasAuthenticationException("User role credentials is not set properly for " + username);
    }
    User userDetails = new User(username, password, grantedAuths);
    return userDetails;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.apache.atlas.web.model.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException)

Aggregations

AtlasAuthenticationException (org.apache.atlas.web.security.AtlasAuthenticationException)4 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)4 IOException (java.io.IOException)2 MessageDigest (java.security.MessageDigest)2 ArrayList (java.util.ArrayList)2 AtlasException (org.apache.atlas.AtlasException)2 User (org.apache.atlas.web.model.User)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2