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());
}
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);
}
}
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);
}
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
}
}
Aggregations