Search in sources :

Example 11 with BaseClientDetails

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

the class BaseClientDetailsTests method testBaseClientDetailsImplicitAutoApprove.

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

Example 12 with BaseClientDetails

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

the class BaseClientDetailsTests method testJsonDeserialize.

@Test
public void testJsonDeserialize() throws Exception {
    String value = "{\"foo\":\"bar\",\"client_id\":\"foo\",\"scope\":[\"bar\",\"foo\"],\"authorized_grant_types\":[\"authorization_code\"],\"authorities\":[\"ROLE_USER\"]}";
    BaseClientDetails details = new ObjectMapper().readValue(value, BaseClientDetails.class);
    BaseClientDetails expected = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    expected.setAdditionalInformation(Collections.singletonMap("foo", (Object) "bar"));
    assertEquals(expected, details);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 13 with BaseClientDetails

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

the class BaseClientDetailsTests method testBaseClientDetailsConvenienceConstructor.

/**
	 * test explicit convenience constructor
	 */
@Test
public void testBaseClientDetailsConvenienceConstructor() {
    BaseClientDetails details = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    assertEquals("[]", details.getResourceIds().toString());
    assertEquals("[bar, foo]", details.getScope().toString());
    assertEquals("[authorization_code]", details.getAuthorizedGrantTypes().toString());
    assertEquals("[ROLE_USER]", details.getAuthorities().toString());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 14 with BaseClientDetails

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

the class BaseClientDetailsTests method testBaseClientDetailsAutoApprove.

/**
	 * test explicit autoapprove
	 */
@Test
public void testBaseClientDetailsAutoApprove() {
    BaseClientDetails details = new BaseClientDetails("foo", "", "foo,bar", "authorization_code", "ROLE_USER");
    details.setAutoApproveScopes(StringUtils.commaDelimitedListToSet("read,write"));
    assertTrue(details.isAutoApprove("read"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 15 with BaseClientDetails

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

the class BaseClientDetailsTests method testEqualityOfValidity.

/**
	 * test equality
	 */
@Test
public void testEqualityOfValidity() {
    BaseClientDetails details = new BaseClientDetails();
    details.setAccessTokenValiditySeconds(100);
    BaseClientDetails other = new BaseClientDetails();
    other.setAccessTokenValiditySeconds(100);
    assertEquals(details, other);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) 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