Package org.springframework.security.oauth2.provider

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


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

    parameters.put("code", code);
    // Ensure even if token request asks for more scope they are not granted
    parameters.put(OAuth2Utils.SCOPE, "read write");
View Full Code Here


    parameters.put(OAuth2Utils.SCOPE, "scope");
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request(parameters, "foo", Collections.<GrantedAuthority> emptySet(), true, Collections.singleton("scope"), null, null, null, null);
   
    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);
    AuthorizationCodeTokenGranter granter = new AuthorizationCodeTokenGranter(providerTokenServices,
        authorizationCodeServices, clientDetailsService, requestFactory);
View Full Code Here

    parameters.put(OAuth2Utils.CLIENT_ID, "foo");
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request(parameters, "foo", null, true, null, null, "https://redirectMe", null, null);
   
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken("marissa", "koala",
        AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    String code = authorizationCodeServices.createAuthorizationCode(new OAuth2Authentication(storedOAuth2Request,
        userAuthentication));

    Map<String, String> authorizationParameters = new HashMap<String, String>();
    authorizationParameters.put("code", code);
 
View Full Code Here

    filter.setTokenServices(tokenServices);
    Mockito.when(restTemplate.getAccessToken()).thenReturn(new DefaultOAuth2AccessToken("FOO"));
    Set<String> scopes = new HashSet<String>();
    scopes.addAll(Arrays.asList("read", "write"));
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("client", false, scopes);
    this.authentication = new OAuth2Authentication(storedOAuth2Request, null);
    Mockito.when(tokenServices.loadAuthentication("FOO")).thenReturn(authentication);
    Authentication authentication = filter.attemptAuthentication(new MockHttpServletRequest(), null);
    assertEquals(this.authentication, authentication);
    Mockito.verify(restTemplate, Mockito.times(1)).getAccessToken();
  }
View Full Code Here

  public void testSuccessfulAuthentication() throws Exception {
    filter.setRestTemplate(restTemplate);
    Set<String> scopes = new HashSet<String>();
    scopes.addAll(Arrays.asList("read", "write"));
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("client", false, scopes);
    this.authentication = new OAuth2Authentication(storedOAuth2Request, null);
    filter.successfulAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse(), null, authentication);
    Mockito.verify(restTemplate, Mockito.times(1)).getAccessToken();
  }
View Full Code Here

        DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
        result.setRefreshToken(refreshToken);
        return result;
      }
    });
    OAuth2Authentication authentication = createAuthentication();
    OAuth2AccessToken original = getTokenServices().createAccessToken(authentication);
    assertTrue(original.getRefreshToken().equals(refreshToken));
    OAuth2AccessToken result = getTokenStore().getAccessToken(authentication);
    assertEquals(original, result);
    assertEquals(refreshToken, result.getRefreshToken());
View Full Code Here

    assertTrue(refreshedAccessToken.getValue().startsWith("I'mEnhanced"));
  }

  @Test
  public void testOneAccessTokenPerAuthentication() throws Exception {
    OAuth2Authentication authentication = createAuthentication();
    OAuth2AccessToken first = getTokenServices().createAccessToken(authentication);
    assertEquals(1, getAccessTokenCount());
    assertEquals(1, getRefreshTokenCount());
    OAuth2AccessToken second = getTokenServices().createAccessToken(authentication);
    assertEquals(first, second);
View Full Code Here

  @Test
  public void testOneAccessTokenPerUniqueAuthentication() throws Exception {
    getTokenServices()
        .createAccessToken(
            new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false,
                Collections.singleton("read")), new TestAuthentication("test2",
                false)));
    assertEquals(1, getAccessTokenCount());
    getTokenServices()
        .createAccessToken(
            new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false,
                Collections.singleton("write")), new TestAuthentication(
                "test2", false)));
    assertEquals(2, getAccessTokenCount());
  }
View Full Code Here

  @Before
  public void init() {
    token = new DefaultOAuth2AccessToken("FOO");
    ClientDetails client = new BaseClientDetails("client", null, "read", "client_credentials", "ROLE_CLIENT");
    authentication = new OAuth2Authentication(
        new TokenRequest(null, "client", null, "client_credentials").createOAuth2Request(client), null);
    tokenStore.clear();
  }
View Full Code Here

        "client_credentials", "ROLE_CLIENT"));
    request.setApproved(true);
    OAuth2Request clientAuthentication = request.createOAuth2Request();
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken("user", "pass",
        AuthorityUtils.createAuthorityList("ROLE_USER"));
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
    MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(),
        "testOauthClient"));
    EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
    Expression expression = handler.getExpressionParser().parseExpression(
        "#oauth2.hasAnyScope('write') or #oauth2.isUser()");
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.