Search in sources :

Example 11 with DefaultAttributeDefinitionStore

use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.

the class DefaultAttributeDefinitionStoreTests method verifyBadDefinitionsResource.

@Test
public void verifyBadDefinitionsResource() throws Exception {
    val file = File.createTempFile("badfile", ".json");
    FileUtils.write(file, "data", StandardCharsets.UTF_8);
    val store = new DefaultAttributeDefinitionStore(new FileSystemResource(file));
    store.setScope("example.org");
    assertTrue(store.isEmpty());
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with DefaultAttributeDefinitionStore

use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.

the class DefaultAttributeDefinitionStoreTests method verifyFormattedAttrDefn.

@Test
public void verifyFormattedAttrDefn() {
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").attribute("givenName").scoped(true).patternFormat("hello,{0}").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("hello,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 13 with DefaultAttributeDefinitionStore

use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.

the class DefaultAttributeDefinitionStoreTests method verifyPredicateAttributeDefinitions.

@Test
public void verifyPredicateAttributeDefinitions() {
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("cn").scoped(true).build();
    store.registerAttributeDefinition(defn);
    assertTrue(store.locateAttributeDefinition(attributeDefinition -> attributeDefinition.equals(defn)).isPresent());
}
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 14 with DefaultAttributeDefinitionStore

use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.

the class DefaultAttributeDefinitionStoreTests method verifyScriptedEmbeddedAttrDefn.

@Test
public void verifyScriptedEmbeddedAttrDefn() {
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").attribute("uid").scoped(true).script("groovy { logger.info(\" name: ${attributeName}, values: ${attributeValues} \"); return ['hello', 'world'] } ").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("hello@example.org"));
    assertTrue(values.get().getValue().contains("world@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 15 with DefaultAttributeDefinitionStore

use of org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore in project cas by apereo.

the class DefaultAttributeDefinitionStoreTests method verifyExternalImport.

@Test
public void verifyExternalImport() throws Exception {
    val store = new DefaultAttributeDefinitionStore(new ClassPathResource("AttributeDefns.json"));
    assertFalse(store.getAttributeDefinitions().isEmpty());
    assertNotNull(store.locateAttributeDefinition("eduPersonPrincipalName"));
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) ClassPathResource(org.springframework.core.io.ClassPathResource) 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