Commit ed07049a by Shwetha GS

ATLAS-968 Set group information from UGI for Ldap authentication (nixonrodrigues via shwethags)

parent dda382f4
...@@ -101,6 +101,8 @@ atlas.authentication.method.ldap.type=LDAP ...@@ -101,6 +101,8 @@ atlas.authentication.method.ldap.type=LDAP
#### user credentials file #### user credentials file
atlas.authentication.method.file.filename=${sys:atlas.home}/conf/users-credentials.properties atlas.authentication.method.file.filename=${sys:atlas.home}/conf/users-credentials.properties
### groups from UGI
#atlas.authentication.method.ldap.ugi-groups=true
######## LDAP properties ######### ######## LDAP properties #########
#atlas.authentication.method.ldap.url=ldap://<ldap server url>:389 #atlas.authentication.method.ldap.url=ldap://<ldap server url>:389
......
...@@ -6,6 +6,7 @@ INCOMPATIBLE CHANGES: ...@@ -6,6 +6,7 @@ INCOMPATIBLE CHANGES:
ALL CHANGES: ALL CHANGES:
ATLAS-968 Set group information from UGI for Ldap authentication (nixonrodrigues via shwethags)
ATLAS-584 Integrate CSRF prevention filter (kevalbhatt18 via shwethags) ATLAS-584 Integrate CSRF prevention filter (kevalbhatt18 via shwethags)
ATLAS-963 UI: Entity details is not display String array attribute values correctly (kevalbhatt18 via shwethags) ATLAS-963 UI: Entity details is not display String array attribute values correctly (kevalbhatt18 via shwethags)
ATLAS-988 HiveHookIT.testInsertIntoTable is broken (svimal2106 via shwethags) ATLAS-988 HiveHookIT.testInsertIntoTable is broken (svimal2106 via shwethags)
......
...@@ -48,6 +48,7 @@ public class AtlasADAuthenticationProvider extends ...@@ -48,6 +48,7 @@ public class AtlasADAuthenticationProvider extends
private String adBase; private String adBase;
private String adReferral; private String adReferral;
private String adDefaultRole; private String adDefaultRole;
private boolean groupsFromUGI;
@PostConstruct @PostConstruct
public void setup() { public void setup() {
...@@ -85,6 +86,9 @@ public class AtlasADAuthenticationProvider extends ...@@ -85,6 +86,9 @@ public class AtlasADAuthenticationProvider extends
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken( final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(
principal, userPassword, grantedAuths); principal, userPassword, grantedAuths);
authentication = adAuthenticationProvider.authenticate(finalAuthentication); authentication = adAuthenticationProvider.authenticate(finalAuthentication);
if(groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication; return authentication;
} else { } else {
throw new AtlasAuthenticationException( throw new AtlasAuthenticationException(
...@@ -109,6 +113,7 @@ public class AtlasADAuthenticationProvider extends ...@@ -109,6 +113,7 @@ public class AtlasADAuthenticationProvider extends
this.adBase = configuration.getString("atlas.authentication.method.ldap.ad.base.dn"); this.adBase = configuration.getString("atlas.authentication.method.ldap.ad.base.dn");
this.adReferral = configuration.getString("atlas.authentication.method.ldap.ad.referral"); this.adReferral = configuration.getString("atlas.authentication.method.ldap.ad.referral");
this.adDefaultRole = configuration.getString("atlas.authentication.method.ldap.ad.default.role"); this.adDefaultRole = configuration.getString("atlas.authentication.method.ldap.ad.default.role");
this.groupsFromUGI = configuration.getBoolean("atlas.authentication.method.ldap.ugi-groups", true);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Exception while setADProperties", e); LOG.error("Exception while setADProperties", e);
......
...@@ -22,6 +22,7 @@ package org.apache.atlas.web.security; ...@@ -22,6 +22,7 @@ package org.apache.atlas.web.security;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.hadoop.security.UserGroupInformation;
import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
...@@ -71,4 +72,38 @@ public abstract class AtlasAbstractAuthenticationProvider implements ...@@ -71,4 +72,38 @@ public abstract class AtlasAbstractAuthenticationProvider implements
return grantedAuths; return grantedAuths;
} }
public Authentication getAuthenticationWithGrantedAuthorityFromUGI(
Authentication authentication) {
UsernamePasswordAuthenticationToken result = null;
if (authentication != null && authentication.isAuthenticated()) {
List<GrantedAuthority> grantedAuthsUGI = getAuthoritiesFromUGI(authentication
.getName().toString());
final UserDetails userDetails = new User(authentication.getName()
.toString(), authentication.getCredentials().toString(),
grantedAuthsUGI);
result = new UsernamePasswordAuthenticationToken(userDetails,
authentication.getCredentials(), grantedAuthsUGI);
result.setDetails(authentication.getDetails());
return result;
}
return authentication;
}
public 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));
}
}
}
return grantedAuths;
}
} }
...@@ -54,6 +54,7 @@ public class AtlasLdapAuthenticationProvider extends ...@@ -54,6 +54,7 @@ public class AtlasLdapAuthenticationProvider extends
private String ldapUserSearchFilter; private String ldapUserSearchFilter;
private String ldapReferral; private String ldapReferral;
private String ldapBase; private String ldapBase;
private boolean groupsFromUGI;
@PostConstruct @PostConstruct
public void setup() { public void setup() {
...@@ -107,6 +108,9 @@ public class AtlasLdapAuthenticationProvider extends ...@@ -107,6 +108,9 @@ public class AtlasLdapAuthenticationProvider extends
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken( final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(
principal, userPassword, grantedAuths); principal, userPassword, grantedAuths);
authentication = ldapAuthenticationProvider.authenticate(finalAuthentication); authentication = ldapAuthenticationProvider.authenticate(finalAuthentication);
if(groupsFromUGI) {
authentication = getAuthenticationWithGrantedAuthorityFromUGI(authentication);
}
return authentication; return authentication;
} else { } else {
throw new AtlasAuthenticationException( throw new AtlasAuthenticationException(
...@@ -141,6 +145,7 @@ public class AtlasLdapAuthenticationProvider extends ...@@ -141,6 +145,7 @@ public class AtlasLdapAuthenticationProvider extends
"atlas.authentication.method.ldap.user.searchfilter"); "atlas.authentication.method.ldap.user.searchfilter");
ldapReferral = configuration.getString("atlas.authentication.method.ldap.ad.referral"); ldapReferral = configuration.getString("atlas.authentication.method.ldap.ad.referral");
ldapBase = configuration.getString("atlas.authentication.method.ldap.base.dn"); ldapBase = configuration.getString("atlas.authentication.method.ldap.base.dn");
groupsFromUGI = configuration.getBoolean("atlas.authentication.method.ldap.ugi-groups", true);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Exception while setLdapProperties", e); LOG.error("Exception while setLdapProperties", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment