Search in sources :

Example 6 with DefaultAttributeDefinitionStore

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

the class DefaultAttributeDefinitionStoreTests method verifyOperation.

@Test
public void verifyOperation() {
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").name("urn:oid:1.3.6.1.4.1.5923.1.1.1.6").build();
    store.registerAttributeDefinition(defn);
    assertNotNull(store.locateAttributeDefinition("eduPersonPrincipalName"));
    assertFalse(store.getAttributeDefinitions().isEmpty());
}
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 7 with DefaultAttributeDefinitionStore

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

the class DefaultAttributeDefinitionStoreTests method verifyDefinitionsReload.

@Test
public void verifyDefinitionsReload() {
    val resource = casProperties.getAuthn().getAttributeRepository().getAttributeDefinitionStore().getJson().getLocation();
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            val store = new DefaultAttributeDefinitionStore(resource);
            store.setScope("example.org");
            Files.setLastModifiedTime(resource.getFile().toPath(), FileTime.from(Instant.now()));
            Thread.sleep(5_000);
            store.destroy();
        }
    });
}
Also used : lombok.val(lombok.val) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with DefaultAttributeDefinitionStore

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

the class DefaultAttributeDefinitionStoreTests method verifyEncryptedAttributeDefinitions.

@Test
public void verifyEncryptedAttributeDefinitions() {
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val servicePublicKey = new RegisteredServicePublicKeyImpl("classpath:keys/RSA1024Public.key", "RSA");
    when(service.getPublicKey()).thenReturn(servicePublicKey);
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("cn").scoped(true).encrypted(true).build();
    store.registerAttributeDefinition(defn);
    assertTrue(store.locateAttributeDefinition("cn", DefaultAttributeDefinition.class).isPresent());
    assertFalse(store.locateAttributeDefinition("unknown", DefaultAttributeDefinition.class).isPresent());
    val attributes = CoreAuthenticationTestUtils.getAttributes();
    val attrs = store.resolveAttributeValues(attributes.keySet(), attributes, service);
    assertFalse(attrs.isEmpty());
    assertTrue(attrs.containsKey("cn"));
    val values = CollectionUtils.toCollection(attrs.get("cn"));
    assertFalse(values.stream().anyMatch(value -> value.toString().equalsIgnoreCase(CoreAuthenticationTestUtils.CONST_USERNAME)));
}
Also used : lombok.val(lombok.val) RegisteredServicePublicKeyImpl(org.apereo.cas.services.RegisteredServicePublicKeyImpl) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) RegisteredServicePublicKey(org.apereo.cas.services.RegisteredServicePublicKey) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) ReturnAllAttributeReleasePolicy(org.apereo.cas.services.ReturnAllAttributeReleasePolicy) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) FileTime(java.nio.file.attribute.FileTime) DefaultAttributeDefinition(org.apereo.cas.authentication.attribute.DefaultAttributeDefinition) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) Pair(org.apache.commons.lang3.tuple.Pair) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) RegisteredServicePublicKeyImpl(org.apereo.cas.services.RegisteredServicePublicKeyImpl) CollectionUtils(org.apereo.cas.util.CollectionUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Tag(org.junit.jupiter.api.Tag) Files(java.nio.file.Files) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) FileSystemResource(org.springframework.core.io.FileSystemResource) FileUtils(org.apache.commons.io.FileUtils) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Instant(java.time.Instant) IPersonAttributeDaoFilter(org.apereo.services.persondir.IPersonAttributeDaoFilter) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) AttributeDefinition(org.apereo.cas.authentication.attribute.AttributeDefinition) Mockito(org.mockito.Mockito) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Executable(org.junit.jupiter.api.function.Executable) JacksonObjectMapperFactory(org.apereo.cas.util.serialization.JacksonObjectMapperFactory) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) DefaultAttributeDefinitionStore(org.apereo.cas.authentication.attribute.DefaultAttributeDefinitionStore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with DefaultAttributeDefinitionStore

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

the class DefaultAttributeDefinitionStoreTests method verifyAttrDefnNotFound.

@Test
public void verifyAttrDefnNotFound() {
    val service = CoreAuthenticationTestUtils.getRegisteredService();
    val store = new DefaultAttributeDefinitionStore();
    store.setScope("example.org");
    val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").attribute("invalid").scoped(true).build();
    store.registerAttributeDefinition(defn);
    var values = (Optional<Pair<AttributeDefinition, List<Object>>>) store.resolveAttributeValues("whatever", CollectionUtils.wrap(CoreAuthenticationTestUtils.CONST_USERNAME), service, Map.of());
    assertTrue(values.isEmpty());
}
Also used : lombok.val(lombok.val) Optional(java.util.Optional) DefaultAttributeDefinition(org.apereo.cas.authentication.attribute.DefaultAttributeDefinition) AttributeDefinition(org.apereo.cas.authentication.attribute.AttributeDefinition) 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 10 with DefaultAttributeDefinitionStore

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

the class DefaultAttributeDefinitionStoreTests method verifyStoreSerialization.

@Test
public void verifyStoreSerialization() throws Exception {
    val defn = DefaultAttributeDefinition.builder().key("eduPersonPrincipalName").name("urn:oid:1.3.6.1.4.1.5923.1.1.1.6").build();
    val store = new DefaultAttributeDefinitionStore(defn);
    store.setScope("example.org");
    val file = File.createTempFile("attr", "json");
    store.to(file);
    assertTrue(file.exists());
    val store2 = new DefaultAttributeDefinitionStore(new FileSystemResource(file));
    assertEquals(store2, store);
}
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)

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