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.");
}
}
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);
}
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"));
}
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;
}
Aggregations