Package org.mule.common.security.oauth

Examples of org.mule.common.security.oauth.OAuthState


    }

    @Test
    public void makeObject() throws Exception
    {
        OAuthState state = this.registerState();

        TestOAuth2Adapter connector = (TestOAuth2Adapter) this.factory.makeObject(KEY);

        Assert.assertSame(connector.getManager(), this.manager);
        Mockito.verify(this.factory).setCustomAdapterProperties(connector, state);
        Mockito.verify(this.manager).postAuth(connector, KEY);

        Assert.assertTrue(connector.wasStarted());
        Assert.assertTrue(connector.wasInitialised());
        Assert.assertSame(connector.getMuleContext(), this.muleContext);

        Assert.assertEquals(connector.getConsumerKey(), consumerKey);
        Assert.assertEquals(connector.getConsumerSecret(), consumerSecret);
        Assert.assertEquals(connector.getAccessToken(), state.getAccessToken());
        Assert.assertEquals(connector.getAccessTokenUrl(), state.getAccessTokenUrl());
        Assert.assertEquals(connector.getAuthorizationUrl(), state.getAuthorizationUrl());
        Assert.assertEquals(connector.getRefreshToken(), state.getRefreshToken());

        Mockito.verify(this.objectStore, Mockito.never()).remove(KEY);
        Mockito.verify(this.objectStore, Mockito.never()).store(Mockito.eq(KEY),
            Mockito.any(OAuthState.class));
    }
View Full Code Here


        Mockito.doAnswer(new Answer<Void>()
        {
            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable
            {
                OAuthState newState = (OAuthState) invocation.getArguments()[1];
                Assert.assertEquals(newState.getAccessToken(), state.getAccessToken());
                Assert.assertEquals(newState.getAccessTokenUrl(), state.getAccessTokenUrl());
                Assert.assertEquals(newState.getAuthorizationUrl(), state.getAuthorizationUrl());
                Assert.assertEquals(newState.getRefreshToken(), state.getRefreshToken());
                Assert.assertEquals(newState.getCustomProperty("custom1"), state.getCustom1());
                Assert.assertEquals(newState.getCustomProperty("custom2"), state.getCustom2());

                state.setChecked(true);
                return null;
            }
        })
View Full Code Here

    }

    @Test
    public void validateObject() throws Exception
    {
        OAuthState state = this.registerState();
        TestOAuth2Adapter adapter = new TestOAuth2Adapter(this.manager);
        adapter.setAccessToken(state.getAccessToken());
        adapter.setRefreshToken(state.getRefreshToken());

        Assert.assertTrue(this.factory.validateObject(KEY, adapter));
    }
View Full Code Here

    }

    @Test
    public void validateObjectWithNoRefreshTokenButStateThatDoes() throws Exception
    {
        OAuthState state = this.registerState();
        TestOAuth2Adapter adapter = new TestOAuth2Adapter(this.manager);
        adapter.setAccessToken(state.getAccessToken());
        adapter.setRefreshToken(null);

        Assert.assertFalse(this.factory.validateObject(KEY, adapter));
    }
View Full Code Here

    }

    @Test
    public void validateObjectWithNoRefreshTokenButStateThatDoesntEither() throws Exception
    {
        OAuthState state = this.registerState();
        TestOAuth2Adapter adapter = new TestOAuth2Adapter(this.manager);
        adapter.setAccessToken(state.getAccessToken());
        adapter.setRefreshToken(null);
        state.setRefreshToken(null);

        Assert.assertTrue(this.factory.validateObject(KEY, adapter));
    }
View Full Code Here

    }

    @Test
    public void validateObjectWithWrongRefresh() throws Exception
    {
        OAuthState state = this.registerState();
        TestOAuth2Adapter adapter = new TestOAuth2Adapter(this.manager);
        adapter.setAccessToken(state.getAccessToken());
        adapter.setRefreshToken("I'm wrong");

        Assert.assertFalse(this.factory.validateObject(KEY, adapter));
    }
View Full Code Here

    }

    @Test
    public void passivateExisting() throws Exception
    {
        OAuthState state = this.registerState();
        TestOAuth2Adapter adapter = new TestOAuth2Adapter(this.manager);

        adapter.setAccessToken("new access token");
        adapter.setAccessTokenUrl("access token url");
        adapter.setAuthorizationUrl("authorization url");
        adapter.setRefreshToken("refresh token");

        this.factory.passivateObject(KEY, adapter);

        Assert.assertEquals(adapter.getAccessToken(), state.getAccessToken());
        Assert.assertEquals(adapter.getAccessTokenUrl(), state.getAccessTokenUrl());
        Assert.assertEquals(adapter.getAuthorizationUrl(), state.getAuthorizationUrl());
        Assert.assertEquals(adapter.getRefreshToken(), state.getRefreshToken());

        Mockito.verify(this.objectStore).remove(KEY);
        Mockito.verify(this.factory).setCustomStateProperties(adapter, state);
        Mockito.verify(this.objectStore).store(KEY, state);
    }
View Full Code Here

        {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable
            {
                OAuthState state = (OAuthState) invocation.getArguments()[1];
                Assert.assertEquals(adapter.getAccessToken(), state.getAccessToken());
                Assert.assertEquals(adapter.getAccessTokenUrl(), state.getAccessTokenUrl());
                Assert.assertEquals(adapter.getAuthorizationUrl(), state.getAuthorizationUrl());
                Assert.assertEquals(adapter.getRefreshToken(), state.getRefreshToken());

                return null;
            }
        }).when(this.objectStore).store(Mockito.eq(KEY), Mockito.any(OAuthState.class));
    }
View Full Code Here

    }

    @Test
    public void objectStoreAtomicity() throws Exception
    {
        OAuthState state = this.registerState();

        this.objectStore = new InMemoryObjectStore<Serializable>();
        this.objectStore.store(KEY, state);
        this.factory = new TestClientFactory(this.manager, this.objectStore);
        final AtomicInteger rejectedAccessAttemps = new AtomicInteger(0);
View Full Code Here

        return adapter;
    }

    private OAuthState registerState() throws ObjectStoreException
    {
        OAuthState state = new OAuthState();
        state.setAccessToken("accessToken");
        state.setAccessTokenUrl("accessTokenUrl");
        state.setAuthorizationUrl("authorizationUrl");
        state.setCustomProperty("custom1", "custom1");
        state.setCustomProperty("custom2", "custom2");
        state.setRefreshToken("refreshToken");

        Mockito.when(this.objectStore.contains(KEY)).thenReturn(true);
        Mockito.when(this.objectStore.retrieve(KEY)).thenReturn(state);

        return state;
View Full Code Here

TOP

Related Classes of org.mule.common.security.oauth.OAuthState

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.