Search in sources :

Example 81 with DirContextOperations

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

the class PerunUserImpl method addAsGroupAdmin.

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

Example 82 with DirContextOperations

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

the class AbstractPerunEntry method addEntry.

/* (non-Javadoc)
	 * @see cz.metacentrum.perun.ldapc.model.impl.PerunEntry#addEntry(cz.metacentrum.perun.core.api.PerunBean)
	 */
@Override
public void addEntry(T bean) {
    DirContextOperations context = new DirContextAdapter(buildDN(bean));
    mapToContext(bean, context);
    ldapTemplate.bind(context);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter)

Example 83 with DirContextOperations

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

the class AbstractPerunEntry method beginSynchronizeEntry.

@Override
public SyncOperation beginSynchronizeEntry(T bean) {
    DirContextOperations entry;
    boolean newEntry = false;
    try {
        entry = findByDN(buildDN(bean));
    } catch (NameNotFoundException e) {
        newEntry = true;
        entry = new DirContextAdapter(buildDN(bean));
    }
    if (newEntry) {
        log.debug("Creating new entry {} ", entry.toString());
        // map with objectclasses
        mapToContext(bean, entry);
    // ldapTemplate.bind(entry);
    } else {
        log.debug("Modifying entry {} ", entry.toString());
        // map without objectclasses (entry exists)
        mapToContext(bean, entry, getAttributeDescriptions());
    // ldapTemplate.modifyAttributes(entry);
    }
    return new SyncOperationImpl(entry, newEntry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) NameNotFoundException(org.springframework.ldap.NameNotFoundException) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter)

Example 84 with DirContextOperations

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

the class PerunResourceImpl method assignGroup.

@Override
public void assignGroup(Resource resource, Group group) {
    DirContextOperations entry = findByDN(buildDN(resource));
    entry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAssignedGroupId, String.valueOf(group.getId()));
    ldapTemplate.modifyAttributes(entry);
    entry = perunGroup.findById(String.valueOf(group.getVoId()), String.valueOf(group.getId()));
    entry.addAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAssignedToResourceId, String.valueOf(resource.getId()));
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 85 with DirContextOperations

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

the class PerunResourceImpl method removeGroup.

@Override
public void removeGroup(Resource resource, Group group) {
    DirContextOperations entry = findByDN(buildDN(resource));
    entry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAssignedGroupId, String.valueOf(group.getId()));
    ldapTemplate.modifyAttributes(entry);
    entry = perunGroup.findById(String.valueOf(group.getVoId()), String.valueOf(group.getId()));
    entry.removeAttributeValue(PerunAttribute.PerunAttributeNames.ldapAttrAssignedToResourceId, String.valueOf(resource.getId()));
    ldapTemplate.modifyAttributes(entry);
}
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