Search in sources :

Example 1 with CapabilityType

use of org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType in project keycloak by keycloak.

the class LDAPCapabilityTest method testCapabilityTypeFromAttributeName.

@Test
public void testCapabilityTypeFromAttributeName() {
    CapabilityType extension = CapabilityType.fromRootDseAttributeName("supportedExtension");
    assertEquals(CapabilityType.EXTENSION, extension);
    CapabilityType control = CapabilityType.fromRootDseAttributeName("supportedControl");
    assertEquals(CapabilityType.CONTROL, control);
    CapabilityType feature = CapabilityType.fromRootDseAttributeName("supportedFeatures");
    assertEquals(CapabilityType.FEATURE, feature);
    CapabilityType unknown = CapabilityType.fromRootDseAttributeName("foo");
    assertEquals(CapabilityType.UNKNOWN, unknown);
}
Also used : CapabilityType(org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType) Test(org.junit.Test)

Example 2 with CapabilityType

use of org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType in project keycloak by keycloak.

the class LDAPIdentityStore method queryServerCapabilities.

@Override
public Set<LDAPCapabilityRepresentation> queryServerCapabilities() {
    Set<LDAPCapabilityRepresentation> result = new LinkedHashSet<>();
    try {
        List<String> attrs = new ArrayList<>();
        attrs.add("supportedControl");
        attrs.add("supportedExtension");
        attrs.add("supportedFeatures");
        List<SearchResult> searchResults = operationManager.search("", "(objectClass=*)", Collections.unmodifiableCollection(attrs), SearchControls.OBJECT_SCOPE);
        if (searchResults.size() != 1) {
            throw new ModelException("Could not query root DSE: unexpected result size");
        }
        SearchResult rootDse = searchResults.get(0);
        Attributes attributes = rootDse.getAttributes();
        for (String attr : attrs) {
            Attribute attribute = attributes.get(attr);
            if (null != attribute) {
                CapabilityType capabilityType = CapabilityType.fromRootDseAttributeName(attr);
                NamingEnumeration<?> values = attribute.getAll();
                while (values.hasMoreElements()) {
                    Object o = values.nextElement();
                    LDAPCapabilityRepresentation capability = new LDAPCapabilityRepresentation(o, capabilityType);
                    logger.info("rootDSE query: " + capability);
                    result.add(capability);
                }
            }
        }
        return result;
    } catch (NamingException e) {
        throw new ModelException("Failed to query root DSE: " + e.getMessage(), e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CapabilityType(org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType) ModelException(org.keycloak.models.ModelException) LDAPCapabilityRepresentation(org.keycloak.representations.idm.LDAPCapabilityRepresentation) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) LDAPObject(org.keycloak.storage.ldap.idm.model.LDAPObject) NamingException(javax.naming.NamingException)

Aggregations

CapabilityType (org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 NamingException (javax.naming.NamingException)1 Attribute (javax.naming.directory.Attribute)1 Attributes (javax.naming.directory.Attributes)1 BasicAttribute (javax.naming.directory.BasicAttribute)1 BasicAttributes (javax.naming.directory.BasicAttributes)1 SearchResult (javax.naming.directory.SearchResult)1 Test (org.junit.Test)1 ModelException (org.keycloak.models.ModelException)1 LDAPCapabilityRepresentation (org.keycloak.representations.idm.LDAPCapabilityRepresentation)1 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)1