Package com.github.zhangkaitao.shiro.chapter18.oauth2

Examples of com.github.zhangkaitao.shiro.chapter18.oauth2.OAuth2Token


public class RestaurantApplication extends Application {
    @Override
    public Set<Object> getSingletons() {
        Set<Object> classes = new HashSet<Object>();
       
        classes.add(new RestaurantService());
       
        return classes;
    }
View Full Code Here


        WebClient.getConfig(ats).getHttpConduit().getClient().setReceiveTimeout(1000000L);
        manager.setAccessTokenService(ats);
       
        reserveService.setOAuthClientManager(manager);
       
        SecurityContextFilter filter = new SecurityContextFilter();
        filter.setUsers(Collections.singletonMap("barry@restaurant.com", "5678"));
       
        WebClient restaurantService =
          WebClient.create("http://localhost:8080/restaurant/reception");
        restaurantService.accept(MediaType.TEXT_PLAIN_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
        reserveService.setRestaurantService(restaurantService);
View Full Code Here

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);

    final OAuth2Token accessToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.ACCESS);
    Assert.assertNotNull(accessToken);
    Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType());
    Assert.assertTrue(accessToken.getExpiresAt() > 1000);

    final OAuth2Token refreshToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.REFRESH);
    Assert.assertNotNull(refreshToken);
    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }
View Full Code Here

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);

    final OAuth2Token accessToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.ACCESS);
    Assert.assertNotNull(accessToken);
    Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType());
    Assert.assertTrue(accessToken.getExpiresAt() > 1000);

    final OAuth2Token refreshToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.REFRESH);
    Assert.assertNotNull(refreshToken);
    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }
View Full Code Here

    final OAuth2HandlerError result = fixture.handleRequest(accessor, request);

    Assert.assertNull(result);

    final OAuth2Token accessToken = CodeAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.ACCESS);
    Assert.assertNotNull(accessToken);
    Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType());
    Assert.assertTrue(accessToken.getExpiresAt() > 1000);

    final OAuth2Token refreshToken = CodeAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.REFRESH);
    Assert.assertNotNull(refreshToken);
    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }
View Full Code Here

    Assert.assertEquals(MockUtils.ACCESSOR_INDEX1, result);
  }

  @Test
  public void testGetToken_1() throws Exception {
    final OAuth2Token result = this.cache.getToken(MockUtils.ACCESS_TOKEN_INDEX);

    Assert.assertNotNull(result);
    Assert.assertEquals(MockUtils.ACCESS_SECRET, new String(result.getSecret(), "UTF-8"));
  }
View Full Code Here

  }

  @Test
  public void testGetTokenIndex_2() throws Exception {

    final OAuth2Token token = null;

    final Integer result = this.cache.getTokenIndex(token);

    Assert.assertNull(result);
  }
View Full Code Here

  }

  @Test
  public void testRemoveToken_1() throws Exception {

    OAuth2Token result = this.cache.getToken(MockUtils.ACCESS_TOKEN_INDEX);

    Assert.assertNotNull(result);

    result = this.cache.removeToken(MockUtils.ACCESS_TOKEN_INDEX);
View Full Code Here

    Assert.assertEquals(null, result);
  }

  @Test
  public void testStoreToken_1() throws Exception {
    OAuth2Token token = new OAuth2TokenPersistence(MockUtils.getDummyEncrypter());
    token.setGadgetUri("xxx");
    token.setServiceName("yyy");
    token.setExpiresAt(2);
    token.setIssuedAt(1);
    token.setMacAlgorithm(OAuth2Message.HMAC_SHA_1);
    token.setMacSecret("shh, it's a secret".getBytes("UTF-8"));
    token.setScope("mac_scope");
    token.setSecret("i'll never tell".getBytes("UTF-8"));
    token.setTokenType(OAuth2Message.MAC_TOKEN_TYPE);
    token.setType(OAuth2Token.Type.ACCESS);
    token.setUser("zzz");

    final Integer result = this.cache.storeToken(token);

    Assert.assertEquals(460203885, result.intValue());

    token = this.cache.getToken(result);

    Assert.assertNotNull(token);
    Assert.assertEquals("xxx", token.getGadgetUri());
    Assert.assertEquals("yyy", token.getServiceName());

    Assert.assertEquals(2, token.getExpiresAt());
    Assert.assertEquals(1, token.getIssuedAt());
    Assert.assertEquals(OAuth2Message.HMAC_SHA_1, token.getMacAlgorithm());
    Assert.assertEquals("shh, it's a secret", new String(token.getMacSecret(), "UTF-8"));
    Assert.assertEquals("mac_scope", token.getScope());
    Assert.assertEquals("i'll never tell", new String(token.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.MAC_TOKEN_TYPE, token.getTokenType());
    Assert.assertEquals(OAuth2Token.Type.ACCESS, token.getType());
    Assert.assertEquals("zzz", token.getUser());
  }
View Full Code Here

  }

  @Test
  public void testStoreToken_2() throws Exception {

    final OAuth2Token token = null;

    final Integer result = this.cache.storeToken(token);

    Assert.assertEquals(null, result);
  }
View Full Code Here

TOP

Related Classes of com.github.zhangkaitao.shiro.chapter18.oauth2.OAuth2Token

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.