Search in sources :

Example 1 with DefaultAuthenticationTransactionFactory

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());
}
Also used : lombok.val(lombok.val) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultAuthenticationTransactionFactory

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");
}
Also used : lombok.val(lombok.val) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SneakyThrows(lombok.SneakyThrows)

Example 3 with DefaultAuthenticationTransactionFactory

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);
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultAuthenticationTransactionFactory

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();
}
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 5 with DefaultAuthenticationTransactionFactory

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);
}
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)

Aggregations

lombok.val (lombok.val)33 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)33 Test (org.junit.jupiter.api.Test)27 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)9 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)9 RegisteredServiceAuthenticationPolicyResolver (org.apereo.cas.authentication.policy.RegisteredServiceAuthenticationPolicyResolver)7 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)5 DefaultAuthenticationResultBuilderFactory (org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory)4 DefaultAuthenticationSystemSupport (org.apereo.cas.authentication.DefaultAuthenticationSystemSupport)4 DefaultAuthenticationTransactionManager (org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)4 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)4 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)3 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 HashMap (java.util.HashMap)2 AuthenticationTransaction (org.apereo.cas.authentication.AuthenticationTransaction)2 RegisteredServiceAuthenticationHandlerResolver (org.apereo.cas.authentication.handler.RegisteredServiceAuthenticationHandlerResolver)2 AtLeastOneCredentialValidatedAuthenticationPolicy (org.apereo.cas.authentication.policy.AtLeastOneCredentialValidatedAuthenticationPolicy)2 UsernamePasswordRestHttpRequestCredentialFactory (org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory)2