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();
}
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);
}
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());
}
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"));
}
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);
}
Aggregations