parent
6d2003722e
commit
6f2b24a62b
|
@ -34,7 +34,7 @@ import org.springframework.security.jackson2.SecurityJacksonModules;
|
|||
* ObjectMapper mapper = new ObjectMapper();
|
||||
* mapper.registerModule(new CasJackson2Module());
|
||||
* </pre>
|
||||
* <b>Note: use {@link SecurityJacksonModules#getModules()} to get list of all security modules.</b>
|
||||
* <b>Note: use {@link SecurityJacksonModules#getModules(ClassLoader)} to get list of all security modules on the classpath.</b>
|
||||
*
|
||||
* @author Jitendra Singh.
|
||||
* @see org.springframework.security.jackson2.SecurityJacksonModules
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.util.Collections;
|
|||
* ObjectMapper mapper = new ObjectMapper();
|
||||
* mapper.registerModule(new CoreJackson2Module());
|
||||
* </pre>
|
||||
* <b>Note: use {@link SecurityJacksonModules#getModules()} to get list of all security modules.</b>
|
||||
* <b>Note: use {@link SecurityJacksonModules#getModules(ClassLoader)} to get list of all security modules.</b>
|
||||
*
|
||||
* @author Jitendra Singh.
|
||||
* @see SecurityJacksonModules
|
||||
|
@ -56,7 +56,7 @@ public class CoreJackson2Module extends SimpleModule {
|
|||
context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
|
||||
context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
|
||||
context.setMixInAnnotations(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.class);
|
||||
context.setMixInAnnotations(Collections.unmodifiableSet(Collections.EMPTY_SET).getClass(), UnmodifiableSetMixin.class);
|
||||
context.setMixInAnnotations(Collections.<Object>unmodifiableSet(Collections.emptySet()).getClass(), UnmodifiableSetMixin.class);
|
||||
context.setMixInAnnotations(User.class, UserMixin.class);
|
||||
context.setMixInAnnotations(UsernamePasswordAuthenticationToken.class, UsernamePasswordAuthenticationTokenMixin.class);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ class UnmodifiableSetMixin {
|
|||
|
||||
/**
|
||||
* Mixin Constructor
|
||||
* @param s
|
||||
* @param s the Set
|
||||
*/
|
||||
@JsonCreator
|
||||
UnmodifiableSetMixin(Set s) {}
|
||||
UnmodifiableSetMixin(Set<?> s) {}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,11 @@ class UserDeserializer extends JsonDeserializer<User> {
|
|||
* serialized json, because credentials may be removed from the {@link User} by invoking {@link User#eraseCredentials()}.
|
||||
* In that case there won't be any password key in serialized json.
|
||||
*
|
||||
* @param jp
|
||||
* @param ctxt
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws JsonProcessingException
|
||||
* @param jp the JsonParser
|
||||
* @param ctxt the DeserializationContext
|
||||
* @return the user
|
||||
* @throws IOException if a exception during IO occurs
|
||||
* @throws JsonProcessingException if an error during JSON processing occurs
|
||||
*/
|
||||
@Override
|
||||
public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
|
|
|
@ -47,11 +47,11 @@ class UsernamePasswordAuthenticationTokenDeserializer extends JsonDeserializer<U
|
|||
|
||||
/**
|
||||
* This method construct {@link UsernamePasswordAuthenticationToken} object from serialized json.
|
||||
* @param jp
|
||||
* @param ctxt
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws JsonProcessingException
|
||||
* @param jp the JsonParser
|
||||
* @param ctxt the DeserializationContext
|
||||
* @return the user
|
||||
* @throws IOException if a exception during IO occurs
|
||||
* @throws JsonProcessingException if an error during JSON processing occurs
|
||||
*/
|
||||
@Override
|
||||
public UsernamePasswordAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
|
|
|
@ -18,12 +18,8 @@ package org.springframework.security.jackson2;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.json.JSONException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Jackson deserializer for {@link Cookie}. This is needed because in most cases we don't
|
||||
* set {@link Cookie#domain} property. So when jackson deserialize that json {@link Cookie#setDomain(String)}
|
||||
* set {@link Cookie#getDomain()} property. So when jackson deserialize that json {@link Cookie#setDomain(String)}
|
||||
* throws {@link NullPointerException}. This is registered with {@link CookieMixin} but you can also use it with
|
||||
* your own mixin.
|
||||
*
|
||||
|
|
|
@ -43,9 +43,9 @@ class DefaultCsrfTokenMixin {
|
|||
* JsonCreator constructor needed by Jackson to create {@link org.springframework.security.web.csrf.DefaultCsrfToken}
|
||||
* object.
|
||||
*
|
||||
* @param headerName
|
||||
* @param parameterName
|
||||
* @param token
|
||||
* @param headerName the name of the header
|
||||
* @param parameterName the parameter name
|
||||
* @param token the CSRF token value
|
||||
*/
|
||||
@JsonCreator
|
||||
public DefaultCsrfTokenMixin(@JsonProperty("headerName") String headerName,
|
||||
|
|
|
@ -75,6 +75,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void deserializeSavedCookieWithList() throws IOException, JSONException {
|
||||
String expectedJson = String.format("[\"java.util.ArrayList\", [%s]]", expectedSavedCookieJson);
|
||||
List<SavedCookie> savedCookies = (List<SavedCookie>)buildObjectMapper().readValue(expectedJson, Object.class);
|
||||
|
|
Loading…
Reference in New Issue