use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.
the class GrantServiceTest method createTestToken.
private TokenEntity createTestToken() {
final String grantId = GrantService.generateGrantId();
final String dn = grantService.buildDn(TokenHashUtil.hash(TEST_TOKEN_CODE));
final TokenEntity t = new TokenEntity();
t.setDn(dn);
t.setGrantId(grantId);
t.setClientId(clientId);
t.setTokenCode(TokenHashUtil.hash(TEST_TOKEN_CODE));
t.setTokenType(TokenType.ACCESS_TOKEN.getValue());
t.setCreationDate(new Date());
t.setExpirationDate(new Date());
return t;
}
use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.
the class AuthorizationGrant method asToken.
public TokenEntity asToken(AccessToken accessToken) {
final TokenEntity result = asTokenEntity(accessToken);
result.setTokenTypeEnum(TokenType.ACCESS_TOKEN);
return result;
}
use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.
the class AuthorizationGrant method asTokenEntity.
public TokenEntity asTokenEntity(AbstractToken token) {
final TokenEntity result = new TokenEntity();
final String hashedCode = TokenHashUtil.hash(token.getCode());
result.setDn(grantService.buildDn(hashedCode));
result.setGrantId(getGrantId());
result.setCreationDate(token.getCreationDate());
result.setExpirationDate(token.getExpirationDate());
result.setTtl(token.getTtl());
result.setTokenCode(hashedCode);
result.setUserId(getUserId());
result.setUserDn(getUserDn());
result.setClientId(getClientId());
result.getAttributes().setX5cs256(token.getX5ts256());
result.setDpop(token.getDpop());
final AuthorizationGrantType grantType = getAuthorizationGrantType();
if (grantType != null) {
result.setGrantType(grantType.getParamName());
}
final AuthorizationCode authorizationCode = getAuthorizationCode();
if (authorizationCode != null) {
result.setAuthorizationCode(TokenHashUtil.hash(authorizationCode.getCode()));
}
initTokenFromGrant(result);
return result;
}
use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.
the class AuthorizationGrant method saveImpl.
private void saveImpl() {
String grantId = getGrantId();
if (StringUtils.isNotBlank(grantId)) {
final List<TokenEntity> grants = grantService.getGrantsByGrantId(grantId);
if (grants != null && !grants.isEmpty()) {
for (TokenEntity t : grants) {
initTokenFromGrant(t);
log.debug("Saving grant: {}, code_challenge: {}", grantId, getCodeChallenge());
grantService.mergeSilently(t);
}
}
}
}
use of io.jans.as.server.model.ldap.TokenEntity in project jans by JanssenProject.
the class AuthorizationGrant method saveRefreshToken.
private RefreshToken saveRefreshToken(RefreshToken refreshToken, ExecutionContext executionContext) {
try {
if (refreshToken.getExpiresIn() > 0) {
final TokenEntity entity = asToken(refreshToken);
executionContext.setRefreshTokenEntity(entity);
boolean externalOk = externalUpdateTokenService.modifyRefreshToken(refreshToken, ExternalUpdateTokenContext.of(executionContext));
if (!externalOk) {
log.trace("External script forbids refresh token creation.");
return null;
}
persist(entity);
statService.reportRefreshToken(getGrantType());
metricService.incCounter(MetricType.TOKEN_REFRESH_TOKEN_COUNT);
if (log.isTraceEnabled()) {
log.trace("Created refresh token: {}", refreshToken.getCode());
}
return refreshToken;
}
log.debug("Token expiration date is in the past. Skip refresh_token creation.");
return null;
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
Aggregations