Search in sources :

Example 1 with UsernamePasswordRestHttpRequestCredentialFactory

use of org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory in project cas by apereo.

the class TicketGrantingTicketResourceTests method setUp.

@Before
public void setUp() {
    final AuthenticationManager mgmr = mock(AuthenticationManager.class);
    when(mgmr.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
    this.ticketGrantingTicketResourceUnderTest = new TicketGrantingTicketResource(new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(mgmr), new DefaultPrincipalElectionStrategy()), new UsernamePasswordRestHttpRequestCredentialFactory(), casMock, new WebApplicationServiceFactory(), new DefaultTicketGrantingTicketResourceEntityResponseFactory());
    this.mockMvc = MockMvcBuilders.standaloneSetup(this.ticketGrantingTicketResourceUnderTest).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
Also used : AuthenticationManager(org.apereo.cas.authentication.AuthenticationManager) TicketGrantingTicketResource(org.apereo.cas.support.rest.resources.TicketGrantingTicketResource) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.DefaultPrincipalElectionStrategy) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) UsernamePasswordRestHttpRequestCredentialFactory(org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory) DefaultTicketGrantingTicketResourceEntityResponseFactory(org.apereo.cas.rest.factory.DefaultTicketGrantingTicketResourceEntityResponseFactory) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) Before(org.junit.Before)

Example 2 with UsernamePasswordRestHttpRequestCredentialFactory

use of org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory 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 3 with UsernamePasswordRestHttpRequestCredentialFactory

use of org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory 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();
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) DefaultLogoutExecutionPlan(org.apereo.cas.logout.DefaultLogoutExecutionPlan) TicketGrantingTicketResource(org.apereo.cas.support.rest.resources.TicketGrantingTicketResource) DefaultLogoutManager(org.apereo.cas.logout.DefaultLogoutManager) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) UsernamePasswordRestHttpRequestCredentialFactory(org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory) MultifactorAuthenticationProvider(org.apereo.cas.authentication.MultifactorAuthenticationProvider) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) DefaultRestAuthenticationService(org.apereo.cas.rest.authentication.DefaultRestAuthenticationService) HttpServletRequest(javax.servlet.http.HttpServletRequest) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultTicketGrantingTicketResourceEntityResponseFactory(org.apereo.cas.rest.factory.DefaultTicketGrantingTicketResourceEntityResponseFactory) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) DefaultSingleLogoutRequestExecutor(org.apereo.cas.logout.slo.DefaultSingleLogoutRequestExecutor) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MultiValueMap(org.springframework.util.MultiValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with UsernamePasswordRestHttpRequestCredentialFactory

use of org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory in project cas by apereo.

the class UserAuthenticationResourceTests 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 api = new DefaultRestAuthenticationService(authenticationSupport, httpRequestCredentialFactory, new WebApplicationServiceFactory(), multifactorTriggerSelectionStrategy, servicesManager, requestedContextValidator);
    this.userAuthenticationResource = new UserAuthenticationResource(api, new DefaultUserAuthenticationResourceEntityResponseFactory(), new GenericApplicationContext());
    this.mockMvc = MockMvcBuilders.standaloneSetup(this.userAuthenticationResource).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) UserAuthenticationResource(org.apereo.cas.support.rest.resources.UserAuthenticationResource) UsernamePasswordRestHttpRequestCredentialFactory(org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory) MultifactorAuthenticationProvider(org.apereo.cas.authentication.MultifactorAuthenticationProvider) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) DefaultRestAuthenticationService(org.apereo.cas.rest.authentication.DefaultRestAuthenticationService) HttpServletRequest(javax.servlet.http.HttpServletRequest) DefaultUserAuthenticationResourceEntityResponseFactory(org.apereo.cas.rest.factory.DefaultUserAuthenticationResourceEntityResponseFactory) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Authentication(org.apereo.cas.authentication.Authentication) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) MultiValueMap(org.springframework.util.MultiValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)4 UsernamePasswordRestHttpRequestCredentialFactory (org.apereo.cas.rest.factory.UsernamePasswordRestHttpRequestCredentialFactory)4 lombok.val (lombok.val)3 AuthenticationTransaction (org.apereo.cas.authentication.AuthenticationTransaction)3 DefaultAuthenticationSystemSupport (org.apereo.cas.authentication.DefaultAuthenticationSystemSupport)3 DefaultAuthenticationTransactionManager (org.apereo.cas.authentication.DefaultAuthenticationTransactionManager)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Authentication (org.apereo.cas.authentication.Authentication)2 Credential (org.apereo.cas.authentication.Credential)2 DefaultAuthenticationResultBuilderFactory (org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory)2 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)2 MultifactorAuthenticationProvider (org.apereo.cas.authentication.MultifactorAuthenticationProvider)2 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)2 TestMultifactorAuthenticationProvider (org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider)2 DefaultPrincipalElectionStrategy (org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy)2 DefaultRestAuthenticationService (org.apereo.cas.rest.authentication.DefaultRestAuthenticationService)2 DefaultTicketGrantingTicketResourceEntityResponseFactory (org.apereo.cas.rest.factory.DefaultTicketGrantingTicketResourceEntityResponseFactory)2 TicketGrantingTicketResource (org.apereo.cas.support.rest.resources.TicketGrantingTicketResource)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2