Search in sources :

Example 6 with LockedException

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());
}
Also used : LockedException(org.orcid.core.security.aop.LockedException) Test(org.junit.Test)

Example 7 with LockedException

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;
}
Also used : InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) LockedException(org.orcid.core.security.aop.LockedException) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication)

Example 8 with LockedException

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());
}
Also used : OAuthError(org.orcid.core.oauth.OAuthError) LockedException(org.orcid.core.security.aop.LockedException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

LockedException (org.orcid.core.security.aop.LockedException)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 HashMap (java.util.HashMap)3 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)3 InvalidScopeException (org.springframework.security.oauth2.common.exceptions.InvalidScopeException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 Test (org.junit.Test)2 OrcidDeprecatedException (org.orcid.core.exception.OrcidDeprecatedException)2 OrcidNotClaimedException (org.orcid.core.exception.OrcidNotClaimedException)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1