use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project entando-core by entando.
the class OAuth2TokenDAOTest method failReadAuthenticationForRefreshToken.
@Test(expected = RuntimeException.class)
public void failReadAuthenticationForRefreshToken() throws Exception {
OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("value_X2");
try {
when(this.stat.executeQuery()).thenReturn(res);
Mockito.when(res.next()).thenReturn(true).thenReturn(false);
Mockito.when(res.getString("localuser")).thenReturn("username");
Mockito.when(res.getString("clientid")).thenThrow(SQLException.class);
Mockito.when(res.getString("granttype")).thenReturn("password");
OAuth2Authentication auth = this.tokenDAO.readAuthenticationForRefreshToken(refreshToken);
Assert.fail();
} catch (RuntimeException e) {
Mockito.verify(stat, Mockito.times(1)).setString(Mockito.anyInt(), Mockito.anyString());
Mockito.verify(res, Mockito.times(2)).getString(Mockito.anyString());
Mockito.verify(res, Mockito.times(0)).getTimestamp(Mockito.anyString());
Mockito.verify(stat, Mockito.times(1)).close();
Mockito.verify(res, Mockito.times(1)).close();
Mockito.verify(conn, Mockito.times(1)).close();
throw e;
}
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project entando-core by entando.
the class OAuth2TokenDAOTest method readRefreshToken.
@Test
public void readRefreshToken() throws Exception {
when(this.statForSearchId.executeQuery()).thenReturn(resForSearchId);
Mockito.when(resForSearchId.next()).thenReturn(true).thenReturn(false);
Mockito.when(resForSearchId.getString(Mockito.anyString())).thenReturn("refresh_token");
OAuth2RefreshToken refreshToken = this.tokenDAO.readRefreshToken("refresh_token");
Assert.assertNotNull(refreshToken);
Assert.assertEquals("refresh_token", refreshToken.getValue());
Mockito.verify(statForSearchId, Mockito.times(1)).setString(Mockito.anyInt(), Mockito.anyString());
Mockito.verify(resForSearchId, Mockito.times(1)).getString(Mockito.anyString());
this.executeFinalCheckForSearchId(true);
Mockito.verify(conn, Mockito.times(1)).close();
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project entando-core by entando.
the class OAuth2TokenDAOTest method readRefreshToken_noteExists.
@Test
public void readRefreshToken_noteExists() throws Exception {
when(this.statForSearchId.executeQuery()).thenReturn(resForSearchId);
Mockito.when(resForSearchId.next()).thenReturn(false);
OAuth2RefreshToken refreshToken = this.tokenDAO.readRefreshToken("refresh_token");
Assert.assertNull(refreshToken);
Mockito.verify(statForSearchId, Mockito.times(1)).setString(Mockito.anyInt(), Mockito.anyString());
Mockito.verify(resForSearchId, Mockito.times(0)).getString(Mockito.anyString());
this.executeFinalCheckForSearchId(true);
Mockito.verify(conn, Mockito.times(1)).close();
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project entando-core by entando.
the class ApiOAuth2TokenManagerTest method removeAccessTokenUsingRefreshToken.
@Test
public void removeAccessTokenUsingRefreshToken() throws Exception {
OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("value_2");
this.tokenManager.removeAccessTokenUsingRefreshToken(refreshToken);
Mockito.verify(tokenDAO, Mockito.times(1)).removeAccessTokenUsingRefreshToken("value_2");
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project jhipster-registry by jhipster.
the class AuthorizationHeaderUtil method refreshToken.
private String refreshToken(OAuth2AuthorizedClient client, OAuth2AuthenticationToken oauthToken) {
OAuth2AccessTokenResponse atr = refreshTokenClient(client);
if (atr == null || atr.getAccessToken() == null) {
log.info("Failed to refresh token for user");
return null;
}
OAuth2RefreshToken refreshToken = atr.getRefreshToken() != null ? atr.getRefreshToken() : client.getRefreshToken();
OAuth2AuthorizedClient updatedClient = new OAuth2AuthorizedClient(client.getClientRegistration(), client.getPrincipalName(), atr.getAccessToken(), refreshToken);
clientService.saveAuthorizedClient(updatedClient, oauthToken);
return atr.getAccessToken().getTokenValue();
}
Aggregations