Package org.apache.amber.oauth2.client.response

Examples of org.apache.amber.oauth2.client.response.OAuthAuthzResponse


    @Consumes("application/json")
    @Produces("application/json")
    public Response register(@Context HttpServletRequest request) throws OAuthSystemException {


        OAuthServerRegistrationRequest oauthRequest = null;
        try {
            oauthRequest = new OAuthServerRegistrationRequest(new JSONHttpServletRequestWrapper(request));
            oauthRequest.discover();
            oauthRequest.getClientName();
            oauthRequest.getClientUrl();
            oauthRequest.getClientDescription();
            oauthRequest.getRedirectURI();

            OAuthResponse response = OAuthServerRegistrationResponse
                .status(HttpServletResponse.SC_OK)
                .setClientId(CommonExt.CLIENT_ID)
                .setClientSecret(CommonExt.CLIENT_SECRET)
View Full Code Here


    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.HEADER);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Validate the access token
            if (!Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the OAuth error message
View Full Code Here

    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.QUERY);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Validate the access token
            if (!Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the OAuth error message
View Full Code Here

    public Response get(@Context HttpServletRequest request) throws OAuthSystemException {

        try {

            // Make the OAuth Request out of this request and validate it
            OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request,
                ParameterStyle.BODY);

            // Get the access token
            String accessToken = oauthRequest.getAccessToken();

            // Check if the token is valid
            if (Common.ACCESS_TOKEN_VALID.equals(accessToken)) {

                // Return the resource
View Full Code Here

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        OAuthAuthzResponse r = null;
        try {
            r = OAuthAuthzResponse.oauthTokenAuthzResponse(request);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        String token = r.getAccessToken();
        Assert.assertNotNull(token);

        verify(request);

        reset(request);

        //both parameters code and access token
        TestUtils.expectNoErrorParameters(request);
        parameters.put(OAuth.OAUTH_CODE, new String[] {"code"});
        parameters.put(OAuth.OAUTH_ACCESS_TOKEN, null);
        parameters.put(OAuth.OAUTH_SCOPE, null);
        parameters.put(OAuth.OAUTH_EXPIRES_IN, null);

        expect(request.getParameterMap()).andReturn(parameters);

        replay(request);

        r = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        token = r.getAccessToken();
        Assert.assertNull(token);
        verify(request);

        reset(request);
View Full Code Here

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        OAuthAuthzResponse r = null;
        try {
            OAuthAuthzResponse.oauthCodeAuthzResponse(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertTrue(
                e.getError().equals(OAuthError.TokenResponse.INVALID_REQUEST));
        }

        verify(request);

        reset(request);

        TestUtils.expectNoErrorParameters(request);
        parameters.put(OAuth.OAUTH_CODE, null);
        parameters.put(OAuth.OAUTH_ACCESS_TOKEN, new String[] {"token"});
        parameters.put(OAuth.OAUTH_SCOPE, new String[] {"test_scope"});
        parameters.put(OAuth.OAUTH_EXPIRES_IN, new String[] {"3600"});

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        try {
            r = OAuthAuthzResponse.oauthTokenAuthzResponse(request);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }

        Assert.assertNotNull(r.getExpiresIn());
        verify(request);
    }
View Full Code Here

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        OAuthAuthzResponse r = null;
        try {
            OAuthAuthzResponse.oauthCodeAuthzResponse(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertTrue(
                e.getError().equals(OAuthError.TokenResponse.INVALID_REQUEST));

        }

        verify(request);

        reset(request);
        TestUtils.expectNoErrorParameters(request);

        parameters.put(OAuth.OAUTH_CODE, null);
        parameters.put(OAuth.OAUTH_ACCESS_TOKEN, new String[] {"token"});
        parameters.put(OAuth.OAUTH_SCOPE, new String[] {"test_scope"});
        parameters.put(OAuth.OAUTH_EXPIRES_IN, new String[] {"3600"});

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        try {
            r = OAuthAuthzResponse.oauthTokenAuthzResponse(request);
        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }
        Assert.assertNotNull(r.getScope());
        verify(request);

    }
View Full Code Here

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        OAuthAuthzResponse r = OAuthAuthzResponse.oauthTokenAuthzResponse(request);
        String code = r.getCode();
        Assert.assertNull(code);

        verify(request);

        reset(request);

        //both parameters code and access token
        TestUtils.expectNoErrorParameters(request);

        parameters.put(OAuth.OAUTH_CODE, new String[] {"code"});
        parameters.put(OAuth.OAUTH_ACCESS_TOKEN, null);
        parameters.put(OAuth.OAUTH_SCOPE, new String[] {null});
        parameters.put(OAuth.OAUTH_EXPIRES_IN, new String[] {null});

        expect(request.getParameterMap()).andStubReturn(parameters);
        replay(request);

        r = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        code = r.getCode();
        Assert.assertNotNull(code);
        verify(request);

        reset(request);
View Full Code Here

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        OAuthAuthzResponse r = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        String state = r.getState();
        Assert.assertNotNull(state);

        verify(request);

        reset(request);
        //check valid request
        TestUtils.expectNoErrorParameters(request);

        parameters.put(OAuth.OAUTH_CODE, new String[] {null});
        parameters.put(OAuth.OAUTH_ACCESS_TOKEN, new String[] {"test_access_token"});
        parameters.put(OAuth.OAUTH_SCOPE, new String[] {null});
        parameters.put(OAuth.OAUTH_STATE, new String[] {"test_state"});
        parameters.put(OAuth.OAUTH_EXPIRES_IN, new String[] {null});

        expect(request.getParameterMap()).andStubReturn(parameters);

        replay(request);

        r = OAuthAuthzResponse.oauthTokenAuthzResponse(request);
        state = r.getState();
        Assert.assertNotNull(state);

        verify(request);
    }
View Full Code Here

    return OAuth.OAUTH_BEARER_TOKEN;
  }
 
  private static String getCode(final HttpServletRequest request) {
   
    OAuthAuthzResponse oar;

    try {

      logger.log(Level.INFO, "Trying to get authorization code from request {0}", request);
     
      oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
     
      String code = oar.getCode();
     
      logger.log(Level.INFO, "Got code {0} from authorization request", code);
     
      return oar.getCode();

    } catch (OAuthProblemException e) {

      logger.log(Level.SEVERE, "Could not read authorization request: {0}, {1}", new Object[] { e.getError(), e.getDescription() });
View Full Code Here

TOP

Related Classes of org.apache.amber.oauth2.client.response.OAuthAuthzResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.