use of org.ow2.proactive.authentication.principals.GroupNamePrincipal in project scheduling by ow2-proactive.
the class Client method getGroups.
public Set<String> getGroups() {
Set<String> answer = new HashSet<>();
Set<GroupNamePrincipal> groupPrincipals = subject.getPrincipals(GroupNamePrincipal.class);
for (GroupNamePrincipal principal : groupPrincipals) {
answer.add(principal.getName());
}
return answer;
}
use of org.ow2.proactive.authentication.principals.GroupNamePrincipal in project scheduling by ow2-proactive.
the class UserIdentificationImpl method getGroups.
@Override
public Set<String> getGroups() {
Set<String> answer = new HashSet<>();
Set<GroupNamePrincipal> groupPrincipals = subject.getPrincipals(GroupNamePrincipal.class);
for (GroupNamePrincipal principal : groupPrincipals) {
answer.add(principal.getName());
}
return answer;
}
use of org.ow2.proactive.authentication.principals.GroupNamePrincipal in project scheduling by ow2-proactive.
the class FileLoginModule method groupMembershipFromFile.
/**
* Return corresponding group for an user from the group file.
* @param username user's login
* @throws LoginException if group file is not found or unreadable.
*/
protected void groupMembershipFromFile(String username) throws LoginException {
try (FileInputStream stream = new FileInputStream(groupFile)) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
while ((line = reader.readLine()) != null) {
String[] u2g = line.split(":");
if (u2g[0].trim().equals(username)) {
subject.getPrincipals().add(new GroupNamePrincipal(u2g[1]));
logger.debug("adding group principal '" + u2g[1] + "' for user '" + username + "'");
}
}
} catch (FileNotFoundException e) {
throw new LoginException(e.toString());
} catch (IOException e) {
throw new LoginException(e.toString());
}
}
use of org.ow2.proactive.authentication.principals.GroupNamePrincipal in project scheduling by ow2-proactive.
the class LDAPLoginModule method getLDAPUserDN.
/**
* Connects anonymously to the LDAP server <code>url</code> and retrieve
* DN of the user <code>username</code>
*
* <p>
* @exception NamingException
* if a naming exception is encountered.
* <p>
*
* @return the String containing the UID of the user or null if the user is
* not found.
*/
private String getLDAPUserDN(String username) throws NamingException {
String userDN = null;
DirContext ctx = null;
try {
// Create the initial directory context
ctx = this.connectAndGetContext();
SearchControls sControl = new SearchControls();
sControl.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = String.format(ldapProperties.getProperty(LDAPProperties.LDAP_USER_FILTER), username);
// looking for the user dn (distinguish name)
NamingEnumeration<SearchResult> answer = ctx.search(USERS_DN, filter, sControl);
if (answer.hasMoreElements()) {
SearchResult result = (SearchResult) answer.next();
userDN = result.getNameInNamespace();
if (logger.isDebugEnabled()) {
logger.debug("User " + username + " has LDAP entry " + userDN);
}
subject.getPrincipals().add(new UserNamePrincipal(username));
// looking for the user groups
String groupFilter = String.format(ldapProperties.getProperty(LDAPProperties.LDAP_GROUP_FILTER), userDN);
NamingEnumeration<SearchResult> groupResults = ctx.search(GROUPS_DN, groupFilter, sControl);
while (groupResults.hasMoreElements()) {
SearchResult res = (SearchResult) groupResults.next();
Attribute attr = res.getAttributes().get(ldapProperties.getProperty(LDAPProperties.LDAP_GROUPNAME_ATTR));
if (attr != null) {
String groupName = attr.get().toString();
subject.getPrincipals().add(new GroupNamePrincipal(groupName));
if (logger.isDebugEnabled()) {
logger.debug("User " + username + " is a member of group " + groupName);
}
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("User DN not found");
}
}
} catch (NamingException e) {
logger.error("Problem with the search in mode: " + AUTHENTICATION_METHOD + e);
throw e;
} finally {
try {
if (ctx != null) {
ctx.close();
}
} catch (NamingException e) {
logger.error("", e);
logger.error("Problem closing LDAP connection: " + e.getMessage());
}
}
return userDN;
}
Aggregations