Search in sources :

Example 6 with SimpleTestUsernamePasswordAuthenticationHandler

use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.

the class CoreAuthenticationTestUtils method getAuthentication.

public static Authentication getAuthentication(final Principal principal, final Map<String, Object> attributes) {
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("testHandler", new DefaultHandlerResult(handler, meta)).setAttributes(attributes).build();
}
Also used : SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)

Example 7 with SimpleTestUsernamePasswordAuthenticationHandler

use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.

the class SpnegoCredentialsToPrincipalResolverTests method verifyValidCredentials.

@Test
public void verifyValidCredentials() {
    this.spnegoCredentials.setPrincipal(new DefaultPrincipalFactory().createPrincipal("test"));
    assertEquals("test", this.resolver.resolve(this.spnegoCredentials, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
Also used : SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Test(org.junit.Test)

Example 8 with SimpleTestUsernamePasswordAuthenticationHandler

use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyNullPrincipal.

@Test
public void verifyNullPrincipal() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
    final Principal p = resolver.resolve(() -> null, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler());
    assertNull(p);
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) Test(org.junit.Test)

Example 9 with SimpleTestUsernamePasswordAuthenticationHandler

use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyChainingResolver.

@Test
public void verifyChainingResolver() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
    resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
    final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
    chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
    final Principal p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal(CoreAuthenticationTestUtils.CONST_USERNAME, Collections.singletonMap(ATTR_1, "value")), new SimpleTestUsernamePasswordAuthenticationHandler());
    assertEquals(p.getAttributes().size(), CoreAuthenticationTestUtils.getAttributeRepository().getPossibleUserAttributeNames().size() + 1);
    assertTrue(p.getAttributes().containsKey(ATTR_1));
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test)

Example 10 with SimpleTestUsernamePasswordAuthenticationHandler

use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.

the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverDistinct.

@Test
public void verifyChainingResolverDistinct() {
    final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
    resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
    final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
    chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
    this.thrown.expect(PrincipalException.class);
    chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal("somethingelse", Collections.singletonMap(ATTR_1, "value")), new SimpleTestUsernamePasswordAuthenticationHandler());
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test)

Aggregations

SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)14 Test (org.junit.Test)11 PersonDirectoryPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver)6 ChainingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver)5 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)4 EchoingPrincipalResolver (org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver)4 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)3 HashMap (java.util.HashMap)2 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)2 CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)2 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)2 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)1 Credential (org.apereo.cas.authentication.Credential)1 RememberMeUsernamePasswordCredential (org.apereo.cas.authentication.RememberMeUsernamePasswordCredential)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1