Search in sources :

Example 36 with DirContextOperations

use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.

the class PerunGroupImpl method synchronizeMembers.

@Override
public void synchronizeMembers(Group group, List<Member> members) {
    DirContextOperations groupEntry = findByDN(buildDN(group));
    doSynchronizeMembers(groupEntry, members);
    ldapTemplate.modifyAttributes(groupEntry);
// user attributes are set when synchronizing users
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 37 with DirContextOperations

use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.

the class PerunGroupImpl method getAllUniqueMembersInGroup.

@Deprecated
public List<String> getAllUniqueMembersInGroup(int groupId, int voId) {
    Pattern userIdPattern = Pattern.compile("[0-9]+");
    List<String> uniqueMembers = new ArrayList<String>();
    DirContextOperations groupEntry = findById(String.valueOf(groupId), String.valueOf(voId));
    String[] uniqueGroupInformation = groupEntry.getStringAttributes(PerunAttribute.PerunAttributeNames.ldapAttrUniqueMember);
    if (uniqueGroupInformation != null) {
        for (String s : uniqueGroupInformation) {
            Matcher userIdMatcher = userIdPattern.matcher(s);
            if (userIdMatcher.find())
                uniqueMembers.add(s.substring(userIdMatcher.start(), userIdMatcher.end()));
        }
    }
    return uniqueMembers;
}
Also used : Pattern(java.util.regex.Pattern) DirContextOperations(org.springframework.ldap.core.DirContextOperations) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 38 with DirContextOperations

use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.

the class PerunGroupImpl method synchronizeResources.

@Override
public void synchronizeResources(Group group, List<Resource> resources) {
    DirContextOperations groupEntry = findByDN(buildDN(group));
    doSynchronizeResources(groupEntry, resources);
    ldapTemplate.modifyAttributes(groupEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 39 with DirContextOperations

use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.

the class PerunGroupImpl method removeMemberFromGroup.

public void removeMemberFromGroup(Member member, Group group) {
    // Remove member from group
    Name groupDN = buildDN(group);
    DirContextOperations groupEntry = findByDN(groupDN);
    Name memberDN = user.getEntryDN(String.valueOf(member.getUserId()));
    Name fullMemberDN = addBaseDN(memberDN);
    if (!isMember(groupEntry, fullMemberDN))
        return;
    groupEntry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrUniqueMember, fullMemberDN.toString());
    ldapTemplate.modifyAttributes(groupEntry);
    // Remove member from vo if this group is membersGroup
    if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
        // Remove info from vo
        vo.removeMemberFromVO(group.getVoId(), member);
    }
    // Remove group info from member
    DirContextOperations userEntry = findByDN(memberDN);
    userEntry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrMemberOf, addBaseDN(groupDN).toString());
    ldapTemplate.modifyAttributes(userEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Example 40 with DirContextOperations

use of org.springframework.ldap.core.DirContextOperations in project perun by CESNET.

the class PerunGroupImpl method removeFromGroupAdmins.

@Override
public void removeFromGroupAdmins(Group group, Group group2) {
    DirContextOperations entry = findByDN(buildDN(group));
    Name groupDN = addBaseDN(getEntryDN(String.valueOf(group2.getVoId()), String.valueOf(group2.getId())));
    entry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAdminOfGroup, groupDN.toString());
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Aggregations

DirContextOperations (org.springframework.ldap.core.DirContextOperations)89 Name (javax.naming.Name)20 Test (org.junit.jupiter.api.Test)13 Test (org.junit.Test)9 UserDetails (org.springframework.security.core.userdetails.UserDetails)9 HashSet (java.util.HashSet)8 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)8 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)8 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 FilterBasedLdapUserSearch (org.springframework.security.ldap.search.FilterBasedLdapUserSearch)7 LdapConfig (com.thoughtworks.go.config.LdapConfig)6 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)6 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 NameNotFoundException (org.springframework.ldap.NameNotFoundException)6 GrantedAuthority (org.springframework.security.core.GrantedAuthority)5 PerunAttribute (cz.metacentrum.perun.ldapc.model.PerunAttribute)4 List (java.util.List)4