Search in sources :

Example 11 with AuthorizationGrant

use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.

the class CleanerTimer method processRegisteredClients.

private void processRegisteredClients() {
    log.debug("Start Client clean up");
    BatchOperation<Client> clientBatchService = new BatchOperation<Client>(ldapEntryManager) {

        @Override
        protected List<Client> getChunkOrNull(int chunkSize) {
            return clientService.getClientsWithExpirationDate(this, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Client> entries) {
            for (Client client : entries) {
                try {
                    GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                    GregorianCalendar expirationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                    expirationDate.setTime(client.getClientSecretExpiresAt());
                    if (expirationDate.before(now)) {
                        List<AuthorizationGrant> toRemove = authorizationGrantList.getAuthorizationGrant(client.getClientId());
                        authorizationGrantList.removeAuthorizationGrants(toRemove);
                        log.debug("Removing Client: {}, Expiration date: {}", client.getClientId(), client.getClientSecretExpiresAt());
                        clientService.remove(client);
                    }
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    clientBatchService.iterateAllByChunks(BATCH_SIZE);
    log.debug("End Client clean up");
}
Also used : AuthorizationGrantList(org.xdi.oxauth.model.common.AuthorizationGrantList) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) Client(org.xdi.oxauth.model.registration.Client) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 12 with AuthorizationGrant

use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceImpl method httpBased.

public Response httpBased(String postLogoutRedirectUri, String state, Pair<SessionState, AuthorizationGrant> pair) {
    SessionState sessionState = pair.getFirst();
    AuthorizationGrant authorizationGrant = pair.getSecond();
    // Validate redirectUri
    String redirectUri;
    if (authorizationGrant == null) {
        redirectUri = redirectionUriService.validatePostLogoutRedirectUri(sessionState, postLogoutRedirectUri);
    } else {
        redirectUri = redirectionUriService.validatePostLogoutRedirectUri(authorizationGrant.getClient().getClientId(), postLogoutRedirectUri);
    }
    final Set<String> frontchannelLogoutUris = getRpFrontchannelLogoutUris(pair);
    final String html = constructPage(frontchannelLogoutUris, redirectUri, state);
    log.debug("Constructed http logout page: " + html);
    return Response.ok().cacheControl(ServerUtil.cacheControl(true, true)).header("Pragma", "no-cache").type(MediaType.TEXT_HTML_TYPE).entity(html).build();
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 13 with AuthorizationGrant

use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceImpl method endSession.

private Pair<SessionState, AuthorizationGrant> endSession(String idTokenHint, String sessionState, HttpServletRequest httpRequest, HttpServletResponse httpResponse, SecurityContext sec) {
    AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByIdToken(idTokenHint);
    if (authorizationGrant == null) {
        Boolean endSessionWithAccessToken = appConfiguration.getEndSessionWithAccessToken();
        if ((endSessionWithAccessToken != null) && endSessionWithAccessToken) {
            authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(idTokenHint);
        }
    }
    SessionState ldapSessionState = removeSessionState(sessionState, httpRequest, httpResponse);
    if ((authorizationGrant == null) && (ldapSessionState == null)) {
        log.info("Failed to find out authorization grant for id_token_hint '{}' and session_state '{}'", idTokenHint, sessionState);
        errorResponseFactory.throwUnauthorizedException(EndSessionErrorResponseType.INVALID_GRANT);
    }
    boolean isExternalLogoutPresent;
    boolean externalLogoutResult = false;
    isExternalLogoutPresent = externalApplicationSessionService.isEnabled();
    if (isExternalLogoutPresent && (ldapSessionState != null)) {
        String userName = ldapSessionState.getSessionAttributes().get(Constants.AUTHENTICATED_USER);
        externalLogoutResult = externalApplicationSessionService.executeExternalEndSessionMethods(httpRequest, ldapSessionState);
        log.info("End session result for '{}': '{}'", userName, "logout", externalLogoutResult);
    }
    boolean isGrantAndExternalLogoutSuccessful = isExternalLogoutPresent && externalLogoutResult;
    if (isExternalLogoutPresent && !isGrantAndExternalLogoutSuccessful) {
        errorResponseFactory.throwUnauthorizedException(EndSessionErrorResponseType.INVALID_GRANT);
    }
    if (ldapSessionState != null) {
        grantService.removeAllTokensBySession(ldapSessionState.getDn());
    }
    if (identity != null) {
        identity.logout();
    }
    return new Pair<SessionState, AuthorizationGrant>(ldapSessionState, authorizationGrant);
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) Pair(org.xdi.util.Pair)

Example 14 with AuthorizationGrant

use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceImpl method getRpFrontchannelLogoutUris.

private Set<String> getRpFrontchannelLogoutUris(Pair<SessionState, AuthorizationGrant> pair) {
    final Set<String> result = Sets.newHashSet();
    SessionState sessionState = pair.getFirst();
    AuthorizationGrant authorizationGrant = pair.getSecond();
    if (sessionState == null) {
        log.error("session_state is not passed to endpoint (as cookie or manually). Therefore unable to match clients for session_state." + "Http based html will contain no iframes.");
        return result;
    }
    final Set<Client> clientsByDns = sessionState.getPermissionGrantedMap() != null ? clientService.getClient(sessionState.getPermissionGrantedMap().getClientIds(true), true) : Sets.<Client>newHashSet();
    if (authorizationGrant != null) {
        clientsByDns.add(authorizationGrant.getClient());
    }
    for (Client client : clientsByDns) {
        String[] logoutUris = client.getFrontChannelLogoutUri();
        if (logoutUris == null) {
            continue;
        }
        for (String logoutUri : logoutUris) {
            if (Util.isNullOrEmpty(logoutUri)) {
                // skip client if logout_uri is blank
                continue;
            }
            if (client.getFrontChannelLogoutSessionRequired() != null && client.getFrontChannelLogoutSessionRequired()) {
                if (logoutUri.contains("?")) {
                    logoutUri = logoutUri + "&sid=" + sessionState.getId();
                } else {
                    logoutUri = logoutUri + "?sid=" + sessionState.getId();
                }
            }
            result.add(logoutUri);
        }
    }
    return result;
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) Client(org.xdi.oxauth.model.registration.Client) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 15 with AuthorizationGrant

use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.

the class ResourceSetRegistrationWS method getResourceSetList.

/**
     * Gets resource set lists.
     * ATTENTION: "scope" is parameter added by gluu to have additional filtering.
     * There is no such parameter in UMA specification.
     *
     * @param authorization authorization
     * @param scope         scope of resource set for additional filtering, can blank string.
     * @return resource set ids.
     */
@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Lists all previously registered resource set identifiers for this user using the GET method.", notes = "Lists all previously registered resource set identifiers for this user using the GET method. The authorization server MUST return the list in the form of a JSON array of {rsid} string values.\n" + "\n" + "The resource server uses this method as a first step in checking whether its understanding of protected resources is in full synchronization with the authorization server's understanding.", response = ResourceSet.class)
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized") })
public List<String> getResourceSetList(@HeaderParam("Authorization") String authorization, @QueryParam("scope") @ApiParam(value = "Scope uri", required = false) String scope) {
    try {
        log.trace("Getting list of resource set descriptions.");
        final AuthorizationGrant authorizationGrant = umaValidationService.assertHasProtectionScope(authorization);
        final String clientDn = authorizationGrant.getClientDn();
        final List<org.xdi.oxauth.model.uma.persistence.ResourceSet> ldapResourceSets = resourceSetService.getResourceSetsByAssociatedClient(clientDn);
        final List<String> result = new ArrayList<String>(ldapResourceSets.size());
        for (org.xdi.oxauth.model.uma.persistence.ResourceSet ldapResourceSet : ldapResourceSets) {
            // if scope parameter is not null then filter by it, otherwise just add to result
            if (StringUtils.isNotBlank(scope)) {
                final List<String> scopeUrlsByDns = umaScopeService.getScopeUrlsByDns(ldapResourceSet.getScopes());
                if (scopeUrlsByDns != null && scopeUrlsByDns.contains(scope)) {
                    result.add(ldapResourceSet.getId());
                }
            } else {
                result.add(ldapResourceSet.getId());
            }
        }
        return result;
    } catch (Exception ex) {
        log.error("Exception happened on getResourceSetList()", ex);
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
    }
    errorResponseFactory.throwUmaInternalErrorException();
    // redundant but required by java
    return Lists.newArrayList();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebApplicationException(javax.ws.rs.WebApplicationException) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Aggregations

AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)15 WebApplicationException (javax.ws.rs.WebApplicationException)5 SessionState (org.xdi.oxauth.model.common.SessionState)5 Client (org.xdi.oxauth.model.registration.Client)4 ArrayList (java.util.ArrayList)3 OAuth2AuditLog (org.xdi.oxauth.model.audit.OAuth2AuditLog)3 IOException (java.io.IOException)2 SignatureException (java.security.SignatureException)2 Produces (javax.ws.rs.Produces)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 AccessToken (org.xdi.oxauth.model.common.AccessToken)2 IdToken (org.xdi.oxauth.model.common.IdToken)2 User (org.xdi.oxauth.model.common.User)2 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1