Search in sources :

Example 1 with DefaultAttributeDefinitionStore

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"));
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) List(java.util.List) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DefaultAttributeDefinitionStore

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"));
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DefaultAttributeDefinitionStore

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"));
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with DefaultAttributeDefinitionStore

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"));
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with DefaultAttributeDefinitionStore

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());
}
Also used : lombok.val(lombok.val) RegisteredServicePublicKey(org.apereo.cas.services.RegisteredServicePublicKey) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)16 DefaultAttributeDefinitionStore (org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore)16 Test (org.junit.jupiter.api.Test)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 List (java.util.List)3 FileSystemResource (org.springframework.core.io.FileSystemResource)3 Optional (java.util.Optional)2 AttributeDefinition (org.apereo.cas.authentication.attribute.AttributeDefinition)2 DefaultAttributeDefinition (org.apereo.cas.authentication.attribute.DefaultAttributeDefinition)2 RegisteredServicePublicKey (org.apereo.cas.services.RegisteredServicePublicKey)2 Executable (org.junit.jupiter.api.function.Executable)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 FileTime (java.nio.file.attribute.FileTime)1 Instant (java.time.Instant)1 Map (java.util.Map)1 FileUtils (org.apache.commons.io.FileUtils)1