Search in sources :

Example 11 with CustomOAuth2AccessToken

use of org.company.oauth2.CustomOAuth2AccessToken in project spring-security-oauth by spring-projects.

the class CustomSerializationStrategyTests method loadCustomSerializationStrategy.

@Test
public void loadCustomSerializationStrategy() {
    spy(SpringFactoriesLoader.class);
    when(SpringFactoriesLoader.loadFactories(SerializationStrategy.class, SerializationUtils.class.getClassLoader())).thenReturn(Arrays.<SerializationStrategy>asList(new CustomSerializationStrategy()));
    deserialize(new DefaultOAuth2AccessToken("access-token-" + UUID.randomUUID()));
    deserialize(new OAuth2Authentication(new OAuth2Request(Collections.<String, String>emptyMap(), "clientId", Collections.<GrantedAuthority>emptyList(), false, Collections.<String>emptySet(), new HashSet<String>(Arrays.asList("resourceId-1", "resourceId-2")), "redirectUri", Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap()), new UsernamePasswordAuthenticationToken("test", "N/A")));
    deserialize(new DefaultExpiringOAuth2RefreshToken("access-token-" + UUID.randomUUID(), new Date()));
    deserialize("xyz");
    deserialize(new HashMap<String, String>());
    deserialize(new CustomOAuth2AccessToken("xyz"));
    deserialize(new CustomOAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new CustomAuthentication("test", false)));
}
Also used : CustomOAuth2Authentication(org.company.oauth2.CustomOAuth2Authentication) CustomOAuth2AccessToken(org.company.oauth2.CustomOAuth2AccessToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) CustomOAuth2Authentication(org.company.oauth2.CustomOAuth2Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) DefaultExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken) CustomAuthentication(org.company.oauth2.CustomAuthentication) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with CustomOAuth2AccessToken

use of org.company.oauth2.CustomOAuth2AccessToken in project spring-security-oauth by spring-projects.

the class SerializationUtilsTests method deserializeNotAllowedCustomClasses.

@Test(expected = IllegalArgumentException.class)
public void deserializeNotAllowedCustomClasses() {
    OAuth2AccessToken accessToken = new CustomOAuth2AccessToken("FOO");
    WhitelistedSerializationStrategy newStrategy = new WhitelistedSerializationStrategy();
    SerializationStrategy oldStrategy = SerializationUtils.getSerializationStrategy();
    try {
        SerializationUtils.setSerializationStrategy(newStrategy);
        byte[] bytes = SerializationUtils.serialize(accessToken);
        OAuth2AccessToken clone = SerializationUtils.deserialize(bytes);
        assertNotNull(clone);
        assertEquals(accessToken, clone);
    } finally {
        SerializationUtils.setSerializationStrategy(oldStrategy);
    }
}
Also used : CustomOAuth2AccessToken(org.company.oauth2.CustomOAuth2AccessToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) CustomOAuth2AccessToken(org.company.oauth2.CustomOAuth2AccessToken) Test(org.junit.Test)

Example 13 with CustomOAuth2AccessToken

use of org.company.oauth2.CustomOAuth2AccessToken in project spring-security-oauth by spring-projects.

the class SerializationUtilsTests method deserializeCustomClasses.

@Test
public void deserializeCustomClasses() {
    OAuth2AccessToken accessToken = new CustomOAuth2AccessToken("FOO");
    byte[] bytes = SerializationUtils.serialize(accessToken);
    OAuth2AccessToken clone = SerializationUtils.deserialize(bytes);
    assertNotNull(clone);
    assertEquals(accessToken, clone);
}
Also used : CustomOAuth2AccessToken(org.company.oauth2.CustomOAuth2AccessToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) CustomOAuth2AccessToken(org.company.oauth2.CustomOAuth2AccessToken) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 CustomOAuth2AccessToken (org.company.oauth2.CustomOAuth2AccessToken)12 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)11 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)9 CustomOAuth2Authentication (org.company.oauth2.CustomOAuth2Authentication)8 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)8 SerializationStrategy (org.springframework.security.oauth2.common.util.SerializationStrategy)7 WhitelistedSerializationStrategy (org.springframework.security.oauth2.common.util.WhitelistedSerializationStrategy)7 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)5 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 ArrayList (java.util.ArrayList)3 CustomAuthentication (org.company.oauth2.CustomAuthentication)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 Authentication (org.springframework.security.core.Authentication)3 AuthorizationCodeResourceDetails (org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails)3 DefaultSerializationStrategy (org.springframework.security.oauth2.common.util.DefaultSerializationStrategy)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 DefaultExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken)1