Search in sources :

Example 66 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails in project spring-security-oauth by spring-projects.

the class JdbcClientDetailsServiceTests method testUpdateClientRedirectURI.

@Test
public void testUpdateClientRedirectURI() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("newClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    String[] redirectURI = { "http://localhost:8080", "http://localhost:9090" };
    clientDetails.setRegisteredRedirectUri(new HashSet<String>(Arrays.asList(redirectURI)));
    service.updateClientDetails(clientDetails);
    Map<String, Object> map = jdbcTemplate.queryForMap(SELECT_SQL, "newClientIdWithNoDetails");
    assertEquals("newClientIdWithNoDetails", map.get("client_id"));
    assertTrue(map.containsKey("web_server_redirect_uri"));
    assertEquals("http://localhost:8080,http://localhost:9090", map.get("web_server_redirect_uri"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 67 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails in project spring-security-oauth by spring-projects.

the class JdbcClientDetailsServiceTests method testInsertDuplicateClient.

@Test(expected = ClientAlreadyExistsException.class)
public void testInsertDuplicateClient() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("duplicateClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    service.addClientDetails(clientDetails);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 68 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails in project spring-security-oauth by spring-projects.

the class JdbcClientDetailsServiceTests method testRemoveClient.

@Test
public void testRemoveClient() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("deletedClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    service.removeClientDetails(clientDetails.getClientId());
    int count = jdbcTemplate.queryForObject("select count(*) from oauth_client_details where client_id=?", Integer.class, "deletedClientIdWithNoDetails");
    assertEquals(0, count);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 69 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails in project spring-security-oauth by spring-projects.

the class JdbcClientDetailsServiceTests method testLoadingClientIdWithAdditionalInformation.

@Test
public void testLoadingClientIdWithAdditionalInformation() {
    jdbcTemplate.update(INSERT_SQL, "clientIdWithAddInfo", null, null, 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());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Test(org.junit.Test)

Example 70 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails in project spring-security-oauth by spring-projects.

the class JdbcClientDetailsServiceTests method testAddClientWithNoDetails.

@Test
public void testAddClientWithNoDetails() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("addedClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    Map<String, Object> map = jdbcTemplate.queryForMap(SELECT_SQL, "addedClientIdWithNoDetails");
    assertEquals("addedClientIdWithNoDetails", map.get("client_id"));
    assertTrue(map.containsKey("client_secret"));
    assertEquals(null, map.get("client_secret"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)40 Test (org.junit.Test)34 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)28 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)23 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)19 Authentication (org.springframework.security.core.Authentication)18 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)16 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)14 Date (java.util.Date)13 HashMap (java.util.HashMap)11 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)7 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)6 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)6 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)6 OrcidOauth2ClientAuthentication (org.orcid.core.oauth.OrcidOauth2ClientAuthentication)5 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)5 InvalidClientException (org.springframework.security.oauth2.common.exceptions.InvalidClientException)5