use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy 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.principal.DefaultPrincipalElectionStrategy in project cas by apereo.
the class BaseActionTests method assertNoMfa.
protected void assertNoMfa() {
val builder = WebUtils.getAuthenticationResultBuilder(requestContext);
val attributes = builder.build(new DefaultPrincipalElectionStrategy()).getAuthentication().getAttributes();
assertNull(attributes.get("inweboAuthenticationDevice"));
}
use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.
the class TicketGrantingTicketResourceTests method initialize.
@BeforeEach
public void initialize() {
val httpRequestCredentialFactory = new UsernamePasswordRestHttpRequestCredentialFactory() {
@Override
public List<Credential> fromAuthentication(final HttpServletRequest request, final MultiValueMap<String, String> requestBody, final Authentication authentication, final MultifactorAuthenticationProvider provider) {
if (provider.getId().contains("unknown")) {
return List.of();
}
return List.of(new UsernamePasswordCredential("mfa-user", "mfa-user"));
}
};
val publisher = mock(ApplicationEventPublisher.class);
val manager = mock(AuthenticationManager.class);
lenient().when(manager.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
lenient().when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
lenient().when(requestedContextValidator.validateAuthenticationContext(any(), any(), any(), any(), any())).thenReturn(AuthenticationContextValidationResult.builder().success(true).build());
lenient().when(multifactorTriggerSelectionStrategy.resolve(any(), any(), any(), any(), any())).thenReturn(Optional.empty());
val authenticationSystemSupport = new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(publisher, manager), new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory());
val api = new DefaultRestAuthenticationService(authenticationSystemSupport, httpRequestCredentialFactory, new WebApplicationServiceFactory(), multifactorTriggerSelectionStrategy, servicesManager, requestedContextValidator);
val logoutManager = new DefaultLogoutManager(false, new DefaultLogoutExecutionPlan());
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
this.ticketGrantingTicketResourceUnderTest = new TicketGrantingTicketResource(api, casMock, new DefaultTicketGrantingTicketResourceEntityResponseFactory(), new GenericWebApplicationContext(), new DefaultSingleLogoutRequestExecutor(casMock, logoutManager, applicationContext));
this.mockMvc = MockMvcBuilders.standaloneSetup(this.ticketGrantingTicketResourceUnderTest).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.
the class UserAuthenticationResourceTests method verifyStatus.
@Test
public void verifyStatus() throws Exception {
val builder = new DefaultAuthenticationResultBuilder().collect(CoreAuthenticationTestUtils.getAuthentication());
val result = builder.build(new DefaultPrincipalElectionStrategy());
lenient().when(authenticationSupport.finalizeAuthenticationTransaction(any(), anyCollection())).thenReturn(result);
when(authenticationSupport.handleInitialAuthenticationTransaction(any(), any())).thenReturn(builder);
when(authenticationSupport.finalizeAllAuthenticationTransactions(any(), any())).thenReturn(result);
when(requestedContextValidator.validateAuthenticationContext(any(), any(), any(), any(), any())).thenReturn(AuthenticationContextValidationResult.builder().success(false).build());
when(multifactorTriggerSelectionStrategy.resolve(any(), any(), any(), any(), any())).thenReturn(Optional.empty());
this.mockMvc.perform(post(TICKETS_RESOURCE_URL).param("username", "casuser").param("password", "Mellon")).andExpect(status().isOk());
}
use of org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy in project cas by apereo.
the class UserAuthenticationResourceTests method verifyAuthWithMfa.
@Test
public void verifyAuthWithMfa() throws Exception {
val builder = new DefaultAuthenticationResultBuilder().collect(CoreAuthenticationTestUtils.getAuthentication());
val result = builder.build(new DefaultPrincipalElectionStrategy());
when(authenticationSupport.finalizeAuthenticationTransaction(any(), anyCollection())).thenReturn(result);
when(authenticationSupport.handleInitialAuthenticationTransaction(any(), any())).thenReturn(builder);
when(requestedContextValidator.validateAuthenticationContext(any(), any(), any(), any(), any())).thenReturn(AuthenticationContextValidationResult.builder().success(false).build());
when(multifactorTriggerSelectionStrategy.resolve(any(), any(), any(), any(), any())).thenReturn(Optional.of(new TestMultifactorAuthenticationProvider()));
this.mockMvc.perform(post(TICKETS_RESOURCE_URL).param("username", "casuser").param("password", "Mellon")).andExpect(status().isOk());
}
Aggregations