Package org.springframework.security.oauth2.provider

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


  @Test
  public void testClientDetailsFromPropertyFile() {

    // valid client details from property file
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-property-file");
    assertNotNull(clientDetailsService);
    assertEquals("my-client-id-property-file", clientDetails.getClientId());
    assertEquals("my-client-secret-property-file", clientDetails.getClientSecret());

    Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
    assertNotNull(grantTypes);
    assertEquals(2, grantTypes.size());
    assertTrue(grantTypes.contains("password"));
    assertTrue(grantTypes.contains("authorization_code"));

    Set<String> scopes = clientDetails.getScope();
    assertNotNull(scopes);
    assertEquals(2, scopes.size());
    assertTrue(scopes.contains("scope1"));
    assertTrue(scopes.contains("scope2"));

    Collection<GrantedAuthority> authorities = clientDetails.getAuthorities();
    assertNotNull(authorities);
    assertEquals(2, authorities.size());
    assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
    assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_ANONYMOUS"));
  }
View Full Code Here


    assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_ANONYMOUS"));
  }

  @Test
  public void testClientDetailsDefaultFlow() {
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-default-flow");
    assertNotNull(clientDetailsService);
    assertEquals("my-client-id-default-flow", clientDetails.getClientId());
    assertEquals(1, clientDetails.getRegisteredRedirectUri().size());
    assertEquals("http://mycompany.com", clientDetails.getRegisteredRedirectUri().iterator().next());

    Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
    assertNotNull(grantTypes);
    assertEquals(2, grantTypes.size());
    assertTrue(grantTypes.contains("authorization_code"));
    assertTrue(grantTypes.contains("refresh_token"));
  }
View Full Code Here

  @Test
  public void testLoadingClientIdWithNoDetails() {
    jdbcTemplate.update(INSERT_SQL, "clientIdWithNoDetails", null, null,
        null, null, null, null, null, null, null);

    ClientDetails clientDetails = service
        .loadClientByClientId("clientIdWithNoDetails");

    assertEquals("clientIdWithNoDetails", clientDetails.getClientId());
    assertFalse(clientDetails.isSecretRequired());
    assertNull(clientDetails.getClientSecret());
    assertFalse(clientDetails.isScoped());
    assertEquals(0, clientDetails.getScope().size());
    assertEquals(2, clientDetails.getAuthorizedGrantTypes().size());
    assertNull(clientDetails.getRegisteredRedirectUri());
    assertEquals(0, clientDetails.getAuthorities().size());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
  }
View Full Code Here

        null, null, null, null, null, null, null);
    jdbcTemplate
        .update("update oauth_client_details set additional_information=? where client_id=?",
            "{\"foo\":\"bar\"}", "clientIdWithAddInfo");

    ClientDetails clientDetails = service
        .loadClientByClientId("clientIdWithAddInfo");

    assertEquals("clientIdWithAddInfo", clientDetails.getClientId());
    assertEquals(Collections.singletonMap("foo", "bar"),
        clientDetails.getAdditionalInformation());
  }
View Full Code Here

  public void testLoadingClientIdWithSingleDetails() {
    jdbcTemplate.update(INSERT_SQL, "clientIdWithSingleDetails",
        "mySecret", "myResource", "myScope", "myAuthorizedGrantType",
        "myRedirectUri", "myAuthority", 100, 200, "true");

    ClientDetails clientDetails = service
        .loadClientByClientId("clientIdWithSingleDetails");

    assertEquals("clientIdWithSingleDetails", clientDetails.getClientId());
    assertTrue(clientDetails.isSecretRequired());
    assertEquals("mySecret", clientDetails.getClientSecret());
    assertTrue(clientDetails.isScoped());
    assertEquals(1, clientDetails.getScope().size());
    assertEquals("myScope", clientDetails.getScope().iterator().next());
    assertEquals(1, clientDetails.getResourceIds().size());
    assertEquals("myResource", clientDetails.getResourceIds().iterator()
        .next());
    assertEquals(1, clientDetails.getAuthorizedGrantTypes().size());
    assertEquals("myAuthorizedGrantType", clientDetails
        .getAuthorizedGrantTypes().iterator().next());
    assertEquals("myRedirectUri", clientDetails.getRegisteredRedirectUri()
        .iterator().next());
    assertEquals(1, clientDetails.getAuthorities().size());
    assertEquals("myAuthority", clientDetails.getAuthorities().iterator()
        .next().getAuthority());
    assertEquals(new Integer(100),
        clientDetails.getAccessTokenValiditySeconds());
    assertEquals(new Integer(200),
        clientDetails.getRefreshTokenValiditySeconds());
  }
