use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.
private static AuthenticationBuilder newBuilder(final Credential credential, final RememberMeAuthenticationProperties properties) {
val populator = new RememberMeAuthenticationMetaDataPopulator(properties);
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
if (populator.supports(credential)) {
populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credential));
}
return builder;
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class RegisteredServiceAuthenticationPolicyResolverTests method checkRestPolicy.
@Test
public void checkRestPolicy() {
val resolver = new RegisteredServiceAuthenticationPolicyResolver(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(RegisteredServiceTestUtils.getService("serviceid6"), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
val policies = resolver.resolve(transaction);
assertEquals(1, policies.size());
assertTrue(policies.iterator().next() instanceof RestfulAuthenticationPolicy);
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class RegisteredServiceAuthenticationPolicyResolverTests method checkNotPreventedPolicy.
@Test
public void checkNotPreventedPolicy() {
val resolver = new RegisteredServiceAuthenticationPolicyResolver(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(RegisteredServiceTestUtils.getService("serviceid4"), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
val policies = resolver.resolve(transaction);
assertEquals(1, policies.size());
assertTrue(policies.iterator().next() instanceof NotPreventedAuthenticationPolicy);
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class SamlAuthenticationMetaDataPopulatorTests method verifyAuthenticationTypeFoundCustom.
@Test
public void verifyAuthenticationTypeFoundCustom() {
val credentials = new CustomCredential();
val added = new HashMap<String, String>();
added.put(CustomCredential.class.getName(), "FF");
this.populator.setUserDefinedMappings(added);
val builder = CoreAuthenticationTestUtils.getAuthenticationBuilder();
this.populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credentials));
val auth = builder.build();
assertEquals("FF", auth.getAttributes().get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD).get(0));
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory 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();
}
Aggregations