Search in sources :

Example 96 with ClientDetails

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

the class ResourceServerConfigurationTests method init.

@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();
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Before(org.junit.Before)

Example 97 with ClientDetails

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

the class ClientDetailsServiceBeanDefinitionParserTests method testClientDetailsDefaultFlow.

@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("https://secure.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"));
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Test(org.junit.Test)

Example 98 with ClientDetails

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

the class ClientDetailsServiceBeanDefinitionParserTests method testClientDetailsFromNonPropertyFile.

@Test
public void testClientDetailsFromNonPropertyFile() {
    // valid client details NOT from property file
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-non-property-file");
    assertNotNull(clientDetailsService);
    assertEquals("my-client-id-non-property-file", clientDetails.getClientId());
    assertEquals("my-client-secret-non-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"));
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.Test)

Example 99 with ClientDetails

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

the class ApprovalStoreUserApprovalHandlerTests method init.

@Before
public void init() {
    handler.setApprovalStore(store);
    InMemoryClientDetailsService clientDetailsService = new InMemoryClientDetailsService();
    Map<String, ClientDetails> map = new HashMap<String, ClientDetails>();
    map.put("client", new BaseClientDetails("client", null, "read,write", "authorization_code", null));
    clientDetailsService.setClientDetailsStore(map);
    handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
    userAuthentication = new UsernamePasswordAuthenticationToken("user", "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
}
Also used : InMemoryClientDetailsService(org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) DefaultOAuth2RequestFactory(org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) HashMap(java.util.HashMap) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Before(org.junit.Before)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)47 Test (org.junit.Test)39 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)32 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)28 Authentication (org.springframework.security.core.Authentication)21 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)20 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)20 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)19 Date (java.util.Date)14 HashMap (java.util.HashMap)13 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)9 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)7 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)7 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 OrcidOauth2ClientAuthentication (org.orcid.core.oauth.OrcidOauth2ClientAuthentication)5