use of org.springframework.security.oauth2.common.util.WhitelistedSerializationStrategy in project spring-security-oauth by spring-projects.
the class JdbcTokenStoreTests method testNotAllowedCustomTokenWithCustomStrategy.
@Test
public void testNotAllowedCustomTokenWithCustomStrategy() {
OAuth2Authentication authentication = new CustomOAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new CustomAuthentication("test4", false));
OAuth2AccessToken accessToken = new CustomOAuth2AccessToken("customToken");
JdbcTokenStore tokenStore = getTokenStore();
WhitelistedSerializationStrategy newStrategy = new WhitelistedSerializationStrategy();
SerializationStrategy oldStrategy = SerializationUtils.getSerializationStrategy();
try {
SerializationUtils.setSerializationStrategy(newStrategy);
tokenStore.storeAccessToken(accessToken, authentication);
Collection<OAuth2AccessToken> tokens = tokenStore.findTokensByUserName("test4");
assertTrue(tokens.isEmpty());
} finally {
SerializationUtils.setSerializationStrategy(oldStrategy);
}
}
use of org.springframework.security.oauth2.common.util.WhitelistedSerializationStrategy in project spring-security-oauth by spring-projects.
the class JdbcAuthorizationCodeServicesTests method testCustomImplementationWithCustomStrategy.
@Test
public void testCustomImplementationWithCustomStrategy() {
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false);
OAuth2Authentication expectedAuthentication = new CustomOAuth2Authentication(storedOAuth2Request, new CustomAuthentication("test3", false));
AuthorizationCodeServices jdbcAuthorizationCodeServices = getAuthorizationCodeServices();
List<String> allowedClasses = new ArrayList<String>();
allowedClasses.add("java.util.");
allowedClasses.add("org.springframework.security.");
allowedClasses.add("org.company.oauth2.CustomOAuth2AccessToken");
allowedClasses.add("org.company.oauth2.CustomOAuth2Authentication");
allowedClasses.add("org.company.oauth2.CustomAuthentication");
WhitelistedSerializationStrategy newStrategy = new WhitelistedSerializationStrategy(allowedClasses);
SerializationStrategy oldStrategy = SerializationUtils.getSerializationStrategy();
try {
SerializationUtils.setSerializationStrategy(newStrategy);
String code = jdbcAuthorizationCodeServices.createAuthorizationCode(expectedAuthentication);
assertNotNull(code);
OAuth2Authentication actualAuthentication = getAuthorizationCodeServices().consumeAuthorizationCode(code);
assertEquals(expectedAuthentication, actualAuthentication);
} finally {
SerializationUtils.setSerializationStrategy(oldStrategy);
}
}
use of org.springframework.security.oauth2.common.util.WhitelistedSerializationStrategy in project spring-security-oauth by spring-projects.
the class JdbcAuthorizationCodeServicesTests method testNotAllowedCustomImplementation.
@Test(expected = IllegalArgumentException.class)
public void testNotAllowedCustomImplementation() {
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false);
OAuth2Authentication expectedAuthentication = new CustomOAuth2Authentication(storedOAuth2Request, new CustomAuthentication("test2", false));
WhitelistedSerializationStrategy newStrategy = new WhitelistedSerializationStrategy();
SerializationStrategy oldStrategy = SerializationUtils.getSerializationStrategy();
try {
SerializationUtils.setSerializationStrategy(newStrategy);
String code = getAuthorizationCodeServices().createAuthorizationCode(expectedAuthentication);
assertNotNull(code);
getAuthorizationCodeServices().consumeAuthorizationCode(code);
} finally {
SerializationUtils.setSerializationStrategy(oldStrategy);
}
}
use of org.springframework.security.oauth2.common.util.WhitelistedSerializationStrategy 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);
}
}
Aggregations