Search in sources :

Example 16 with ExecutionContext

use of io.jans.as.server.model.common.ExecutionContext 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

ExecutionContext (io.jans.as.server.model.common.ExecutionContext)16 Client (io.jans.as.common.model.registration.Client)8 JSONObject (org.json.JSONObject)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)5 Response (javax.ws.rs.core.Response)5 JSONException (org.json.JSONException)4 Test (org.testng.annotations.Test)4 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)3 AccessToken (io.jans.as.server.model.common.AccessToken)3 RegisterRequest (io.jans.as.client.RegisterRequest)2 User (io.jans.as.common.model.common.User)2 GrantType (io.jans.as.model.common.GrantType)2 Jwt (io.jans.as.model.jwt.Jwt)2 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)2 ClientCredentialsGrant (io.jans.as.server.model.common.ClientCredentialsGrant)2 SessionId (io.jans.as.server.model.common.SessionId)2 SessionClient (io.jans.as.server.model.session.SessionClient)2 ExternalUpdateTokenContext (io.jans.as.server.service.external.context.ExternalUpdateTokenContext)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2