View Full Code Here

    }
    else {
      if (clientDetailsService != null) {
        Collection<String> requestedScopes = authorizationRequest.getScope();
        try {
          ClientDetails client = clientDetailsService
              .loadClientByClientId(authorizationRequest.getClientId());
          for (String scope : requestedScopes) {
            if (client.isAutoApprove(scope) || client.isAutoApprove("all")) {
              approved = true;
              break;
            }
          }
        }
View Full Code Here

        db);
    customService
        .setSelectClientDetailsSql("select appId, appSecret, resourceIds, scope, "
            + "grantTypes, redirectUrl, authorities, access_token_validity, refresh_token_validity, additionalInformation, autoApproveScopes from ClientDetails where appId = ?");

    ClientDetails clientDetails = customService
        .loadClientByClientId("clientIdWithSingleDetails");

    assertEquals("clientIdWithSingleDetails", clientDetails.getClientId());
    assertTrue(clientDetails.isSecretRequired());
    assertEquals("mySecret", clientDetails.getClientSecret());
    assertTrue(clientDetails.isScoped());
    assertEquals(1, clientDetails.getScope().size());
    assertEquals("myScope", clientDetails.getScope().iterator().next());
    assertEquals(1, clientDetails.getResourceIds().size());
    assertEquals("myResource", clientDetails.getResourceIds().iterator()
        .next());
    assertEquals(1, clientDetails.getAuthorizedGrantTypes().size());
    assertEquals("myAuthorizedGrantType", clientDetails
        .getAuthorizedGrantTypes().iterator().next());
    assertEquals("myRedirectUri", clientDetails.getRegisteredRedirectUri()
        .iterator().next());
    assertEquals(1, clientDetails.getAuthorities().size());
    assertEquals("myAuthority", clientDetails.getAuthorities().iterator()
        .next().getAuthority());
  }
View Full Code Here

        "mySecret", "myResource1,myResource2", "myScope1,myScope2",
        "myAuthorizedGrantType1,myAuthorizedGrantType2",
        "myRedirectUri1,myRedirectUri2", "myAuthority1,myAuthority2",
        100, 200, "read,write");

    ClientDetails clientDetails = service
        .loadClientByClientId("clientIdWithMultipleDetails");

    assertEquals("clientIdWithMultipleDetails", clientDetails.getClientId());
    assertTrue(clientDetails.isSecretRequired());
    assertEquals("mySecret", clientDetails.getClientSecret());
    assertTrue(clientDetails.isScoped());
    assertEquals(2, clientDetails.getResourceIds().size());
    Iterator<String> resourceIds = clientDetails.getResourceIds()
        .iterator();
    assertEquals("myResource1", resourceIds.next());
    assertEquals("myResource2", resourceIds.next());
    assertEquals(2, clientDetails.getScope().size());
    Iterator<String> scope = clientDetails.getScope().iterator();
    assertEquals("myScope1", scope.next());
    assertEquals("myScope2", scope.next());
    assertEquals(2, clientDetails.getAuthorizedGrantTypes().size());
    Iterator<String> grantTypes = clientDetails.getAuthorizedGrantTypes()
        .iterator();
    assertEquals("myAuthorizedGrantType1", grantTypes.next());
    assertEquals("myAuthorizedGrantType2", grantTypes.next());
    assertEquals(2, clientDetails.getRegisteredRedirectUri().size());
    Iterator<String> redirectUris = clientDetails
        .getRegisteredRedirectUri().iterator();
    assertEquals("myRedirectUri1", redirectUris.next());
    assertEquals("myRedirectUri2", redirectUris.next());
    assertEquals(2, clientDetails.getAuthorities().size());
    Iterator<GrantedAuthority> authorities = clientDetails.getAuthorities()
        .iterator();
    assertEquals("myAuthority1", authorities.next().getAuthority());
    assertEquals("myAuthority2", authorities.next().getAuthority());
    assertEquals(new Integer(100),
        clientDetails.getAccessTokenValiditySeconds());
    assertEquals(new Integer(200),
        clientDetails.getRefreshTokenValiditySeconds());
    assertTrue(clientDetails.isAutoApprove("read"));
  }
View Full Code Here

  private OAuth2Authentication authentication;

  @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

  private ApprovalStore approvalStore;

  @RequestMapping("/oauth/confirm_access")
  public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
    AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
    ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
    model.put("auth_request", clientAuth);
    model.put("client", client);
    Map<String, String> scopes = new LinkedHashMap<String, String>();
    for (String scope : clientAuth.getScope()) {
      scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
    }
    for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
      if (clientAuth.getScope().contains(approval.getScope())) {
        scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
            approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
      }
    }
View Full Code Here

TOP

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

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.