org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO Java Examples

The following examples show how to use org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuth2TokenValidationServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the OAuth 2.0 request
 *
 * @param accessTokenIdentifier The accessToken from the authorization header
 * @return OAuth2TokenValidationResponseDTO
 * @throws Exception
 */
public OAuth2TokenValidationResponseDTO validateAuthenticationRequest(String accessTokenIdentifier,
                                                                      List<OAuth2TokenValidationRequestDTO_TokenValidationContextParam> params) throws Exception {

    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
            new org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    accessToken.setTokenType(OAuthConstants.BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(accessTokenIdentifier);
    oauthReq.setAccessToken(accessToken);
    oauthReq.setContext(params.toArray(new OAuth2TokenValidationRequestDTO_TokenValidationContextParam[params.size()]));
    try {
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        throw new Exception("Error while validating OAuth2 request", e);
    }
}
 
Example #2
Source File: RemoteOAuthValidator.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
private OAuth2TokenValidationRequestDTO createValidationRequest(String accessToken, String resource) {
    OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken oauthToken =
            new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();

    oauthToken.setTokenType("bearer");
    oauthToken.setIdentifier(accessToken);
    validationRequest.setAccessToken(oauthToken);

    OAuth2TokenValidationRequestDTO_TokenValidationContextParam resourceContextParam =
            new OAuth2TokenValidationRequestDTO_TokenValidationContextParam();

    resourceContextParam.setKey("resource");
    resourceContextParam.setValue(resource);

    OAuth2TokenValidationRequestDTO_TokenValidationContextParam[] tokenValidationContextParams =
            new OAuth2TokenValidationRequestDTO_TokenValidationContextParam[1];

    tokenValidationContextParams[0] = resourceContextParam;
    validationRequest.setContext(tokenValidationContextParams);

    return validationRequest;
}
 
Example #3
Source File: OAuthServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the OAuth 2.0 request
 *
 * @param accessTokenIdentifier
 * @return
 * @throws Exception
 */
public OAuth2TokenValidationResponseDTO validateAccessToken(String accessTokenIdentifier)
        throws Exception {
    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
            new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    accessToken.setTokenType(BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(accessTokenIdentifier);
    oauthReq.setAccessToken(accessToken);
    try {
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        log.error("Error while validating OAuth2 request");
        throw new Exception("Error while validating OAuth2 request", e);
    }
}
 
Example #4
Source File: OAuthServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param accessTokenIdentifier
 * @return
 * @throws Exception
 */
public OAuth2ClientApplicationDTO findOAuthConsumerIfTokenIsValid(String accessTokenIdentifier)
        throws Exception {
    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
            new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    accessToken.setTokenType(BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(accessTokenIdentifier);
    oauthReq.setAccessToken(accessToken);
    try {
        return stub.findOAuthConsumerIfTokenIsValid(oauthReq);
    } catch (RemoteException e) {
        log.error("Error while validating OAuth2 request");
        throw new Exception("Error while validating OAuth2 request", e);
    }
}
 
Example #5
Source File: ExternalOAuthValidator.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets a string accessToken and validates it and generate the OAuth2ClientApplicationDTO
 * containing the validity and user details if valid.
 *
 * @param token which need to be validated.
 * @return OAuthValidationResponse with the validated results.
 */
public OAuthValidationResponse validateToken(String token) throws RemoteException {
    OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken =
            new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    accessToken.setTokenType(OauthAuthenticatorConstants.BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(token);
    validationRequest.setAccessToken(accessToken);
    OAuth2TokenValidationServiceStub tokenValidationService =
            new OAuth2TokenValidationServiceStub(hostURL);
    ServiceClient client = tokenValidationService._getServiceClient();
    Options options = client.getOptions();
    List<Header> headerList = new ArrayList<>();
    Header header = new Header();
    header.setName(HTTPConstants.HEADER_AUTHORIZATION);
    header.setValue(OauthAuthenticatorConstants.AUTHORIZATION_HEADER_PREFIX_BASIC + " " + getBasicAuthCredentials());
    headerList.add(header);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, headerList);
    client.setOptions(options);
    OAuth2TokenValidationResponseDTO tokenValidationResponse = tokenValidationService.
            findOAuthConsumerIfTokenIsValid(validationRequest).getAccessTokenValidationResponse();
    boolean isValid = tokenValidationResponse.getValid();
    String userName = null;
    String tenantDomain = null;
    if (isValid) {
        userName = MultitenantUtils.getTenantAwareUsername(
                tokenValidationResponse.getAuthorizedUser());
        tenantDomain = MultitenantUtils.
                getTenantDomain(tokenValidationResponse.getAuthorizedUser());
    }
    return new OAuthValidationResponse(userName,tenantDomain,isValid);
}
 
Example #6
Source File: ValidationServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public OAuth2TokenValidationResponseDTO validateAuthenticationRequest(String accessToken) throws Exception {
    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken oAuth2AccessToken
            = new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    oAuth2AccessToken.setIdentifier(accessToken);
    oAuth2AccessToken.setTokenType(OAuthConstants.BEARER_TOKEN_TYPE);
    oauthReq.setAccessToken(oAuth2AccessToken);
    try {
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        log.error("Error while validating OAuth2 request");
        throw new Exception("Error while validating OAuth2 request", e);
    }
}
 
Example #7
Source File: ValidationServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public OAuth2TokenValidationResponseDTO validateAuthenticationRequest(String accessToken) throws Exception {
    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO_OAuth2AccessToken oAuth2AccessToken
            = new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
    oAuth2AccessToken.setIdentifier(accessToken);
    oAuth2AccessToken.setTokenType(OAuthConstants.BEARER_TOKEN_TYPE);
    oauthReq.setAccessToken(oAuth2AccessToken);
    try {
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        log.error("Error while validating OAuth2 request");
        throw new Exception("Error while validating OAuth2 request", e);
    }
}
 
Example #8
Source File: ValidationServiceClient.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
public OAuth2TokenValidationResponseDTO validateAuthenticationRequest(String accessToken) throws Exception {
    OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();
    oauthReq.setAccessToken(accessToken);
    oauthReq.setTokenType(OAuthConstants.BEARER_TOKEN_TYPE);
    try {
        return stub.validate(oauthReq);
    } catch (RemoteException e) {
        log.error("Error while validating OAuth2 request");
        throw new Exception("Error while validating OAuth2 request", e);
    }
}