use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class ByCredentialTypeAuthenticationHandlerResolverTests method verifyResolves.
@Test
public void verifyResolves() {
val resolver = new ByCredentialTypeAuthenticationHandlerResolver(UsernamePasswordCredential.class);
val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
c.setSource("TestHandler");
val handler = new SimpleTestUsernamePasswordAuthenticationHandler("TESTHANDLER");
val results = resolver.resolve(CollectionUtils.wrapSet(handler), new DefaultAuthenticationTransactionFactory().newTransaction(c));
assertFalse(results.isEmpty());
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class BaseThrottledSubmissionHandlerInterceptorAdapterTests method loginUnsuccessfully.
@SneakyThrows
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
request.setRequestURI("/cas/login");
val context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
getThrottle().preHandle(request, response, null);
try {
val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(CoreAuthenticationTestUtils.getService(), badCredentials(username));
authenticationManager.authenticate(transaction);
} catch (final AuthenticationException e) {
getThrottle().postHandle(request, response, null, null);
return response;
} finally {
getThrottle().afterCompletion(request, response, null, null);
}
throw new AssertionError("Expected AbstractAuthenticationException");
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory in project cas by apereo.
the class WsFederationCredentialsToPrincipalResolverTests method verifyMultipleAttributes.
@Test
public void verifyMultipleAttributes() {
val attributes = new HashMap<>(CoreAuthenticationTestUtils.getAttributeRepository().getBackingMap());
attributes.put("upn", List.of("cas1", "cas2"));
val creds = getCredential(attributes);
val auth = authenticationManager.authenticate(new DefaultAuthenticationTransactionFactory().newTransaction(creds));
assertNotNull(auth);
}
use of org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory 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.DefaultAuthenticationTransactionFactory 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);
}
Aggregations