Search in sources :

Example 11 with TokenEntity

use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.

the class AuthorizationGrant method asToken.

public TokenEntity asToken(RefreshToken token) {
    final TokenEntity result = asTokenEntity(token);
    result.setTokenTypeEnum(TokenType.REFRESH_TOKEN);
    return result;
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 12 with TokenEntity

use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.

the class GrantService method logout.

public void logout(String sessionDn) {
    final List<TokenEntity> tokens = getGrantsBySessionDn(sessionDn);
    if (BooleanUtils.isFalse(appConfiguration.getRemoveRefreshTokensForClientOnLogout())) {
        List<TokenEntity> refreshTokens = Lists.newArrayList();
        for (TokenEntity token : tokens) {
            if (token.getTokenTypeEnum() == TokenType.REFRESH_TOKEN) {
                refreshTokens.add(token);
            }
        }
        if (!refreshTokens.isEmpty()) {
            log.trace("Refresh tokens are not removed on logout (because removeRefreshTokensForClientOnLogout configuration property is false)");
            tokens.removeAll(refreshTokens);
        }
    }
    removeSilently(tokens);
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 13 with TokenEntity

use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.

the class GrantService method removeByCode.

/**
 * Removes grant with particular code.
 *
 * @param code code
 */
public void removeByCode(String code) {
    final TokenEntity t = getGrantByCode(code);
    if (t != null) {
        removeSilently(t);
    }
    cacheService.remove(CacheGrant.cacheKey(code, null));
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 14 with TokenEntity

use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.

the class CleanerTimerTest method token_whichIsExpiredAndDeletable_MustBeRemoved.

@Test
public void token_whichIsExpiredAndDeletable_MustBeRemoved() throws StringEncrypter.EncryptionException {
    final Client client = createClient();
    clientService.persist(client);
    // 1. create token
    final ClientCredentialsGrant grant = authorizationGrantList.createClientCredentialsGrant(new User(), client);
    final AccessToken accessToken = grant.createAccessToken(new ExecutionContext(null, null));
    // 2. token exists
    assertNotNull(grantService.getGrantByCode(accessToken.getCode()));
    // 3. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 4. token exists
    final TokenEntity grantLdap = grantService.getGrantByCode(accessToken.getCode());
    assertNotNull(grantLdap);
    final Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MINUTE, -10);
    grantLdap.setExpirationDate(calendar.getTime());
    grantService.merge(grantLdap);
    // 5. clean up
    cleanerTimer.processImpl();
    cacheService.clear();
    // 6. no token in persistence
    assertNull(grantService.getGrantByCode(accessToken.getCode()));
}
Also used : User(io.jans.as.common.model.common.User) ExecutionContext(io.jans.as.server.model.common.ExecutionContext) AccessToken(io.jans.as.server.model.common.AccessToken) ClientCredentialsGrant(io.jans.as.server.model.common.ClientCredentialsGrant) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) TokenEntity(io.jans.as.server.model.ldap.TokenEntity) Client(io.jans.as.common.model.registration.Client) Test(org.testng.annotations.Test) BaseComponentTest(io.jans.as.server.BaseComponentTest)

Aggregations

TokenEntity (io.jans.as.server.model.ldap.TokenEntity)14 User (io.jans.as.common.model.common.User)1 Client (io.jans.as.common.model.registration.Client)1 GrantType (io.jans.as.model.common.GrantType)1 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)1 JSONWebKey (io.jans.as.model.jwk.JSONWebKey)1 Jwt (io.jans.as.model.jwt.Jwt)1 BaseComponentTest (io.jans.as.server.BaseComponentTest)1 AccessToken (io.jans.as.server.model.common.AccessToken)1 AuthorizationCodeGrant (io.jans.as.server.model.common.AuthorizationCodeGrant)1 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)1 ClientCredentialsGrant (io.jans.as.server.model.common.ClientCredentialsGrant)1 ExecutionContext (io.jans.as.server.model.common.ExecutionContext)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ServletException (javax.servlet.ServletException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.testng.annotations.Test)1