Search in sources :

Example 1 with OAuth2TokenValidationRequestDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO in project airavata by apache.

the class DefaultOAuthClient method validateAccessToken.

/**
 * Validates the OAuth 2.0 access token
 *
 * @param accessToken
 * @return
 * @throws Exception
 */
public OAuth2TokenValidationResponseDTO validateAccessToken(String accessToken) throws AiravataSecurityException {
    try {
        OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
        OAuth2TokenValidationRequestDTO_OAuth2AccessToken token = new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
        token.setIdentifier(accessToken);
        token.setTokenType(BEARER_TOKEN_TYPE);
        oauthReq.setAccessToken(token);
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        logger.error(e.getMessage(), e);
        throw new AiravataSecurityException("Error in validating the OAuth access token.");
    }
}
Also used : OAuth2TokenValidationRequestDTO_OAuth2AccessToken(org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken) RemoteException(java.rmi.RemoteException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException) OAuth2TokenValidationRequestDTO(org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO)

Example 2 with OAuth2TokenValidationRequestDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO in project carbon-apimgt by wso2.

the class SystemScopeIssuerImplTest method init.

@Before
public void init() throws IdentityOAuth2Exception {
    systemScopesIssuer = Mockito.mock(SystemScopesIssuer.class);
    oAuth2AuthorizeReqDTO = new OAuth2AuthorizeReqDTO();
    String[] scopes = { "test", "test1" };
    restAPIScopes.put("test", "test");
    authenticatedUser = Mockito.mock(AuthenticatedUser.class);
    Mockito.when(systemScopesIssuer.getAppScopes(Mockito.anyString(), Mockito.anyObject(), Mockito.anyList())).thenReturn(restAPIScopes);
    Mockito.when(systemScopesIssuer.validateScope((OAuthAuthzReqMessageContext) Mockito.anyObject())).thenReturn(true);
    oAuth2AuthorizeReqDTO.setScopes(scopes);
    oAuth2AuthorizeReqDTO.setUser(authenticatedUser);
    oAuthAuthzReqMessageContext = new OAuthAuthzReqMessageContext(oAuth2AuthorizeReqDTO);
    oAuth2AccessTokenReqDTO = new OAuth2AccessTokenReqDTO();
    oAuth2AccessTokenReqDTO.setScope(scopes);
    oAuthTokenReqMessageContext = new OAuthTokenReqMessageContext(oAuth2AccessTokenReqDTO);
    Mockito.when(systemScopesIssuer.validateScope((OAuthTokenReqMessageContext) Mockito.anyObject())).thenReturn(true);
    oAuth2TokenValidationRequestDTO = new OAuth2TokenValidationRequestDTO();
    oAuth2TokenValidationResponseDTO = new OAuth2TokenValidationResponseDTO();
    oAuth2TokenValidationMessageContext = new OAuth2TokenValidationMessageContext(oAuth2TokenValidationRequestDTO, oAuth2TokenValidationResponseDTO);
    Mockito.when(systemScopesIssuer.validateScope((OAuth2TokenValidationMessageContext) Mockito.anyObject())).thenReturn(true);
}
Also used : OAuth2TokenValidationMessageContext(org.wso2.carbon.identity.oauth2.validators.OAuth2TokenValidationMessageContext) OAuthTokenReqMessageContext(org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext) OAuthAuthzReqMessageContext(org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext) OAuth2AuthorizeReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) OAuth2AccessTokenReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO) OAuth2TokenValidationRequestDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO) OAuth2TokenValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO) Before(org.junit.Before)

Example 3 with OAuth2TokenValidationRequestDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO in project carbon-apimgt by wso2.

the class APIKeyMgtUtilTestCase method testConstructParameterMap.

