|
43 | 43 | */ |
44 | 44 | public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixinTests { |
45 | 45 |
|
46 | | - // @formatter:off |
47 | 46 | private static final String AUTHENTICATED_JSON = "{" |
48 | | - + "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\"," |
49 | | - + "\"principal\": "+ UserDeserializerTests.USER_JSON + ", " |
50 | | - + "\"credentials\": \"1234\", " |
51 | | - + "\"authenticated\": true, " |
52 | | - + "\"details\": null, " |
53 | | - + "\"authorities\": "+ SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON |
54 | | - + "}"; |
55 | | - // @formatter:on |
56 | | - |
57 | | - // @formatter:off |
58 | | - public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON.replace( UserDeserializerTests.USER_JSON, "\"admin\""); |
59 | | - // @formatter:on |
60 | | - |
61 | | - // @formatter:off |
| 47 | + + "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\"," |
| 48 | + + "\"principal\": " + UserDeserializerTests.USER_JSON + ", " + "\"credentials\": \"1234\", " |
| 49 | + + "\"authenticated\": true, " + "\"details\": null, " + "\"authorities\": " |
| 50 | + + SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON + "}"; |
| 51 | + |
| 52 | + public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON |
| 53 | + .replace(UserDeserializerTests.USER_JSON, "\"admin\""); |
| 54 | + |
62 | 55 | private static final String NON_USER_PRINCIPAL_JSON = "{" |
63 | | - + "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", " |
64 | | - + "\"username\": \"admin\"" |
65 | | - + "}"; |
66 | | - // @formatter:on |
| 56 | + + "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", " |
| 57 | + + "\"username\": \"admin\"" + "}"; |
67 | 58 |
|
68 | | - // @formatter:off |
69 | | - private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", "\"details\": \"details\", "); |
70 | | - // @formatter:on |
| 59 | + private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", |
| 60 | + "\"details\": \"details\", "); |
71 | 61 |
|
72 | | - // @formatter:off |
73 | 62 | private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON |
74 | | - .replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON) |
75 | | - .replaceAll(UserDeserializerTests.USER_PASSWORD, "null") |
76 | | - .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON); |
77 | | - // @formatter:on |
| 63 | + .replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON) |
| 64 | + .replaceAll(UserDeserializerTests.USER_PASSWORD, "null") |
| 65 | + .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, |
| 66 | + SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON); |
78 | 67 |
|
79 | | - // @formatter:off |
80 | 68 | private static final String UNAUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_STRINGPRINCIPAL_JSON |
81 | | - .replace("\"authenticated\": true, ", "\"authenticated\": false, ") |
82 | | - .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON); |
83 | | - // @formatter:on |
| 69 | + .replace("\"authenticated\": true, ", "\"authenticated\": false, ") |
| 70 | + .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, |
| 71 | + SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON); |
84 | 72 |
|
85 | 73 | @Test |
86 | 74 | public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() |
@@ -184,30 +172,20 @@ public void deserializeAuthenticatedUsernamePasswordAuthenticationTokenWithDetai |
184 | 172 |
|
185 | 173 | @Test |
186 | 174 | public void serializingThenDeserializingWithNoCredentialsOrDetailsShouldWork() throws IOException { |
187 | | - // given |
188 | 175 | UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); |
189 | | - |
190 | | - // when |
191 | 176 | String serialized = this.mapper.writeValueAsString(original); |
192 | 177 | UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, |
193 | 178 | UsernamePasswordAuthenticationToken.class); |
194 | | - |
195 | | - // then |
196 | 179 | assertThat(deserialized).isEqualTo(original); |
197 | 180 | } |
198 | 181 |
|
199 | 182 | @Test |
200 | 183 | public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException { |
201 | | - // given |
202 | 184 | this.mapper.setDefaultPropertyInclusion(construct(ALWAYS, NON_NULL)).setSerializationInclusion(NON_ABSENT); |
203 | 185 | UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); |
204 | | - |
205 | | - // when |
206 | 186 | String serialized = this.mapper.writeValueAsString(original); |
207 | 187 | UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, |
208 | 188 | UsernamePasswordAuthenticationToken.class); |
209 | | - |
210 | | - // then |
211 | 189 | assertThat(deserialized).isEqualTo(original); |
212 | 190 | } |
213 | 191 |
|
|
0 commit comments