Search in sources :

Example 46 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class PrincipalFromRequestRemoteUserNonInteractiveCredentialsActionTests method verifyRemoteUserExists.

@Test
public void verifyRemoteUserExists() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteUser("test");
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    assertEquals("success", this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 47 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project cas by apereo.

the class PrincipalFromRequestUserPrincipalNonInteractiveCredentialsActionTests method verifyRemoteUserExists.

@Test
public void verifyRemoteUserExists() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setUserPrincipal(() -> "test");
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    Assert.assertEquals("success", this.action.execute(context).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 48 with ServletExternalContext

use of org.springframework.webflow.context.servlet.ServletExternalContext in project oxTrust by GluuFederation.

the class ClientAuthenticationHandler method doAuthentication.

/**
	 * {@InheritDoc}
	 */
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final ClientCredential clientCredentials = (ClientCredential) credential;
    final OpenIdCredentials openIdCredentials = clientCredentials.getOpenIdCredentials();
    logger.debug("Client credentials : '{}'", clientCredentials);
    final String clientName = openIdCredentials.getClientName();
    logger.debug("Client name : '{}'", clientName);
    // Web context
    final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
    final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();
    final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();
    final WebContext webContext = new J2EContext(request, response);
    // Get user profile
    final UserProfile userProfile = this.client.getUserProfile(openIdCredentials, webContext);
    logger.debug("userProfile : {}", userProfile);
    if (userProfile != null) {
        final String id = userProfile.getId();
        if (StringHelper.isNotEmpty(id)) {
            openIdCredentials.setUserProfile(userProfile);
            return new HandlerResult(this, clientCredentials, new SimplePrincipal(id, userProfile.getAttributes()));
        }
    }
    throw new FailedLoginException("Provider did not produce profile for " + clientCredentials);
}
Also used : ClientCredential(org.gluu.oxauth.cas.auth.principal.ClientCredential) HttpServletRequest(javax.servlet.http.HttpServletRequest) WebContext(org.xdi.context.WebContext) FailedLoginException(javax.security.auth.login.FailedLoginException) UserProfile(org.gluu.oxauth.client.auth.user.UserProfile) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) OpenIdCredentials(org.gluu.oxauth.client.auth.principal.OpenIdCredentials) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerResult(org.jasig.cas.authentication.HandlerResult) J2EContext(org.xdi.context.J2EContext) SimplePrincipal(org.jasig.cas.authentication.principal.SimplePrincipal)

Aggregations

ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)47 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)47 Test (org.junit.Test)44 MockServletContext (org.springframework.mock.web.MockServletContext)43 MockRequestContext (org.springframework.webflow.test.MockRequestContext)40 Event (org.springframework.webflow.execution.Event)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)11 Credential (org.apereo.cas.authentication.Credential)7 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)7 Cookie (javax.servlet.http.Cookie)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Service (org.apereo.cas.authentication.principal.Service)3 SamlMetadataUIInfo (org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)2 Authentication (org.apereo.cas.authentication.Authentication)2 OpenIdService (org.apereo.cas.support.openid.authentication.principal.OpenIdService)2 OpenIdServiceFactory (org.apereo.cas.support.openid.authentication.principal.OpenIdServiceFactory)2 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)2