Search in sources :

Example 61 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)61 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)60 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)60 Test (org.junit.Test)55 MockServletContext (org.springframework.mock.web.MockServletContext)54 MockRequestContext (org.springframework.webflow.test.MockRequestContext)50 Event (org.springframework.webflow.execution.Event)22 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)15 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 Credential (org.apereo.cas.authentication.Credential)7 Cookie (javax.servlet.http.Cookie)6 Service (org.apereo.cas.authentication.principal.Service)5 Clients (org.pac4j.core.client.Clients)5 FacebookClient (org.pac4j.oauth.client.FacebookClient)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3