use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class AuthenticationPolicyAwareServiceTicketValidationAuthorizerTests method verifyRequiredHandlerAuthenticationPolicy.
@Test
public void verifyRequiredHandlerAuthenticationPolicy() {
val handler = getAcceptUsersAuthenticationHandler();
val handlers = List.of(getTestOtpAuthenticationHandler(), handler, getSimpleTestAuthenticationHandler());
val service = CoreAuthenticationTestUtils.getService("https://example.com/high/");
val authz = getAuthorizer(new RequiredAuthenticationHandlerAuthenticationPolicy(handler.getName()), handlers);
val map = (Map) Map.of(new UsernamePasswordCredential(), handler, getOtpCredential(), getTestOtpAuthenticationHandler());
val assertion = getAssertion(map);
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
authz.authorize(new MockHttpServletRequest(), service, assertion);
}
});
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class AuthenticationPolicyAwareServiceTicketValidationAuthorizerTests method verifyAllAuthenticationHandlersSucceededAuthenticationPolicy.
@Test
public void verifyAllAuthenticationHandlersSucceededAuthenticationPolicy() {
val handlers = List.of(getTestOtpAuthenticationHandler(), getAcceptUsersAuthenticationHandler(), getSimpleTestAuthenticationHandler());
val service = CoreAuthenticationTestUtils.getService("https://example.com/high/");
val authz = getAuthorizer(new AllAuthenticationHandlersSucceededAuthenticationPolicy(), handlers);
val map = (Map) Map.of(new UsernamePasswordCredential(), getAcceptUsersAuthenticationHandler(), getOtpCredential(), getTestOtpAuthenticationHandler());
val assertion = getAssertion(map);
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
authz.authorize(new MockHttpServletRequest(), service, assertion);
}
});
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class PersonDirectoryPrincipalResolverActiveDirectoryTests method verifyResolver.
@Test
public void verifyResolver() {
val resolver = CoreAuthenticationUtils.newPersonDirectoryPrincipalResolver(PrincipalFactoryUtils.newPrincipalFactory(), this.attributeRepository, CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger()), casProperties.getPersonDirectory());
val p = resolver.resolve(new UsernamePasswordCredential("admin", "P@ssw0rd"), Optional.of(CoreAuthenticationTestUtils.getPrincipal()), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("description"));
assertTrue(p.getAttributes().containsKey("objectGUID"));
assertTrue(p.getAttributes().containsKey("objectSid"));
CollectionUtils.firstElement(p.getAttributes().get("objectGUID")).ifPresent(value -> assertNotNull(EncodingUtils.decodeBase64(value.toString())));
CollectionUtils.firstElement(p.getAttributes().get("objectSid")).ifPresent(value -> assertNotNull(EncodingUtils.decodeBase64(value.toString())));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class PersonDirectoryPrincipalResolverLdapTests method verifyChainedResolver.
@Test
public void verifyChainedResolver() {
val resolver = CoreAuthenticationUtils.newPersonDirectoryPrincipalResolver(PrincipalFactoryUtils.newPrincipalFactory(), this.attributeRepository, CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger()), casProperties.getPersonDirectory());
val chain = new ChainingPrincipalResolver(new DefaultPrincipalElectionStrategy(), casProperties);
chain.setChain(Arrays.asList(new EchoingPrincipalResolver(), resolver));
val attributes = new HashMap<String, List<Object>>(2);
attributes.put("a1", List.of("v1"));
attributes.put("a2", List.of("v2"));
val p = chain.resolve(new UsernamePasswordCredential("admin", "password"), Optional.of(CoreAuthenticationTestUtils.getPrincipal("admin", attributes)), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("cn"));
assertTrue(p.getAttributes().containsKey("a1"));
assertTrue(p.getAttributes().containsKey("a2"));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class OpenLdapPasswordManagementServiceTests method verifyPasswordChangedFails.
@Test
public void verifyPasswordChangedFails() {
val credential = new UsernamePasswordCredential("caspm", "123456");
val bean = new PasswordChangeRequest();
bean.setConfirmedPassword("Mellon");
bean.setPassword("Mellon");
bean.setUsername(credential.getUsername());
assertTrue(passwordChangeService.change(credential, bean));
}
Aggregations