use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class AnonymousAuthenticationTokenTests method testNotEqualsDueToDifferentAuthenticationClass.
@Test
public void testNotEqualsDueToDifferentAuthenticationClass() {
AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key", "Test", ROLES_12);
UsernamePasswordAuthenticationToken token2 = new UsernamePasswordAuthenticationToken("Test", "Password", ROLES_12);
assertThat(token1.equals(token2)).isFalse();
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class AnonymousAuthenticationTokenMixinTests method serializeAnonymousAuthenticationTokenMixinAfterEraseCredentialTest.
@Test
public void serializeAnonymousAuthenticationTokenMixinAfterEraseCredentialTest() throws JsonProcessingException, JSONException {
User user = createDefaultUser();
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken(HASH_KEY, user, user.getAuthorities());
token.eraseCredentials();
String actualJson = mapper.writeValueAsString(token);
JSONAssert.assertEquals(ANONYMOUS_JSON.replace(UserDeserializerTests.USER_PASSWORD, "null"), actualJson, true);
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class AnonymousAuthenticationTokenMixinTests method deserializeAnonymousAuthenticationTokenTest.
@Test
public void deserializeAnonymousAuthenticationTokenTest() throws IOException {
AnonymousAuthenticationToken token = mapper.readValue(ANONYMOUS_JSON, AnonymousAuthenticationToken.class);
assertThat(token).isNotNull();
assertThat(token.getKeyHash()).isEqualTo(HASH_KEY.hashCode());
assertThat(token.getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class SpringSecurityAuthenticationSourceTests method principalIsEmptyForAnonymousUser.
@Test
public void principalIsEmptyForAnonymousUser() {
AuthenticationSource source = new SpringSecurityAuthenticationSource();
SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils.createAuthorityList("ignored")));
assertThat(source.getPrincipal()).isEqualTo("");
}
use of org.springframework.security.authentication.AnonymousAuthenticationToken in project spring-security by spring-projects.
the class AuthenticationSimpleHttpInvokerRequestExecutorTests method testNullContextHolderWhenAnonymous.
// SEC-1975
@Test
public void testNullContextHolderWhenAnonymous() throws Exception {
AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key", "principal", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
SecurityContextHolder.getContext().setAuthentication(anonymous);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("http://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties (shouldn't be an Authorization header)
assertThat(conn.getRequestProperty("Authorization")).isNull();
}
Aggregations