use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.
the class DefaultAttributeDefinitionStoreTests method verifyAttributeDefinitionsAsMap.
@Test
public void verifyAttributeDefinitionsAsMap() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder().key("cn").scoped(true).name("urn:oid:1.3.6.1.4.1.5923.1.1.1.6").build();
store.registerAttributeDefinition(defn);
assertFalse(store.isEmpty());
val attributes = CoreAuthenticationTestUtils.getAttributes();
val attrs = store.resolveAttributeValues(attributes.keySet(), attributes, service);
assertFalse(attrs.isEmpty());
assertTrue(attrs.containsKey("mail"));
assertTrue(attrs.containsKey(defn.getName()));
val values = (List<Object>) attrs.get(defn.getName());
assertTrue(values.contains("TEST@example.org"));
}
use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.
the class DefaultAttributeDefinitionStoreTests method verifyScriptedExternalAttrDefn.
@Test
public void verifyScriptedExternalAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("system.org");
val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").attribute("uid").scoped(true).script("classpath:/attribute-definition.groovy").build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName", CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service, Map.of());
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("casuser@system.org"));
assertTrue(values.get().getValue().contains("groovy@system.org"));
}
use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.
the class DefaultAttributeDefinitionStoreTests method verifyMappedToMultipleNames.
@Test
public void verifyMappedToMultipleNames() {
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder().key("cn").name("commonName,common-name,cname").build();
store.registerAttributeDefinition(defn);
val attributes = CoreAuthenticationTestUtils.getAttributes();
val attrs = store.resolveAttributeValues(attributes.keySet(), attributes, CoreAuthenticationTestUtils.getRegisteredService());
assertFalse(attrs.isEmpty());
assertFalse(attrs.containsKey("cn"));
assertTrue(attrs.containsKey("commonName"));
assertTrue(attrs.containsKey("common-name"));
assertTrue(attrs.containsKey("cname"));
}
use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.
the class DefaultAttributeDefinitionStoreTests method verifyScopedAttrDefn.
@Test
public void verifyScopedAttrDefn() {
val service = CoreAuthenticationTestUtils.getRegisteredService();
val store = new DefaultAttributeDefinitionStore();
store.setScope("example.org");
val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").attribute("uid").scoped(true).build();
store.registerAttributeDefinition(defn);
var values = store.resolveAttributeValues("eduPersonPrincipalName", CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service, Map.of());
assertTrue(values.isPresent());
assertTrue(values.get().getValue().contains("test@example.org"));
}
use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.
the class DefaultAttributeDefinitionStoreTests method verifyDefinitions.
@Test
public void verifyDefinitions() {
val defn1 = DefaultAttributeDefinition.builder().key("cn").encrypted(true).build();
val defn2 = DefaultAttributeDefinition.builder().key("cn").build();
assertEquals(0, defn1.compareTo(defn2));
val store = new DefaultAttributeDefinitionStore(defn1);
store.setScope("example.org");
val service = CoreAuthenticationTestUtils.getRegisteredService();
var results = store.resolveAttributeValues("cn", List.of("common-name"), service, Map.of());
assertFalse(results.isEmpty());
assertTrue(results.get().getValue().isEmpty());
when(service.getPublicKey()).thenReturn(mock(RegisteredServicePublicKey.class));
results = store.resolveAttributeValues("cn", List.of("common-name"), service, Map.of());
assertTrue(results.get().getValue().isEmpty());
}
Aggregations