Search in sources :

Example 26 with Groups

use of org.apache.hadoop.security.Groups in project atlas by apache.

the class AtlasAbstractAuthenticationProvider method getAuthoritiesFromUGI.

public static List<GrantedAuthority> getAuthoritiesFromUGI(String userName) {
    List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName);
    if (ugi != null) {
        String[] userGroups = ugi.getGroupNames();
        if (userGroups != null) {
            for (String group : userGroups) {
                grantedAuths.add(new SimpleGrantedAuthority(group));
            }
        }
    }
    // if group empty take groups from UGI LDAP-based group mapping
    if (grantedAuths != null && grantedAuths.isEmpty()) {
        try {
            Configuration config = new Configuration();
            Groups gp = new Groups(config);
            List<String> userGroups = gp.getGroups(userName);
            if (userGroups != null) {
                for (String group : userGroups) {
                    grantedAuths.add(new SimpleGrantedAuthority(group));
                }
            }
        } catch (java.io.IOException e) {
            LOG.error("Exception while fetching groups ", e);
        }
    }
    return grantedAuths;
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Configuration(org.apache.hadoop.conf.Configuration) Groups(org.apache.hadoop.security.Groups) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 27 with Groups

use of org.apache.hadoop.security.Groups in project knox by apache.

the class HadoopGroupProviderFilter method init.

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    super.init(filterConfig);
    try {
        hadoopConfig = new Configuration(false);
        if (filterConfig.getInitParameterNames() != null) {
            for (final Enumeration<String> keys = filterConfig.getInitParameterNames(); keys.hasMoreElements(); ) {
                final String key = keys.nextElement();
                hadoopConfig.set(key, filterConfig.getInitParameter(key));
            }
        }
        hadoopGroups = new Groups(hadoopConfig);
    } catch (final Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Configuration(org.apache.hadoop.conf.Configuration) Groups(org.apache.hadoop.security.Groups) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 28 with Groups

use of org.apache.hadoop.security.Groups in project zeppelin by apache.

the class KnoxJwtRealm method onInit.

@Override
protected void onInit() {
    super.onInit();
    try {
        Configuration hadoopConfig = new Configuration();
        hadoopGroups = new Groups(hadoopConfig);
    } catch (final Exception e) {
        LOGGER.error("Exception in onInit", e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Groups(org.apache.hadoop.security.Groups) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 29 with Groups

use of org.apache.hadoop.security.Groups in project incubator-atlas by apache.

the class AtlasAbstractAuthenticationProvider method getAuthoritiesFromUGI.

public static List<GrantedAuthority> getAuthoritiesFromUGI(String userName) {
    List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName);
    if (ugi != null) {
        String[] userGroups = ugi.getGroupNames();
        if (userGroups != null) {
            for (String group : userGroups) {
                grantedAuths.add(new SimpleGrantedAuthority(group));
            }
        }
    }
    // if group empty take groups from UGI LDAP-based group mapping
    if (grantedAuths != null && grantedAuths.isEmpty()) {
        try {
            Configuration config = new Configuration();
            Groups gp = new Groups(config);
            List<String> userGroups = gp.getGroups(userName);
            if (userGroups != null) {
                for (String group : userGroups) {
                    grantedAuths.add(new SimpleGrantedAuthority(group));
                }
            }
        } catch (java.io.IOException e) {
            LOG.error("Exception while fetching groups ", e);
        }
    }
    return grantedAuths;
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Configuration(org.apache.hadoop.conf.Configuration) Groups(org.apache.hadoop.security.Groups) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

Groups (org.apache.hadoop.security.Groups)29 Test (org.junit.Test)19 IOException (java.io.IOException)14 FakeTimer (org.apache.hadoop.util.FakeTimer)10 Configuration (org.apache.hadoop.conf.Configuration)8 ArrayList (java.util.ArrayList)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)3 ServletException (javax.servlet.ServletException)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Principal (java.security.Principal)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 CertificateException (java.security.cert.CertificateException)1 ParseException (java.text.ParseException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Subject (javax.security.auth.Subject)1