use of org.orcid.core.security.aop.LockedException in project ORCID-Source by ORCID.
the class OAuthErrorUtilsTest method testGetOAuthErrorForLockedException.
@Test
public void testGetOAuthErrorForLockedException() {
OAuthError error = OAuthErrorUtils.getOAuthError(new LockedException("message here"));
assertEquals(OAuthError.UNAUTHORIZED_CLIENT, error.getError());
assertEquals(Status.BAD_REQUEST, error.getResponseStatus());
assertEquals("message here", error.getErrorDescription());
}
use of org.orcid.core.security.aop.LockedException in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesImpl method loadAuthentication.
@Override
public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException {
OAuth2AccessToken accessToken = orcidTokenStore.readAccessToken(accessTokenValue);
if (accessToken == null) {
throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
} else {
// If it is, respect the token expiration
if (accessToken.isExpired()) {
orcidTokenStore.removeAccessToken(accessToken);
throw new InvalidTokenException("Access token expired: " + accessTokenValue);
}
Map<String, Object> additionalInfo = accessToken.getAdditionalInformation();
if (additionalInfo != null) {
String clientId = (String) additionalInfo.get(OrcidOauth2Constants.CLIENT_ID);
ClientDetailsEntity clientEntity = clientDetailsEntityCacheManager.retrieve(clientId);
try {
orcidOAuth2RequestValidator.validateClientIsEnabled(clientEntity);
} catch (LockedException le) {
throw new InvalidTokenException(le.getMessage());
}
}
}
OAuth2Authentication result = orcidTokenStore.readAuthentication(accessToken);
return result;
}
use of org.orcid.core.security.aop.LockedException in project ORCID-Source by ORCID.
the class OauthGenericCallsControllerTest method testObtainOauth2TokenPostLockedClient.
@Test
public void testObtainOauth2TokenPostLockedClient() {
when(orcidClientCredentialEndPointDelegator.obtainOauth2Token(isNull(), any())).thenThrow(new LockedException("Client is locked"));
ResponseEntity<?> responseEntity = controller.obtainOauth2TokenPost(new MockHttpServletRequest());
assertNotNull(responseEntity);
assertNotNull(responseEntity.getBody());
assertTrue(responseEntity.getBody() instanceof OAuthError);
OAuthError error = (OAuthError) responseEntity.getBody();
assertEquals(OAuthError.UNAUTHORIZED_CLIENT, error.getError());
assertEquals("Client is locked", error.getErrorDescription());
}
Aggregations