Search in sources :

Example 76 with DirContextOperations

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

the class PerunGroupImpl method removeFromFacilityAdmins.

@Override
public void removeFromFacilityAdmins(Group group, Facility facility) {
    DirContextOperations entry = findByDN(buildDN(group));
    Name facilityDN = addBaseDN(perunFacility.getEntryDN(String.valueOf(facility.getId())));
    entry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAdminOfFacility, facilityDN.toString());
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Example 77 with DirContextOperations

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

the class PerunGroupImpl method addAsVoAdmin.

@Override
public void addAsVoAdmin(Group group, Vo vo) {
    DirContextOperations entry = findByDN(buildDN(group));
    Name voDN = addBaseDN(perunVO.getEntryDN(String.valueOf(vo.getId())));
    entry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAdminOfVo, voDN.toString());
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Example 78 with DirContextOperations

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

the class PerunGroupImpl method removeGroup.

public void removeGroup(Group group) {
    Name groupDN = buildDN(group);
    Name fullGroupDN = this.addBaseDN(groupDN);
    DirContextOperations groupEntry = findByDN(groupDN);
    String[] uniqueMembers = groupEntry.getStringAttributes(PerunAttribute.PerunAttributeNames.ldapAttrUniqueMember);
    if (uniqueMembers != null)
        for (String memberDN : uniqueMembers) {
            DirContextOperations memberEntry = user.findByDN(LdapNameBuilder.newInstance(memberDN).build());
            memberEntry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrMemberOf, fullGroupDN.toString());
            ldapTemplate.modifyAttributes(memberEntry);
        }
    deleteEntry(group);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Example 79 with DirContextOperations

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

the class PerunGroupImpl method addMemberToGroup.

public void addMemberToGroup(Member member, Group group) {
    // Add member to 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.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrUniqueMember, fullMemberDN.toString());
    ldapTemplate.modifyAttributes(groupEntry);
    // Add member to vo if this group is membersGroup
    if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
        // Add info to vo
        vo.addMemberToVO(group.getVoId(), member);
    }
    // Add group info to member
    // user->add('memberOf' => groupDN)
    DirContextOperations userEntry = findByDN(memberDN);
    userEntry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrMemberOf, addBaseDN(groupDN).toString());
    ldapTemplate.modifyAttributes(userEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) Name(javax.naming.Name)

Example 80 with DirContextOperations

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

the class PerunGroupImpl method synchronizeAdminRoles.

@Override
public void synchronizeAdminRoles(Group group, List<Group> admin_groups, List<Vo> admin_vos, List<Facility> admin_facilities) {
    DirContextOperations groupEntry = findByDN(buildDN(group));
    doSynchronizeAdminRoles(groupEntry, admin_groups, admin_vos, admin_facilities);
    ldapTemplate.modifyAttributes(groupEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

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