Search in sources :

Example 11 with OAuth2AccessTokenImpl

use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.

the class OAuth2TokenDAO method getAccessToken.

protected OAuth2AccessToken getAccessToken(final String token, Connection conn) {
    OAuth2AccessTokenImpl accessToken = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
        stat = conn.prepareStatement(SELECT_TOKEN);
        stat.setString(1, token);
        res = stat.executeQuery();
        if (res.next()) {
            accessToken = new OAuth2AccessTokenImpl(token);
            accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(res.getString("refreshtoken")));
            accessToken.setClientId(res.getString("clientid"));
            accessToken.setGrantType(res.getString("granttype"));
            accessToken.setLocalUser(res.getString("localuser"));
            Timestamp timestamp = res.getTimestamp("expiresin");
            Date expiration = new Date(timestamp.getTime());
            accessToken.setExpiration(expiration);
        }
    } catch (Throwable t) {
        logger.error("Error loading token {}", token, t);
        throw new RuntimeException("Error loading token " + token, t);
    } finally {
        closeDaoResources(res, stat);
    }
    return accessToken;
}
Also used : DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) OAuth2AccessTokenImpl(org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl)

Aggregations

OAuth2AccessTokenImpl (org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl)11 DefaultOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken)6 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 Test (org.junit.Test)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)1 Role (com.agiletec.aps.system.services.role.Role)1 IUserManager (com.agiletec.aps.system.services.user.IUserManager)1 IApiOAuth2TokenManager (org.entando.entando.aps.system.services.oauth2.IApiOAuth2TokenManager)1 EntandoTokenException (org.entando.entando.web.common.exceptions.EntandoTokenException)1 EntandoBearerTokenExtractor (org.entando.entando.web.common.interceptor.EntandoBearerTokenExtractor)1 Authentication (org.springframework.security.core.Authentication)1