Search in sources :

Example 61 with UsernamePasswordCredential

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);
        }
    });
}
Also used : lombok.val(lombok.val) RequiredAuthenticationHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredAuthenticationHandlerAuthenticationPolicy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Executable(org.junit.jupiter.api.function.Executable) Map(java.util.Map) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 62 with UsernamePasswordCredential

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);
        }
    });
}
Also used : lombok.val(lombok.val) AllAuthenticationHandlersSucceededAuthenticationPolicy(org.apereo.cas.authentication.policy.AllAuthenticationHandlersSucceededAuthenticationPolicy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Executable(org.junit.jupiter.api.function.Executable) Map(java.util.Map) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with UsernamePasswordCredential

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())));
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 64 with UsernamePasswordCredential

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"));
}
Also used : lombok.val(lombok.val) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) HashMap(java.util.HashMap) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) ChainingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.ChainingPrincipalResolver) EchoingPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.EchoingPrincipalResolver) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 65 with UsernamePasswordCredential

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));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)111 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)111 Test (org.junit.jupiter.api.Test)74 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)12 HashMap (java.util.HashMap)8 Map (java.util.Map)8 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)8 LinkedHashMap (java.util.LinkedHashMap)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockRequestContext (org.springframework.webflow.test.MockRequestContext)6 ArrayList (java.util.ArrayList)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 FailedLoginException (javax.security.auth.login.FailedLoginException)4 SurrogateUsernamePasswordCredential (org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)4