@Test
public void testConstructParameterMap() throws Exception {
    OAuth2TokenValidationRequestDTO.TokenValidationContextParam param1 = new OAuth2TokenValidationRequestDTO().new TokenValidationContextParam();
    param1.setKey("Key1");
    param1.setValue("Value1");
    OAuth2TokenValidationRequestDTO.TokenValidationContextParam param2 = new OAuth2TokenValidationRequestDTO().new TokenValidationContextParam();
    param2.setKey("Key2");
    param2.setValue("Value2");
    OAuth2TokenValidationRequestDTO.TokenValidationContextParam[] params = { param1, param2 };
    Map<String, String> paramMap = APIKeyMgtUtil.constructParameterMap(params);
    Assert.assertEquals(2, paramMap.size());
    Assert.assertEquals("Value1", paramMap.get("Key1"));
    Assert.assertEquals("Value2", paramMap.get("Key2"));
}
Also used : OAuth2TokenValidationRequestDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO) Test(org.junit.Test)

Example 4 with OAuth2TokenValidationRequestDTO

use of org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO in project carbon-apimgt by wso2.

the class OAuthOpaqueAuthenticatorImpl method getTokenMetaData.

@MethodStats
public OAuthTokenInfo getTokenMetaData(String accessToken) throws APIManagementException {
    OAuthTokenInfo tokenInfo = new OAuthTokenInfo();
    OAuth2TokenValidationRequestDTO requestDTO = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO.OAuth2AccessToken token = requestDTO.new OAuth2AccessToken();
    token.setIdentifier(accessToken);
    token.setTokenType("bearer");
    requestDTO.setAccessToken(token);
    OAuth2TokenValidationRequestDTO.TokenValidationContextParam[] contextParams = new OAuth2TokenValidationRequestDTO.TokenValidationContextParam[1];
    requestDTO.setContext(contextParams);
    OAuth2ClientApplicationDTO clientApplicationDTO = findOAuthConsumerIfTokenIsValid(requestDTO);
    OAuth2TokenValidationResponseDTO responseDTO = clientApplicationDTO.getAccessTokenValidationResponse();
    if (!responseDTO.isValid()) {
        tokenInfo.setTokenValid(responseDTO.isValid());
        log.error("Invalid OAuth Token : " + responseDTO.getErrorMsg());
        return tokenInfo;
    }
    tokenInfo.setTokenValid(responseDTO.isValid());
    tokenInfo.setEndUserName(responseDTO.getAuthorizedUser());
    tokenInfo.setConsumerKey(clientApplicationDTO.getConsumerKey());
    // Convert Expiry Time to milliseconds.
    if (responseDTO.getExpiryTime() == Long.MAX_VALUE) {
        tokenInfo.setValidityPeriod(Long.MAX_VALUE);
    } else {
        tokenInfo.setValidityPeriod(responseDTO.getExpiryTime() * 1000L);
    }
    tokenInfo.setIssuedTime(System.currentTimeMillis());
    tokenInfo.setScopes(responseDTO.getScope());
    return tokenInfo;
}
Also used : OAuth2ClientApplicationDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2ClientApplicationDTO) OAuthTokenInfo(org.wso2.carbon.apimgt.api.OAuthTokenInfo) OAuth2TokenValidationRequestDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO) OAuth2TokenValidationResponseDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO) MethodStats(org.wso2.carbon.apimgt.rest.api.util.MethodStats)

Aggregations

OAuth2TokenValidationRequestDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO)3 OAuth2TokenValidationResponseDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO)2 RemoteException (java.rmi.RemoteException)1 AiravataSecurityException (org.apache.airavata.security.AiravataSecurityException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 OAuthTokenInfo (org.wso2.carbon.apimgt.api.OAuthTokenInfo)1 MethodStats (org.wso2.carbon.apimgt.rest.api.util.MethodStats)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 OAuthAuthzReqMessageContext (org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext)1 OAuth2AccessTokenReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO)1 OAuth2AuthorizeReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO)1 OAuth2ClientApplicationDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2ClientApplicationDTO)1 OAuth2TokenValidationRequestDTO (org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO)1 OAuth2TokenValidationRequestDTO_OAuth2AccessToken (org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken)1 OAuthTokenReqMessageContext (org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext)1 OAuth2TokenValidationMessageContext (org.wso2.carbon.identity.oauth2.validators.OAuth2TokenValidationMessageContext)1