use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.
the class PerunUserImpl method addAsFacilityAdmin.
@Override
public void addAsFacilityAdmin(User user, Facility facility) {
DirContextOperations entry = findByDN(buildDN(user));
Name facilityDN = addBaseDN(perunFacility.getEntryDN(String.valueOf(facility.getId())));
entry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAdminOfFacility, facilityDN.toString());
ldapTemplate.modifyAttributes(entry);
}
use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.
the class PerunUserImpl method addAsVoAdmin.
@Override
public void addAsVoAdmin(User user, Vo vo) {
DirContextOperations entry = findByDN(buildDN(user));
Name voDN = addBaseDN(perunVO.getEntryDN(String.valueOf(vo.getId())));
entry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAdminOfVo, voDN.toString());
ldapTemplate.modifyAttributes(entry);
}
use of org.springframework.ldap.core.DirContextOperations in project hub-alert by blackducksoftware.
the class MappingLdapAuthoritiesPopulatorTest method testEmptyAdditionalRoles.
@Test
public void testEmptyAdditionalRoles() {
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
Mockito.doReturn(Set.of(new SimpleGrantedAuthority(DefaultUserRole.ALERT_USER.name()))).when(authoritiesPopulator).addAdditionalRoles(Mockito.anyString(), Mockito.anySet());
ContextSource contextSource = Mockito.mock(ContextSource.class);
DirContextOperations user = Mockito.mock(DirContextOperations.class);
MappingLdapAuthoritiesPopulator ldapAuthoritiesPopulator = new MappingLdapAuthoritiesPopulator(contextSource, null, authoritiesPopulator);
Set<GrantedAuthority> actualRoles = ldapAuthoritiesPopulator.getAdditionalRoles(user, "");
boolean hasAlertUserRole = actualRoles.stream().map(GrantedAuthority::getAuthority).allMatch(roleName -> DefaultUserRole.ALERT_USER.name().equals(roleName));
Mockito.verify(authoritiesPopulator).addAdditionalRoles(Mockito.anyString(), Mockito.anySet());
assertFalse(actualRoles.isEmpty());
assertTrue(hasAlertUserRole);
}
use of org.springframework.ldap.core.DirContextOperations in project kylo by Teradata.
the class ActiveDirectoryAuthenticationProvider method authenticate.
/* (non-Javadoc)
* @see org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider#authenticate(org.springframework.security.core.Authentication)
*/
@Override
public Authentication authenticate(Authentication authentication) throws org.springframework.security.core.AuthenticationException {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, this.messages.getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported"));
final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;
final UsernamePasswordAuthenticationToken authToken = this.serviceToken != null ? this.serviceToken : userToken;
if (this.logger.isDebugEnabled()) {
this.logger.debug("Processing authentication request for user: " + userToken.getName());
}
if (!StringUtils.hasLength(userToken.getName())) {
throw new BadCredentialsException(this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
}
String credentials = String.valueOf((char[]) authToken.getCredentials());
if (!StringUtils.hasLength(credentials)) {
throw new BadCredentialsException(this.messages.getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password"));
}
DirContextOperations userData = doAuthentication(userToken);
Collection<? extends GrantedAuthority> authorities = loadUserAuthorities(userData, authToken.getName(), credentials);
UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, userToken.getName(), authorities);
return createSuccessfulAuthentication(userToken, user);
}
use of org.springframework.ldap.core.DirContextOperations in project cxf by apache.
the class LdapUtils method getDnOfEntry.
public static Name getDnOfEntry(LdapTemplate ldapTemplate, String baseDN, String objectClass, String filterAttributeName, String filterAttributeValue) {
ContextMapper<Name> mapper = new AbstractContextMapper<Name>() {
public Name doMapFromContext(DirContextOperations ctx) {
return ctx.getDn();
}
};
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", objectClass)).and(new EqualsFilter(filterAttributeName, filterAttributeValue));
List<Name> result = ldapTemplate.search((baseDN == null) ? "" : baseDN, filter.toString(), SearchControls.SUBTREE_SCOPE, mapper);
if (result != null && !result.isEmpty()) {
// not only the first one....
return result.get(0);
}
return null;
}
Aggregations