Package org.springframework.security.oauth2.provider

Examples of org.springframework.security.oauth2.provider.OAuth2Authentication


  @Test
  public void testAccessGrantedIfScopesPresentWithPrefix() throws Exception {
    voter.setScopePrefix("scope=");
    OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
    Authentication userAuthentication = null;
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    assertEquals(
        AccessDecisionVoter.ACCESS_GRANTED,
        voter.vote(oAuth2Authentication, null,
            Collections.<ConfigAttribute> singleton(new SecurityConfig("scope=read"))));
  }
View Full Code Here


  @Test
  public void testAccessDeniedIfWrongScopesPresent() throws Exception {
    OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
    Authentication userAuthentication = null;
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    voter.setThrowException(false);
    assertEquals(
        AccessDecisionVoter.ACCESS_DENIED,
        voter.vote(oAuth2Authentication, null,
            Collections.<ConfigAttribute> singleton(new SecurityConfig("SCOPE_WRITE"))));
View Full Code Here

  @Test(expected = AccessDeniedException.class)
  public void testExceptionThrownIfWrongScopesPresent() throws Exception {
    OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
    Authentication userAuthentication = null;
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    assertEquals(
        AccessDecisionVoter.ACCESS_DENIED,
        voter.vote(oAuth2Authentication, null,
            Collections.<ConfigAttribute> singleton(new SecurityConfig("SCOPE_WRITE"))));
  }
View Full Code Here

  @Rule
  public ExpectedException expected = ExpectedException.none();

  @Test
  public void testExpiredToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    // Make it expire (and rely on mutable state in volatile token store)
    firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
View Full Code Here

    getTokenServices().loadAuthentication(firstAccessToken.getValue());
  }

  @Test
  public void testExpiredRefreshToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNotNull(firstAccessToken.getRefreshToken());
    // Make it expire (and rely on mutable state in volatile token store)
View Full Code Here

    getTokenServices().refreshAccessToken(firstAccessToken.getRefreshToken().getValue(), tokenRequest);
  }

  @Test
  public void testExpiredRefreshTokenIsRenewedWithNewAccessToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNotNull(firstAccessToken.getRefreshToken());
    // Make it expire (and rely on mutable state in volatile token store)
View Full Code Here

        client.setAccessTokenValiditySeconds(1);
        client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
        return client;
      }
    });
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    OAuth2RefreshToken expectedExpiringRefreshToken = firstAccessToken.getRefreshToken();
    // Make it expire (and rely on mutable state in volatile token store)
View Full Code Here

        client.setAccessTokenValiditySeconds(1);
        client.setAuthorizedGrantTypes(Arrays.asList("authorization_code"));
        return client;
      }
    });
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNull(token.getRefreshToken());
  }
View Full Code Here

    parameters.clear();
    parameters.put(OAuth2Utils.CLIENT_ID, "foo");
    parameters.put(OAuth2Utils.SCOPE, "scope");
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request(parameters, "foo", true, Collections.singleton("scope"));
   
    String code = authorizationCodeServices.createAuthorizationCode(new OAuth2Authentication(
        storedOAuth2Request, userAuthentication));
    parameters.putAll(storedOAuth2Request.getRequestParameters());
    parameters.put("code", code);
   
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
View Full Code Here

    parameters.put(OAuth2Utils.SCOPE, "scope");
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request(parameters, "foo", true, Collections.singleton("scope"));
   
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken("marissa", "koala",
        AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    String code = authorizationCodeServices.createAuthorizationCode(new OAuth2Authentication(
        storedOAuth2Request, userAuthentication));

    parameters.put("code", code);
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
   
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.provider.OAuth2Authentication

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.