Search in sources :

Example 1 with JdbcClientDetailsService

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

the class JdbcClientDetailsServiceTests method testLoadingClientIdWithSingleDetailsInCustomTable.

@Test
public void testLoadingClientIdWithSingleDetailsInCustomTable() {
    jdbcTemplate.update(CUSTOM_INSERT_SQL, "clientIdWithSingleDetails", "mySecret", "myResource", "myScope", "myAuthorizedGrantType", "myRedirectUri", "myAuthority");
    JdbcClientDetailsService customService = new JdbcClientDetailsService(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());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) JdbcClientDetailsService(org.springframework.security.oauth2.provider.client.JdbcClientDetailsService) Test(org.junit.Test)

Example 2 with JdbcClientDetailsService

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

the class JdbcClientDetailsServiceBuilder method performBuild.

@Override
protected ClientDetailsService performBuild() {
    Assert.state(dataSource != null, "You need to provide a DataSource");
    JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
    if (passwordEncoder != null) {
        // This is used to encode secrets as they are added to the database (if it isn't set then the user has top
        // pass in pre-encoded secrets)
        clientDetailsService.setPasswordEncoder(passwordEncoder);
    }
    for (ClientDetails client : clientDetails) {
        clientDetailsService.addClientDetails(client);
    }
    return clientDetailsService;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) JdbcClientDetailsService(org.springframework.security.oauth2.provider.client.JdbcClientDetailsService)

Example 3 with JdbcClientDetailsService

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

the class JdbcClientDetailsServiceTests method setUp.

@Before
public void setUp() throws Exception {
    // creates a HSQL in-memory db populated from default scripts
    // classpath:schema.sql and classpath:data.sql
    db = new EmbeddedDatabaseBuilder().addDefaultScripts().build();
    jdbcTemplate = new JdbcTemplate(db);
    service = new JdbcClientDetailsService(db);
}
Also used : JdbcClientDetailsService(org.springframework.security.oauth2.provider.client.JdbcClientDetailsService) EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Aggregations

JdbcClientDetailsService (org.springframework.security.oauth2.provider.client.JdbcClientDetailsService)3 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)2 Before (org.junit.Before)1 Test (org.junit.Test)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)1 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)1