Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Compatiblity with SecurityJackson2Modules #983

Open
gonzalad opened this issue Feb 17, 2017 · 0 comments
Open

Compatiblity with SecurityJackson2Modules #983

gonzalad opened this issue Feb 17, 2017 · 0 comments

Comments

@gonzalad
Copy link

I'm using Spring Security 4.2.1.RELEASE with Spring Security OAuth 2.0.11.

I imagine that Spring Security OAuth hasn't been updated with this latest version of Spring Security

When I do the following code :

        ObjectMapper objectMapper = new ObjectMapper();
        ClassLoader loader = getClass().getClassLoader();
        List<Module> modules = SecurityJackson2Modules.getModules(loader);
        objectMapper.registerModules(modules);
        SecurityContext securityContext = objectMapper.readValue(response, SecurityContext.class);

It fails with the following error :

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.security.oauth2.provider.OAuth2Authentication: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
 at [Source: {"@class":"org.springframework.security.core.context.SecurityContextImpl","authentication":{"@class":"org.springframework.security.oauth2.provider.OAuth2Authentication","authorities":["java.util.ArrayList",[{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"},{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"}]],"details":{"@class":"org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails","remoteAddress":"127.0.0.1","sessionId":"1","tokenValue":"myAccessToken","tokenType":"Bearer","decodedDetails":null},"authenticated":true,"userAuthentication":{"@class":"org.springframework.security.authentication.UsernamePasswordAuthenticationToken","authorities":["java.util.ArrayList",[{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"},{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"}]],"details":{"@class":"java.util.LinkedHashMap","id_token":"myValidIdToken","at_hash":"OFnYmAIw","sub":"TtFDExA","aud":"vQ22-LTAu6hyqA","azp":"client","iss":"xxx.issuer","name":"zic zic","preferred_username":"[email protected]","exp":"9999999999","given_name":"zic","iat":["java.lang.Long",1487373034],"family_name":"zic"},"authenticated":true,"principal":{"@class":"org.springframework.security.core.userdetails.User","password":"N/A","username":"zic@@xxx.com","authorities":["java.util.Collections$UnmodifiableSet",[{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"},{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"}]],"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"enabled":true},"credentials":"N/A"},"principal":{"@class":"org.springframework.security.core.userdetails.User","password":"N/A","username":"zic@@xxx.com","authorities":["java.util.Collections$UnmodifiableSet",[{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"},{"@class":"org.springframework.security.core.authority.SimpleGrantedAuthority","authority":"[email protected]"}]],"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"enabled":true},"credentials":"","clientOnly":false,"oauth2Request":{"@class":"org.springframework.security.oauth2.provider.OAuth2Request","clientId":"client","scope":["java.util.Collections$UnmodifiableSet",["openid"]],"requestParameters":{"@class":"java.util.Collections$UnmodifiableMap"},"resourceIds":["java.util.HashSet",[]],"authorities":["java.util.HashSet",[]],"approved":true,"refresh":false,"redirectUri":null,"responseTypes":["java.util.HashSet",[]],"extensions":{"@class":"java.util.HashMap"},"grantType":null,"refreshTokenRequest":null},"name":"zic@@xxx.com"}}; line: 1, column: 170] (through reference chain: org.springframework.security.core.context.SecurityContextImpl["authentication"])

	at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261)
	at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1456)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1012)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1203)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:314)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:183)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:150)
	at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:129)
	at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
	at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:142)
	at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:497)
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:101)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:178)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:150)
	at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:129)
	at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:97)
	at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:142)
	at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:63)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2833)
	at org.xxx.iam.security.autoconfigure.scim.test.ScimOidcTest.testCallToSecuredClientAndRs(ScimOidcTest.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants