use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.
the class ChainingPrincipalResolverTests method examineResolve.
@Test
public void examineResolve() throws Exception {
final Credential credential = mock(Credential.class);
when(credential.getId()).thenReturn("input");
final PrincipalResolver resolver1 = mock(PrincipalResolver.class);
when(resolver1.supports(eq(credential))).thenReturn(true);
when(resolver1.resolve(eq(credential), any(Principal.class), any(AuthenticationHandler.class))).thenReturn(principalFactory.createPrincipal("output"));
final PrincipalResolver resolver2 = mock(PrincipalResolver.class);
when(resolver2.supports(any(Credential.class))).thenReturn(true);
when(resolver2.resolve(any(Credential.class), any(Principal.class), any(AuthenticationHandler.class))).thenReturn(principalFactory.createPrincipal("output", Collections.<String, Object>singletonMap("mail", "final@example.com")));
final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
resolver.setChain(Arrays.asList(resolver1, resolver2));
final Principal principal = resolver.resolve(credential, any(Principal.class), new SimpleTestUsernamePasswordAuthenticationHandler());
assertEquals("output", principal.getId());
assertEquals("final@example.com", principal.getAttributes().get("mail"));
}
use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyChainingResolverOverwrite.
@Test
public void verifyChainingResolverOverwrite() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
resolver.setAttributeRepository(CoreAuthenticationTestUtils.getAttributeRepository());
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Map<String, Object> attributes = new HashMap<>();
attributes.put("cn", "changedCN");
attributes.put(ATTR_1, "value1");
final Principal p = chain.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), CoreAuthenticationTestUtils.getPrincipal(CoreAuthenticationTestUtils.CONST_USERNAME, attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
assertEquals(p.getAttributes().size(), CoreAuthenticationTestUtils.getAttributeRepository().getPossibleUserAttributeNames().size() + 1);
assertTrue(p.getAttributes().containsKey(ATTR_1));
assertTrue(p.getAttributes().containsKey("cn"));
assertTrue(CollectionUtils.toCollection(p.getAttributes().get("cn")).contains("changedCN"));
}
use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.
the class SamlAuthenticationMetaDataPopulatorTests method newAuthenticationBuilder.
private static AuthenticationBuilder newAuthenticationBuilder(final Principal principal) {
final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess("test", new DefaultHandlerResult(handler, meta));
}
use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.
the class X509SerialNumberPrincipalResolverTests method verifyResolvePrincipalInternal.
@Test
public void verifyResolvePrincipalInternal() {
final X509CertificateCredential c = new X509CertificateCredential(new X509Certificate[] { VALID_CERTIFICATE });
c.setCertificate(VALID_CERTIFICATE);
assertEquals(VALID_CERTIFICATE.getSerialNumber().toString(), this.resolver.resolve(c, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
use of org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler in project cas by apereo.
the class X509SerialNumberAndIssuerDNPrincipalResolverTests method verifyResolvePrincipalInternal.
@Test
public void verifyResolvePrincipalInternal() {
final X509CertificateCredential c = new X509CertificateCredential(new X509Certificate[] { VALID_CERTIFICATE });
c.setCertificate(VALID_CERTIFICATE);
final String value = "SERIALNUMBER=" + VALID_CERTIFICATE.getSerialNumber().toString() + ", " + VALID_CERTIFICATE.getIssuerDN().getName();
assertEquals(value, this.resolver.resolve(c, CoreAuthenticationTestUtils.getPrincipal(), new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
Aggregations