Search in sources :

Example 21 with BaseClientDetails

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

the class ApprovalStoreUserApprovalHandlerTests method testAutoapprovedScopes.

@Test
public void testAutoapprovedScopes() {
    handler.setClientDetailsService(clientDetailsService);
    BaseClientDetails client = new BaseClientDetails("client", null, "read", "authorization_code", null);
    client.setAutoApproveScopes(new HashSet<String>(Arrays.asList("read")));
    clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
    AuthorizationRequest result = handler.checkForPreApproval(authorizationRequest, userAuthentication);
    assertTrue(result.isApproved());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) Test(org.junit.Test)

Example 22 with BaseClientDetails

use of org.springframework.security.oauth2.provider.client.BaseClientDetails 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)

Example 23 with BaseClientDetails

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

the class BaseClientDetailsTests method testBaseClientDetailsNoAutoApprove.

@Test
public void testBaseClientDetailsNoAutoApprove() {
    BaseClientDetails details = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    details.setAutoApproveScopes(StringUtils.commaDelimitedListToSet("none"));
    assertFalse(details.isAutoApprove("read"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 24 with BaseClientDetails

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

the class BaseClientDetailsTests method testJsonSerializeAdditionalInformation.

@Test
public void testJsonSerializeAdditionalInformation() throws Exception {
    BaseClientDetails details = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    details.setClientId("foo");
    details.setAdditionalInformation(Collections.singletonMap("foo", "bar"));
    String value = new ObjectMapper().writeValueAsString(details);
    assertTrue(value.contains("\"foo\":\"bar\""));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 25 with BaseClientDetails

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

the class BaseClientDetailsTests method testJsonSerialize.

@Test
public void testJsonSerialize() throws Exception {
    BaseClientDetails details = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    details.setClientId("foo");
    details.setClientSecret("bar");
    String value = new ObjectMapper().writeValueAsString(details);
    assertTrue(value.contains("client_id"));
    assertTrue(value.contains("client_secret"));
    assertTrue(value.contains("authorized_grant_types"));
    assertTrue(value.contains("[\"ROLE_USER\"]"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)42 Test (org.junit.Test)36 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)12 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)12 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)8 Authentication (org.springframework.security.core.Authentication)7 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)6 Before (org.junit.Before)5 Expression (org.springframework.expression.Expression)5 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 EvaluationContext (org.springframework.expression.EvaluationContext)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)3 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)3 Date (java.util.Date)2