Search in sources :

Example 1 with LDAPCapabilityRepresentation

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

the class LDAPCapabilityTest method testContains.

@Test
public void testContains() {
    LDAPCapabilityRepresentation oid1 = new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, CapabilityType.EXTENSION);
    LDAPCapabilityRepresentation oidx = new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, CapabilityType.EXTENSION);
    LDAPCapabilityRepresentation oid2 = new LDAPCapabilityRepresentation("13.2.3.11.22", CapabilityType.CONTROL);
    LDAPCapabilityRepresentation oid3 = new LDAPCapabilityRepresentation("14.2.3.42.22", CapabilityType.FEATURE);
    Set<LDAPCapabilityRepresentation> ids = new LinkedHashSet<>();
    ids.add(oid1);
    ids.add(oidx);
    ids.add(oid2);
    ids.add(oid3);
    assertTrue(ids.contains(oid1));
    assertTrue(ids.contains(oidx));
    assertEquals(3, ids.size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LDAPCapabilityRepresentation(org.keycloak.representations.idm.LDAPCapabilityRepresentation) Test(org.junit.Test)

Example 2 with LDAPCapabilityRepresentation

use of org.keycloak.representations.idm.LDAPCapabilityRepresentation 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)

Example 3 with LDAPCapabilityRepresentation

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

the class LDAPCapabilityTest method testEquals.

@Test
public void testEquals() {
    LDAPCapabilityRepresentation oid1 = new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, CapabilityType.CONTROL);
    LDAPCapabilityRepresentation oid2 = new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, CapabilityType.EXTENSION);
    LDAPCapabilityRepresentation oid3 = new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, CapabilityType.EXTENSION);
    assertFalse(oid1.equals(oid2));
    assertTrue(oid2.equals(oid3));
    System.out.println(oid1);
}
Also used : LDAPCapabilityRepresentation(org.keycloak.representations.idm.LDAPCapabilityRepresentation) Test(org.junit.Test)

Example 4 with LDAPCapabilityRepresentation

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

the class UserFederationLdapConnectionTest method testLdapCapabilities.

@Test
public void testLdapCapabilities() {
    // Query the rootDSE success
    TestLdapConnectionRepresentation config = new TestLdapConnectionRepresentation(LDAPServerCapabilitiesManager.QUERY_SERVER_CAPABILITIES, "ldap://localhost:10389", "uid=admin,ou=system", "secret", "false", null, "false", LDAPConstants.AUTH_TYPE_SIMPLE);
    List<LDAPCapabilityRepresentation> ldapCapabilities = realm.ldapServerCapabilities(config);
    Assert.assertThat(ldapCapabilities, Matchers.hasItem(new LDAPCapabilityRepresentation(PasswordModifyRequest.PASSWORD_MODIFY_OID, LDAPCapabilityRepresentation.CapabilityType.EXTENSION)));
    // Query the rootDSE failure
    try {
        config = new TestLdapConnectionRepresentation(LDAPServerCapabilitiesManager.QUERY_SERVER_CAPABILITIES, "ldap://localhost:10389", "foo", "bar", "false", null, "false", LDAPConstants.AUTH_TYPE_SIMPLE);
        realm.ldapServerCapabilities(config);
        Assert.fail("It wasn't expected to successfully sent the request for query capabilities");
    } catch (BadRequestException bre) {
    // Expected
    }
}
Also used : LDAPCapabilityRepresentation(org.keycloak.representations.idm.LDAPCapabilityRepresentation) BadRequestException(javax.ws.rs.BadRequestException) TestLdapConnectionRepresentation(org.keycloak.representations.idm.TestLdapConnectionRepresentation) Test(org.junit.Test)

Aggregations

LDAPCapabilityRepresentation (org.keycloak.representations.idm.LDAPCapabilityRepresentation)4 Test (org.junit.Test)3 LinkedHashSet (java.util.LinkedHashSet)2 ArrayList (java.util.ArrayList)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 BadRequestException (javax.ws.rs.BadRequestException)1 ModelException (org.keycloak.models.ModelException)1 CapabilityType (org.keycloak.representations.idm.LDAPCapabilityRepresentation.CapabilityType)1 TestLdapConnectionRepresentation (org.keycloak.representations.idm.TestLdapConnectionRepresentation)1 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)1