Search in sources :

Example 1 with TokenLdap

use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.

the class AuthorizationGrant method asTokenLdap.

public TokenLdap asTokenLdap(AbstractToken p_token) {
    final String id = GrantService.generateGrantId();
    final TokenLdap result = new TokenLdap();
    result.setDn(grantService.buildDn(id, getGrantId(), getClientId()));
    result.setId(id);
    result.setGrantId(getGrantId());
    result.setCreationDate(p_token.getCreationDate());
    result.setExpirationDate(p_token.getExpirationDate());
    result.setTokenCode(TokenHashUtil.getHashedToken(p_token.getCode()));
    result.setUserId(getUserId());
    result.setClientId(getClientId());
    result.setScope(getScopesAsString());
    result.setAuthMode(p_token.getAuthMode());
    result.setSessionDn(p_token.getSessionDn());
    result.setAuthenticationTime(getAuthenticationTime());
    final AuthorizationGrantType grantType = getAuthorizationGrantType();
    if (grantType != null) {
        result.setGrantType(grantType.getParamName());
    }
    final AuthorizationCode authorizationCode = getAuthorizationCode();
    if (authorizationCode != null) {
        result.setAuthorizationCode(TokenHashUtil.getHashedToken(authorizationCode.getCode()));
    }
    final String nonce = getNonce();
    if (nonce != null) {
        result.setNonce(nonce);
    }
    final JwtAuthorizationRequest jwtRequest = getJwtAuthorizationRequest();
    if (jwtRequest != null && StringUtils.isNotBlank(jwtRequest.getEncodedJwt())) {
        result.setJwtRequest(jwtRequest.getEncodedJwt());
    }
    return result;
}
Also used : JwtAuthorizationRequest(org.xdi.oxauth.model.authorize.JwtAuthorizationRequest) TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap)

Example 2 with TokenLdap

use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.

the class GrantService method auditLogging.

private void auditLogging(Collection<TokenLdap> entries) {
    for (TokenLdap tokenLdap : entries) {
        OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(null, Action.SESSION_DESTROYED);
        oAuth2AuditLog.setSuccess(true);
        oAuth2AuditLog.setClientId(tokenLdap.getClientId());
        oAuth2AuditLog.setScope(tokenLdap.getScope());
        oAuth2AuditLog.setUsername(tokenLdap.getUserId());
        applicationAuditLogger.sendMessage(oAuth2AuditLog);
    }
}
Also used : OAuth2AuditLog(org.xdi.oxauth.model.audit.OAuth2AuditLog) TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap)

Example 3 with TokenLdap

use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.

the class GrantService method cleanUp.

public void cleanUp() {
    // Cleaning oxAuthToken
    BatchOperation<TokenLdap> tokenBatchService = new BatchOperation<TokenLdap>(ldapEntryManager) {

        @Override
        protected List<TokenLdap> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), TokenLdap.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<TokenLdap> entries) {
            auditLogging(entries);
            remove(entries);
        }

        private Filter getFilter() {
            try {
                return Filter.create(String.format("(oxAuthExpiration<=%s)", StaticUtils.encodeGeneralizedTime(new Date())));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthExpiration");
            }
        }
    };
    tokenBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
    // Cleaning oxAuthGrant
    BatchOperation<Grant> grantBatchService = new BatchOperation<Grant>(ldapEntryManager) {

        @Override
        protected List<Grant> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Grant> entries) {
            removeGrants(entries);
        }

        private Filter getFilter() {
            try {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.SECOND, 60);
                return Filter.create(String.format("(&(oxAuthCreation<=%s)(|(numsubordinates=0)(hasSubordinates=FALSE)))", StaticUtils.encodeGeneralizedTime(calendar.getTime())));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthCreation");
            }
        }
    };
    grantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
    // Cleaning old oxAuthGrant
    // Note: This block should be removed, it is used only to delete old legacy data.
    BatchOperation<Grant> oldGrantBatchService = new BatchOperation<Grant>(ldapEntryManager) {

        @Override
        protected List<Grant> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Grant> entries) {
            removeGrants(entries);
        }

        private Filter getFilter() {
            try {
                return Filter.create("(&(!(oxAuthCreation=*))(|(numsubordinates=0)(hasSubordinates=FALSE)))");
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthCreation");
            }
        }
    };
    oldGrantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
}
Also used : Grant(org.xdi.oxauth.model.ldap.Grant) MemcachedGrant(org.xdi.oxauth.model.common.MemcachedGrant) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) LDAPException(com.unboundid.ldap.sdk.LDAPException) Calendar(java.util.Calendar) List(java.util.List) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap) Date(java.util.Date)

Example 4 with TokenLdap

use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.

the class GrantService method removeByCode.

/**
     * Removes grant with particular code.
     *
     * @param p_code code
     */
public void removeByCode(String p_code, String p_clientId) {
    final TokenLdap t = getGrantsByCodeAndClient(p_code, p_clientId);
    if (t != null) {
        removeSilently(t);
    }
    cacheService.remove(null, MemcachedGrant.cacheKey(p_clientId, p_code));
}
Also used : TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap)

Example 5 with TokenLdap

use of org.xdi.oxauth.model.ldap.TokenLdap in project oxAuth by GluuFederation.

the class AuthorizationGrant method asToken.

public TokenLdap asToken(IdToken p_token) {
    final TokenLdap result = asTokenLdap(p_token);
    result.setTokenTypeEnum(org.xdi.oxauth.model.ldap.TokenType.ID_TOKEN);
    return result;
}
Also used : TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap)

Aggregations

TokenLdap (org.xdi.oxauth.model.ldap.TokenLdap)12 Date (java.util.Date)2 JwtAuthorizationRequest (org.xdi.oxauth.model.authorize.JwtAuthorizationRequest)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 SignatureException (java.security.SignatureException)1 Calendar (java.util.Calendar)1 List (java.util.List)1 BatchOperation (org.gluu.site.ldap.persistence.BatchOperation)1 Test (org.testng.annotations.Test)1 BaseComponentTest (org.xdi.oxauth.BaseComponentTest)1 OAuth2AuditLog (org.xdi.oxauth.model.audit.OAuth2AuditLog)1 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)1 MemcachedGrant (org.xdi.oxauth.model.common.MemcachedGrant)1 InvalidJweException (org.xdi.oxauth.model.exception.InvalidJweException)1 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)1 Grant (org.xdi.oxauth.model.ldap.Grant)1