Search in sources :

Example 1 with ClientCredential

use of org.gluu.oxauth.cas.auth.principal.ClientCredential in project oxTrust by GluuFederation.

the class ClientAuthenticationMetaDataPopulator method populateAttributes.

/**
	 * {@InheritDoc}
	 */
@Override
public void populateAttributes(final AuthenticationBuilder builder, final Credential credential) {
    if (credential instanceof ClientCredential) {
        final ClientCredential clientCredential = (ClientCredential) credential;
        builder.addAttribute(CLIENT_NAME, clientCredential.getOpenIdCredentials().getClientName());
    }
}
Also used : ClientCredential(org.gluu.oxauth.cas.auth.principal.ClientCredential)

Example 2 with ClientCredential

use of org.gluu.oxauth.cas.auth.principal.ClientCredential in project oxTrust by GluuFederation.

the class ClientAction method doExecute.

/**
	 * {@InheritDoc}
	 */
@Override
protected Event doExecute(final RequestContext context) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    // Web context
    final WebContext webContext = new J2EContext(request, response);
    // It's an authentication
    if (client.isAuthorizationResponse(webContext)) {
        logger.info("Procession authentication request");
        // Check if oxAuth request state is correct
        if (!client.isValidRequestState(webContext)) {
            logger.warn("The state in session and in request are not equals");
            // Reinit login page
            prepareForLoginPage(context, webContext);
            return new Event(this, "stop");
        }
        // Try to authenticate
        final ClientCredential credentials = getClientCrendentials(context, webContext);
        if (credentials != null) {
            WebUtils.putTicketGrantingTicketInRequestScope(context, this.centralAuthenticationService.createTicketGrantingTicket(credentials));
            return success();
        }
    }
    // Go to login page
    prepareForLoginPage(context, webContext);
    return error();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ClientCredential(org.gluu.oxauth.cas.auth.principal.ClientCredential) WebContext(org.xdi.context.WebContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) Event(org.springframework.webflow.execution.Event) J2EContext(org.xdi.context.J2EContext)

Example 3 with ClientCredential

use of org.gluu.oxauth.cas.auth.principal.ClientCredential in project oxTrust by GluuFederation.

the class ClientAction method getClientCrendentials.

/**
	 * Build client credenatils from incomming request
	 * 
	 * @param context The current webflow context
	 * @param webContext The current web context
	 * @return client credentials
	 */
private ClientCredential getClientCrendentials(final RequestContext context, final WebContext webContext) {
    final OpenIdCredentials openIdCredentials = client.getCredentials(webContext);
    final ClientCredential credentials = new ClientCredential(openIdCredentials);
    // Retrieve parameters from web session
    final Service service = (Service) webContext.getSessionAttribute(SERVICE);
    if (service != null) {
        webContext.setRequestAttribute(SERVICE, service.getId());
    }
    context.getFlowScope().put(SERVICE, service);
    restoreRequestAttribute(webContext, THEME);
    restoreRequestAttribute(webContext, LOCALE);
    restoreRequestAttribute(webContext, METHOD);
    return credentials;
}
Also used : ClientCredential(org.gluu.oxauth.cas.auth.principal.ClientCredential) OpenIdCredentials(org.gluu.oxauth.client.auth.principal.OpenIdCredentials) Service(org.jasig.cas.authentication.principal.Service) CentralAuthenticationService(org.jasig.cas.CentralAuthenticationService)

Example 4 with ClientCredential

use of org.gluu.oxauth.cas.auth.principal.ClientCredential 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

ClientCredential (org.gluu.oxauth.cas.auth.principal.ClientCredential)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 OpenIdCredentials (org.gluu.oxauth.client.auth.principal.OpenIdCredentials)2 J2EContext (org.xdi.context.J2EContext)2 WebContext (org.xdi.context.WebContext)2 FailedLoginException (javax.security.auth.login.FailedLoginException)1 UserProfile (org.gluu.oxauth.client.auth.user.UserProfile)1 CentralAuthenticationService (org.jasig.cas.CentralAuthenticationService)1 HandlerResult (org.jasig.cas.authentication.HandlerResult)1 Service (org.jasig.cas.authentication.principal.Service)1 SimplePrincipal (org.jasig.cas.authentication.principal.SimplePrincipal)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 Event (org.springframework.webflow.execution.Event)1