Package org.apache.amber.oauth2.as.request

Examples of org.apache.amber.oauth2.as.request.OAuthTokenRequest


        expect(request.getParameter("param")).andStubReturn("someparam");
        replay(request);

        OAuthRequest req = null;
        try {
            req = new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);
        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
        expect(request.getParameter("param")).andStubReturn("someparam");
        replay(request);

        try {
            req = new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here


        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn("authorization_code");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
        verify(request);

        reset(request);
        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.PASSWORD.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);
        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
        verify(request);
        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(null);
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
        verify(request);
        reset(request);

        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn("authorization_code");

        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.PASSWORD.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(null);
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.PASSWORD.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username");
        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("");
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.PASSWORD.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username");
        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("");
        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token");
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }

        verify(request);

        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null);
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            new OAuthTokenRequest(request);
            fail("Exception expected");
        } catch (OAuthProblemException e) {
            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("test_secret");
        replay(request);

        OAuthTokenRequest req = null;
        try {
            req = new OAuthTokenRequest(request);

        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }
        Assert.assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType());
        Assert.assertEquals("test_client", req.getClientId());
        Assert.assertEquals("http://example.com/callback", req.getRedirectURI());
        Assert.assertEquals("test_code", req.getCode());

        verify(request);
        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.PASSWORD.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("username_test");
        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
        replay(request);

        try {
            req = new OAuthTokenRequest(request);

        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }
        Assert.assertEquals("client_id", req.getClientId());
        Assert.assertEquals("username_test", req.getUsername());
        Assert.assertEquals("test_password", req.getPassword());

        verify(request);
        reset(request);

        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(GrantType.CLIENT_CREDENTIALS.toString());
        replay(request);

        try {
            req = new OAuthTokenRequest(request);

        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }
//        Assert.assertEquals("test_assertion", req.getAssertion());
//        Assert.assertEquals("test_type", req.getAssertionType());

        verify(request);
        reset(request);

        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);

        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token");
        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
        replay(request);

        try {
            req = new OAuthTokenRequest(request);

        } catch (OAuthProblemException e) {
            fail("Exception not expected");
        }
        Assert.assertEquals("client_id", req.getClientId());
        Assert.assertEquals("refresh_token", req.getRefreshToken());
        Assert.assertEquals("secret", req.getClientSecret());

        verify(request);


    }
View Full Code Here

            .setClientSecret(Common.CLIENT_SECRET)
            .setUsername(Common.USERNAME)
            .setPassword(Common.PASSWORD)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);

        assertNotNull(response.getAccessToken());
    }
View Full Code Here

            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
            .setGrantType(GrantType.PASSWORD)
            .setClientId(Common.CLIENT_ID)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        OAuthClientResponse response = null;

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here

            .setClientSecret(Common.CLIENT_SECRET)
            .setUsername(Common.USERNAME)
            .setPassword(Common.PASSWORD)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        OAuthClientResponse response = null;

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_CLIENT, e.getError());
        }
View Full Code Here

TOP

Related Classes of org.apache.amber.oauth2.as.request.OAuthTokenRequest

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.