Search in sources :

Example 1 with RememberMeAuthenticationMetaDataPopulator

use of org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator in project cas by apereo.

the class DefaultAuthenticationEventExecutionPlanTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = PrincipalResolutionContext.builder().attributeRepository(CoreAuthenticationTestUtils.getAttributeRepository()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(formUserId -> formUserId).useCurrentPrincipalId(false).resolveAttributes(true).attributeMerger(CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.REPLACE)).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).build();
    val plan = new DefaultAuthenticationEventExecutionPlan();
    plan.registerAuthenticationPreProcessor(transaction -> false);
    plan.registerAuthenticationMetadataPopulators(Set.of(new RememberMeAuthenticationMetaDataPopulator(new RememberMeAuthenticationProperties())));
    plan.registerAuthenticationHandlerWithPrincipalResolvers(Set.of(new SimpleTestUsernamePasswordAuthenticationHandler()), new PersonDirectoryPrincipalResolver(context));
    plan.registerAuthenticationPolicy(new AllCredentialsValidatedAuthenticationPolicy());
    plan.registerAuthenticationPolicyResolver(transaction -> Set.of(new AllCredentialsValidatedAuthenticationPolicy()));
    assertFalse(plan.getAuthenticationPolicies(new DefaultAuthenticationTransactionFactory().newTransaction(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword())).isEmpty());
}
Also used : lombok.val(lombok.val) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) PrincipalFactoryUtils(org.apereo.cas.authentication.principal.PrincipalFactoryUtils) lombok.val(lombok.val) Set(java.util.Set) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AllCredentialsValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy) List(java.util.List) CollectionUtils(org.apereo.cas.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) PrincipalAttributesCoreProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesCoreProperties) PrincipalResolutionContext(org.apereo.cas.authentication.principal.resolvers.PrincipalResolutionContext) Tag(org.junit.jupiter.api.Tag) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AllCredentialsValidatedAuthenticationPolicy(org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 2 with RememberMeAuthenticationMetaDataPopulator

use of org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private static AuthenticationBuilder newBuilder(final Credential credential, final RememberMeAuthenticationProperties properties) {
    val populator = new RememberMeAuthenticationMetaDataPopulator(properties);
    val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
    if (populator.supports(credential)) {
        populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credential));
    }
    return builder;
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) RememberMeAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Aggregations

lombok.val (lombok.val)2 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)2 RememberMeAuthenticationMetaDataPopulator (org.apereo.cas.authentication.metadata.RememberMeAuthenticationMetaDataPopulator)2 List (java.util.List)1 Set (java.util.Set)1 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)1 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)1 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)1 RememberMeUsernamePasswordCredential (org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential)1 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)1 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)1 AllCredentialsValidatedAuthenticationPolicy (org.apereo.cas.authentication.policy.AllCredentialsValidatedAuthenticationPolicy)1 PrincipalFactoryUtils (org.apereo.cas.authentication.principal.PrincipalFactoryUtils)1 PersonDirectoryPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver)1 PrincipalResolutionContext (org.apereo.cas.authentication.principal.resolvers.PrincipalResolutionContext)1 PrincipalAttributesCoreProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesCoreProperties)1 RememberMeAuthenticationProperties (org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)1 Assertions (org.junit.jupiter.api.Assertions)1