Search in sources :

Example 21 with DirContextOperations

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

the class AbstractPerunEntry method entryAttributeExists.

@Override
public Boolean entryAttributeExists(T bean, String ldapAttributeName) {
    DirContextOperations entry = findByDN(buildDN(bean));
    String value = entry.getStringAttribute(ldapAttributeName);
    return (value != null);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 22 with DirContextOperations

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

the class AbstractPerunEntry method modifyEntry.

@Override
public void modifyEntry(T bean, AttributeDefinition attr) {
    DirContextOperations entry = findByDN(buildDN(bean));
    List<PerunAttribute<T>> attrDefs = findAttributeDescriptionsByPerunAttr(getAttributeDescriptions(), attr);
    if (attrDefs.isEmpty()) {
        // this is not exceptional situation
        // throw new InternalErrorException("Attribute description for attribute " + attr.getName() + " not found");
        log.info("Attribute description for attribute {} not found, not modifying entry.", attr.getName());
        return;
    }
    for (PerunAttribute<T> attrDef : attrDefs) {
        mapToContext(bean, entry, attrDef, attr);
    }
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

Example 23 with DirContextOperations

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

the class AbstractPerunEntry method removeAllAttributes.

@Override
public void removeAllAttributes(T bean) {
    DirContextOperations entry = findByDN(buildDN(bean));
    /* we have to find all existing entry attributes to resolve all the present options in names */
    NamingEnumeration<String> attrNames = entry.getAttributes().getIDs();
    while (attrNames.hasMoreElements()) {
        String attrName = attrNames.nextElement();
        Iterable<PerunAttribute<T>> attrDefs = findAttributeDescriptionsByLdapName(getAttributeDescriptions(), Arrays.asList(attrName));
        for (PerunAttribute<T> attrDef : attrDefs) {
            if (attrDef.requiresAttributeBean() && !attrDef.isRequired()) {
                entry.setAttributeValues(attrName, null);
            }
        }
    }
    if (entry.getModificationItems().length > 0) {
        ldapTemplate.modifyAttributes(entry);
    }
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

Example 24 with DirContextOperations

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

the class AbstractPerunEntry method modifyEntry.

@Override
public void modifyEntry(T bean, PerunAttribute<T> attrDef, AttributeDefinition attr) {
    DirContextOperations entry = findByDN(buildDN(bean));
    mapToContext(bean, entry, attrDef, attr);
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations)

Example 25 with DirContextOperations

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

the class AbstractPerunEntry method modifyEntry.

@Override
public void modifyEntry(T bean, Iterable<Pair<PerunAttribute<T>, AttributeDefinition>> attrs) {
    DirContextOperations entry = findByDN(buildDN(bean));
    for (Pair<PerunAttribute<T>, AttributeDefinition> pair : attrs) {
        mapToContext(bean, entry, pair.getLeft(), pair.getRight());
    }
    ldapTemplate.modifyAttributes(entry);
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) PerunAttribute(cz.metacentrum.perun.ldapc.model.PerunAttribute)

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