Search in sources :

Example 6 with DefaultPrincipalElectionStrategy

use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.

the class ServiceTicketResourceTests method initialize.

@BeforeEach
public void initialize() {
    val mgmr = mock(AuthenticationManager.class);
    lenient().when(mgmr.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    lenient().when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    val publisher = mock(ApplicationEventPublisher.class);
    this.serviceTicketResource = new ServiceTicketResource(new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(publisher, mgmr), new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory()), ticketSupport, new DefaultArgumentExtractor(new WebApplicationServiceFactory()), new CasProtocolServiceTicketResourceEntityResponseFactory(casMock), new UsernamePasswordRestHttpRequestCredentialFactory(), new GenericApplicationContext());
    this.mockMvc = MockMvcBuilders.standaloneSetup(this.serviceTicketResource).defaultRequest(get("/").contextPath("/cas").accept(MediaType.APPLICATION_FORM_URLENCODED, MediaType.TEXT_PLAIN).contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
Also used : lombok.val(lombok.val) UsernamePasswordRestHttpRequestCredentialFactory(org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory) ServiceTicketResource(org.apereo.cas.support.rest.resources.ServiceTicketResource) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) CasProtocolServiceTicketResourceEntityResponseFactory(org.apereo.cas.rest.factory.CasProtocolServiceTicketResourceEntityResponseFactory) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with DefaultPrincipalElectionStrategy

use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.

the class RegisteredServiceResourceTests method getRegisteredServiceResource.

private RegisteredServiceResource getRegisteredServiceResource(final String attrName, final String attrValue) {
    val mgmr = mock(AuthenticationManager.class);
    lenient().when(mgmr.authenticate(argThat(new AuthenticationCredentialMatcher("test")))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    lenient().when(mgmr.authenticate(argThat(new AuthenticationCredentialMatcher("testfail")))).thenThrow(AuthenticationException.class);
    val publisher = mock(ApplicationEventPublisher.class);
    return new RegisteredServiceResource(new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(publisher, mgmr), new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory()), new WebApplicationServiceFactory(), servicesManager, attrName, attrValue);
}
Also used : lombok.val(lombok.val) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)

Example 8 with DefaultPrincipalElectionStrategy

use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.

the class RememberMeDelegatingExpirationPolicyTests method verifyTicketExpirationWithRememberMeBuiltAuthn.

@Test
public void verifyTicketExpirationWithRememberMeBuiltAuthn() {
    val builder = new DefaultAuthenticationResultBuilder();
    val p1 = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("uid", "casuser"));
    val authn1 = CoreAuthenticationTestUtils.getAuthentication(p1, CollectionUtils.wrap(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, true));
    val result = builder.collect(authn1).build(new DefaultPrincipalElectionStrategy());
    val authentication = result.getAuthentication();
    assertNotNull(authentication);
    val t = new TicketGrantingTicketImpl("111", authentication, this.expirationPolicy);
    assertFalse(t.isExpired());
    t.grantServiceTicket("55", RegisteredServiceTestUtils.getService(), this.expirationPolicy, false, true);
    assertTrue(t.isExpired());
}
Also used : lombok.val(lombok.val) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) DefaultAuthenticationResultBuilder(org.apereo.cas.authentication.DefaultAuthenticationResultBuilder) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultPrincipalElectionStrategy

use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.

the class BaseActionTests method assertMfa.

protected void assertMfa() {
    val builder = WebUtils.getAuthenticationResultBuilder(requestContext);
    val attributes = builder.build(new DefaultPrincipalElectionStrategy()).getAuthentication().getAttributes();
    assertNotNull(attributes.get("inweboAuthenticationDevice"));
}
Also used : lombok.val(lombok.val) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)

Example 10 with DefaultPrincipalElectionStrategy

use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.

the class BaseActionTests method setUp.

@BeforeEach
public void setUp() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, CoreAuthenticationTestUtils.getAuthenticationSystemSupport(), AuthenticationSystemSupport.BEAN_NAME);
    requestContext = new MockRequestContext();
    request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    requestContext.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    setRequestContext(requestContext);
    setExternalContext(requestContext.getExternalContext());
    ((DefaultMessageContext) requestContext.getMessageContext()).setMessageSource(new AbstractMessageSource() {

        @Override
        protected MessageFormat resolveCode(final String code, final Locale locale) {
            return new MessageFormat(StringUtils.EMPTY);
        }
    });
    service = mock(InweboService.class);
    val authenticationEventExecutionPlan = new DefaultAuthenticationEventExecutionPlan();
    authenticationEventExecutionPlan.registerAuthenticationHandler(new InweboAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), new InweboMultifactorAuthenticationProperties(), service));
    authenticationEventExecutionPlan.registerAuthenticationMetadataPopulator(new InweboAuthenticationDeviceMetadataPopulator());
    val authenticationManager = new DefaultAuthenticationManager(authenticationEventExecutionPlan, true, applicationContext);
    val authenticationTransactionManager = new DefaultAuthenticationTransactionManager(applicationContext, authenticationManager);
    val authenticationSystemSupport = new DefaultAuthenticationSystemSupport(authenticationTransactionManager, new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory());
    val context = CasWebflowEventResolutionConfigurationContext.builder().authenticationSystemSupport(authenticationSystemSupport).build();
    resolver = new InweboMultifactorAuthenticationWebflowEventResolver(context);
    setAuthenticationInContext(LOGIN);
}
Also used : Locale(java.util.Locale) InweboAuthenticationDeviceMetadataPopulator(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationDeviceMetadataPopulator) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultAuthenticationManager(org.apereo.cas.authentication.DefaultAuthenticationManager) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) AbstractMessageSource(org.springframework.context.support.AbstractMessageSource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) lombok.val(lombok.val) InweboAuthenticationHandler(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationHandler) InweboMultifactorAuthenticationWebflowEventResolver(org.apereo.cas.support.inwebo.web.flow.InweboMultifactorAuthenticationWebflowEventResolver) MessageFormat(java.text.MessageFormat) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) DefaultAuthenticationEventExecutionPlan(org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) InweboMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.InweboMultifactorAuthenticationProperties) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) InweboService(org.apereo.cas.support.inwebo.service.InweboService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

lombok.val (lombok.val)20 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)20 Test (org.junit.jupiter.api.Test)13 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 HashMap (java.util.HashMap)4 DefaultAuthenticationResultBuilderFactory (org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory)4 DefaultAuthenticationSystemSupport (org.apereo.cas.authentication.DefaultAuthenticationSystemSupport)4 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)4 DefaultAuthenticationTransactionManager (org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)4 Credential (org.apereo.cas.authentication.Credential)3 DefaultAuthenticationResultBuilder (org.apereo.cas.authentication.DefaultAuthenticationResultBuilder)3 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2