Search in sources :

Example 11 with SimpleTestUsernamePasswordAuthenticationHandler

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

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private AuthenticationBuilder newBuilder(final Credential credential) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final AuthenticationBuilder builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultHandlerResult(handler, meta));
    if (this.p.supports(credential)) {
        this.p.populateAttributes(builder, credential);
    }
    return builder;
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 12 with SimpleTestUsernamePasswordAuthenticationHandler

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

the class X509SubjectDNPrincipalResolverTests method verifyResolvePrincipalInternal.

@Test
public void verifyResolvePrincipalInternal() {
    final X509CertificateCredential c = new X509CertificateCredential(new X509Certificate[] { VALID_CERTIFICATE });
    c.setCertificate(VALID_CERTIFICATE);
    assertEquals(VALID_CERTIFICATE.getSubjectDN().getName(), this.resolver.resolve(c, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
Also used : SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) Test(org.junit.Test)

Example 13 with SimpleTestUsernamePasswordAuthenticationHandler

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

the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyChainedResolver.

@Test
public void verifyChainedResolver() {
    this.getEntries().forEach(entry -> {
        final String username = entry.getAttribute("sAMAccountName").getStringValue();
        final String psw = entry.getAttribute(ATTR_NAME_PASSWORD).getStringValue();
        final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
        resolver.setAttributeRepository(this.attributeRepository);
        final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
        chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
        final Map<String, Object> attributes = new HashMap<>(2);
        attributes.put("a1", "v1");
        attributes.put("a2", "v2");
        final Principal p = chain.resolve(new UsernamePasswordCredential(username, psw), CoreAuthenticationTestUtils.getPrincipal(username, attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
        assertNotNull(p);
        assertTrue(p.getAttributes().containsKey("displayName"));
        assertTrue(p.getAttributes().containsKey("a1"));
        assertTrue(p.getAttributes().containsKey("a2"));
    });
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) HashMap(java.util.HashMap) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with SimpleTestUsernamePasswordAuthenticationHandler

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

the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyResolver.

@Test
public void verifyResolver() {
    this.getEntries().forEach(entry -> {
        final String username = entry.getAttribute("sAMAccountName").getStringValue();
        final String psw = entry.getAttribute(ATTR_NAME_PASSWORD).getStringValue();
        final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
        resolver.setAttributeRepository(this.attributeRepository);
        final Principal p = resolver.resolve(new UsernamePasswordCredential(username, psw), CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler());
        assertNotNull(p);
        assertTrue(p.getAttributes().containsKey("displayName"));
    });
}
Also used : PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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