mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-12 13:23:29 +00:00
Polish JSON warnings / javadoc
Issue gh-3736
This commit is contained in:
parent
6d2003722e
commit
6f2b24a62b
@ -34,7 +34,7 @@ import org.springframework.security.jackson2.SecurityJacksonModules;
|
|||||||
* ObjectMapper mapper = new ObjectMapper();
|
* ObjectMapper mapper = new ObjectMapper();
|
||||||
* mapper.registerModule(new CasJackson2Module());
|
* mapper.registerModule(new CasJackson2Module());
|
||||||
* </pre>
|
* </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.
|
* @author Jitendra Singh.
|
||||||
* @see org.springframework.security.jackson2.SecurityJacksonModules
|
* @see org.springframework.security.jackson2.SecurityJacksonModules
|
||||||
|
@ -38,7 +38,7 @@ import java.util.Collections;
|
|||||||
* ObjectMapper mapper = new ObjectMapper();
|
* ObjectMapper mapper = new ObjectMapper();
|
||||||
* mapper.registerModule(new CoreJackson2Module());
|
* mapper.registerModule(new CoreJackson2Module());
|
||||||
* </pre>
|
* </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.
|
* @author Jitendra Singh.
|
||||||
* @see SecurityJacksonModules
|
* @see SecurityJacksonModules
|
||||||
@ -56,7 +56,7 @@ public class CoreJackson2Module extends SimpleModule {
|
|||||||
context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
|
context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
|
||||||
context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
|
context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
|
||||||
context.setMixInAnnotations(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.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(User.class, UserMixin.class);
|
||||||
context.setMixInAnnotations(UsernamePasswordAuthenticationToken.class, UsernamePasswordAuthenticationTokenMixin.class);
|
context.setMixInAnnotations(UsernamePasswordAuthenticationToken.class, UsernamePasswordAuthenticationTokenMixin.class);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ class UnmodifiableSetMixin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mixin Constructor
|
* Mixin Constructor
|
||||||
* @param s
|
* @param s the Set
|
||||||
*/
|
*/
|
||||||
@JsonCreator
|
@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()}.
|
* 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.
|
* In that case there won't be any password key in serialized json.
|
||||||
*
|
*
|
||||||
* @param jp
|
* @param jp the JsonParser
|
||||||
* @param ctxt
|
* @param ctxt the DeserializationContext
|
||||||
* @return
|
* @return the user
|
||||||
* @throws IOException
|
* @throws IOException if a exception during IO occurs
|
||||||
* @throws JsonProcessingException
|
* @throws JsonProcessingException if an error during JSON processing occurs
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
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.
|
* This method construct {@link UsernamePasswordAuthenticationToken} object from serialized json.
|
||||||
* @param jp
|
* @param jp the JsonParser
|
||||||
* @param ctxt
|
* @param ctxt the DeserializationContext
|
||||||
* @return
|
* @return the user
|
||||||
* @throws IOException
|
* @throws IOException if a exception during IO occurs
|
||||||
* @throws JsonProcessingException
|
* @throws JsonProcessingException if an error during JSON processing occurs
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UsernamePasswordAuthenticationToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
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.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
|
||||||
import org.skyscreamer.jsonassert.JSONAssert;
|
import org.skyscreamer.jsonassert.JSONAssert;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
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
|
* 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
|
* throws {@link NullPointerException}. This is registered with {@link CookieMixin} but you can also use it with
|
||||||
* your own mixin.
|
* your own mixin.
|
||||||
*
|
*
|
||||||
|
@ -43,9 +43,9 @@ class DefaultCsrfTokenMixin {
|
|||||||
* JsonCreator constructor needed by Jackson to create {@link org.springframework.security.web.csrf.DefaultCsrfToken}
|
* JsonCreator constructor needed by Jackson to create {@link org.springframework.security.web.csrf.DefaultCsrfToken}
|
||||||
* object.
|
* object.
|
||||||
*
|
*
|
||||||
* @param headerName
|
* @param headerName the name of the header
|
||||||
* @param parameterName
|
* @param parameterName the parameter name
|
||||||
* @param token
|
* @param token the CSRF token value
|
||||||
*/
|
*/
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public DefaultCsrfTokenMixin(@JsonProperty("headerName") String headerName,
|
public DefaultCsrfTokenMixin(@JsonProperty("headerName") String headerName,
|
||||||
|
@ -75,6 +75,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void deserializeSavedCookieWithList() throws IOException, JSONException {
|
public void deserializeSavedCookieWithList() throws IOException, JSONException {
|
||||||
String expectedJson = String.format("[\"java.util.ArrayList\", [%s]]", expectedSavedCookieJson);
|
String expectedJson = String.format("[\"java.util.ArrayList\", [%s]]", expectedSavedCookieJson);
|
||||||
List<SavedCookie> savedCookies = (List<SavedCookie>)buildObjectMapper().readValue(expectedJson, Object.class);
|
List<SavedCookie> savedCookies = (List<SavedCookie>)buildObjectMapper().readValue(expectedJson, Object.class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user