use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.
the class PerunVOImpl method getVoShortName.
public String getVoShortName(int voId) {
DirContextOperations voEntry = findById(String.valueOf(voId));
String[] voShortNameInformation = voEntry.getStringAttributes(PerunAttribute.PerunAttributeNames.ldapAttrOrganization);
String voShortName = null;
if (voShortNameInformation == null || voShortNameInformation[0] == null)
throw new InternalErrorException("There is no shortName in ldap for vo with id=" + voId);
if (voShortNameInformation.length != 1)
throw new InternalErrorException("There is not exactly one short name of vo with id=" + voId + " in ldap. Count of shortnames is " + voShortNameInformation.length);
voShortName = voShortNameInformation[0];
return voShortName;
}
use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.
the class PerunVOImpl method synchronizeMembers.
@Override
public void synchronizeMembers(Vo vo, List<Member> members) {
DirContextOperations voEntry = findByDN(buildDN(vo));
doSynchronizeMembers(voEntry, members);
ldapTemplate.modifyAttributes(voEntry);
// user attributes are set when synchronizing users
}
use of org.springframework.ldap.core.DirContextOperations in project pentaho-platform by pentaho.
the class RolePreprocessingMapperTests method testMapUserFromContext.
@SuppressWarnings("unchecked")
@Test
public void testMapUserFromContext() throws Exception {
RolePreprocessingMapper mapper = new RolePreprocessingMapper();
// $NON-NLS-1$
mapper.setTokenName("cn");
// $NON-NLS-1$
mapper.setRolePrefix("");
// $NON-NLS-1$
mapper.setRoleAttributes(new String[] { "uniqueMember" });
// get the user record
DirContextOperations ctx = // $NON-NLS-1$
new SpringSecurityLdapTemplate(getContextSource()).retrieveEntry(// $NON-NLS-1$
"uid=suzy,ou=users", null);
// get any roles that aren't in the user record
Set<String> extraRoles = new SpringSecurityLdapTemplate(getContextSource()).searchForSingleAttributeValues("ou=roles", "roleoccupant={0}", new String[] { "uid=suzy,ou=users,dc=pentaho,dc=org", "suzy" }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"cn");
List<GrantedAuthority> authorities = new ArrayList<>();
for (String extraRole : extraRoles) {
authorities.add(new SimpleGrantedAuthority(extraRole));
}
// use the mapper to create a UserDetails instance
// $NON-NLS-1$
UserDetails userDetails = mapper.mapUserFromContext(ctx, "suzy", authorities);
System.out.println(userDetails);
// this asserts the ordering too; not strictly necessary
Collection<? extends GrantedAuthority> expectedAuthorities = new ArrayList<GrantedAuthority>() {
{
add(new SimpleGrantedAuthority("A"));
add(new SimpleGrantedAuthority("Authenticated"));
add(new SimpleGrantedAuthority("is"));
add(new SimpleGrantedAuthority("cto"));
}
};
Collection<? extends GrantedAuthority> unexpectedAuthorities = userDetails.getAuthorities();
assertEquals(expectedAuthorities, unexpectedAuthorities);
}
use of org.springframework.ldap.core.DirContextOperations in project pentaho-platform by pentaho.
the class PentahoCachingLdapAuthenticator method performOperation.
private DirContextOperations performOperation(Authentication authentication, DelegateOperation operation) {
DirContextOperations results = null;
Object fromRegionCache = null;
String cacheEntry = ROLES_BY_USER + hashUserAndPassword(authentication);
if (logger.isTraceEnabled()) {
logger.trace("cacheEntry:" + cacheEntry);
}
fromRegionCache = cacheManager.getFromRegionCache(cacheRegionName, cacheEntry);
if (fromRegionCache instanceof DirContextOperations) {
if (logger.isDebugEnabled()) {
logger.debug("Cache Hit for " + authentication.getPrincipal());
}
results = (DirContextOperations) fromRegionCache;
} else {
if (logger.isDebugEnabled()) {
logger.debug("Cache miss for " + authentication.getPrincipal());
}
results = operation.perform();
cacheManager.putInRegionCache(cacheRegionName, cacheEntry, results);
}
return results;
}
Aggregations