Search in sources :

Example 1 with TokenEntity

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;
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity) Date(java.util.Date)

Example 2 with TokenEntity

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;
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 3 with TokenEntity

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;
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 4 with TokenEntity

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);
            }
        }
    }
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

Example 5 with TokenEntity

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;
    }
}
Also used : TokenEntity(io.jans.as.server.model.ldap.TokenEntity)

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