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