use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.
the class OAuth2TokenDAOTest method createMockAccessToken.
private OAuth2AccessToken createMockAccessToken() {
OAuth2AccessTokenImpl token = new OAuth2AccessTokenImpl("token");
token.setValue("token");
token.setClientId("client_id");
token.setExpiration(new Date());
token.setGrantType("password");
token.setLocalUser("username");
token.setRefreshToken(new DefaultOAuth2RefreshToken("refresh"));
token.setTokenType("bearer");
return token;
}
use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.
the class ApiOAuth2TokenManagerTest method createAccessTokenForLocalUser.
@Test
public void createAccessTokenForLocalUser() {
OAuth2AccessToken token = this.tokenManager.createAccessTokenForLocalUser("username");
Assert.assertNotNull(token);
Mockito.verify(tokenDAO, Mockito.times(1)).storeAccessToken(Mockito.any(OAuth2AccessToken.class), Mockito.eq(null));
Assert.assertTrue(token instanceof OAuth2AccessTokenImpl);
Assert.assertEquals("LOCAL_USER", ((OAuth2AccessTokenImpl) token).getClientId());
}
use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.
the class ApiOAuth2TokenManagerTest method getAccessToken.
@Test
public void getAccessToken() throws Exception {
OAuth2AccessToken token = tokenManager.getAccessToken(this.createMockAuthentication());
Assert.assertNotNull(token);
Assert.assertTrue(token instanceof OAuth2AccessTokenImpl);
Assert.assertEquals("clientId", ((OAuth2AccessTokenImpl) token).getClientId());
Assert.assertEquals("username", ((OAuth2AccessTokenImpl) token).getLocalUser());
}
use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.
the class EntandoOauth2Interceptor method extractOAuthParameters.
protected UserDetails extractOAuthParameters(HttpServletRequest request) {
try {
// Clear previous session
request.getSession().setAttribute("user", null);
String accessToken = new EntandoBearerTokenExtractor().extractToken(request);
if (StringUtils.isBlank(accessToken)) {
return null;
}
final OAuth2AccessToken token = this.getoAuth2TokenManager().readAccessToken(accessToken);
this.validateToken(request, accessToken, token);
String username;
if (token instanceof OAuth2AccessTokenImpl) {
username = ((OAuth2AccessTokenImpl) token).getLocalUser();
} else {
Authentication auth = new EntandoBearerTokenExtractor().extract(request);
username = auth.getPrincipal().toString();
}
UserDetails user = this.getAuthenticationProviderManager().getUser(username);
if (user == null) {
logger.warn("User {} not found ", username);
return null;
}
request.getSession().setAttribute("user", user);
request.getSession().setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);
return user;
} catch (ApsSystemException ex) {
logger.error("System exception {}", ex.getMessage());
throw new EntandoTokenException("error parsing OAuth parameters", request, "guest");
}
}
use of org.entando.entando.aps.system.services.oauth2.model.OAuth2AccessTokenImpl in project entando-core by entando.
the class OAuth2TestUtils method getOAuth2Token.
public static OAuth2AccessToken getOAuth2Token(String username, String accessToken) {
OAuth2AccessTokenImpl oAuth2Token = new OAuth2AccessTokenImpl(accessToken);
oAuth2Token.setRefreshToken(new DefaultOAuth2RefreshToken("refresh_token"));
oAuth2Token.setLocalUser(username);
// gets a calendar using the default time zone and locale.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 3600);
oAuth2Token.setExpiration(calendar.getTime());
oAuth2Token.setGrantType("password");
return oAuth2Token;
}
Aggregations