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;
}
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);
}
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));
}
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()));
}
Aggregations