use of org.entando.entando.aps.system.services.oauth2.model.OAuth2Token in project entando-core by entando.
the class OAuth2TokenDAO method getAccessToken.
@Override
public OAuth2Token getAccessToken(final String accessToken) throws ApsSystemException {
Connection conn = null;
OAuth2Token token = null;
PreparedStatement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
stat = conn.prepareStatement(SELECT_TOKEN);
stat.setString(1, accessToken);
res = stat.executeQuery();
if (res.next()) {
token = new OAuth2Token();
token.setAccessToken(accessToken);
token.setRefreshToken(res.getString("refreshtoken"));
token.setClientId(res.getString("clientid"));
token.setGrantType(res.getString("granttype"));
token.setExpiresIn(res.getTimestamp("expiresin"));
}
} catch (ApsSystemException | SQLException t) {
logger.error("Error while loading token {}", accessToken, t);
throw new ApsSystemException("Error while loading token " + accessToken, t);
} finally {
closeDaoResources(res, stat, conn);
}
return token;
}
use of org.entando.entando.aps.system.services.oauth2.model.OAuth2Token in project entando-core by entando.
the class ApiOAuth2TokenManager method getAccessToken.
protected OAuth2AccessToken getAccessToken(String principal, String clientId, String grantType) {
String tokenPrefix = principal + System.nanoTime();
final String accessToken = DigestUtils.md5Hex(tokenPrefix + "_accessToken");
final String refreshToken = DigestUtils.md5Hex(tokenPrefix + "_refreshToken");
final OAuth2AccessTokenImpl oAuth2Token = new OAuth2AccessTokenImpl(accessToken);
oAuth2Token.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
oAuth2Token.setClientId(clientId);
oAuth2Token.setGrantType(grantType);
oAuth2Token.setLocalUser(principal);
// gets a calendar using the default time zone and locale.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, this.getAccessTokenValiditySeconds());
oAuth2Token.setExpiration(calendar.getTime());
return oAuth2Token;
}
Aggregations