org.springframework.security.authentication.AnonymousAuthenticationToken.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(271)

本文整理了Java中org.springframework.security.authentication.AnonymousAuthenticationToken.<init>()方法的一些代码示例,展示了AnonymousAuthenticationToken.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnonymousAuthenticationToken.<init>()方法的具体详情如下:
包路径:org.springframework.security.authentication.AnonymousAuthenticationToken
类名称:AnonymousAuthenticationToken
方法名:<init>

AnonymousAuthenticationToken.<init>介绍

[英]Constructor helps in Jackson Deserialization
[中]构造函数有助于Jackson反序列化

代码示例

代码示例来源:origin: spring-projects/spring-security

@Test
public void testEqualsWhenEqual() {
  AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  assertThat(token2).isEqualTo(token1);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testNotEqualsDueToAbstractParentEqualsCheck() {
  AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key",
      "DIFFERENT_PRINCIPAL", ROLES_12);
  assertThat(token1.equals(token2)).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
  public void constructorWhenPrincipalIsEmptyStringThenThrowIllegalArgumentException() throws Exception {
    new AnonymousAuthenticationToken("key", "", ROLES_12);
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testNotEqualsDueToKey() {
  AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken(
      "DIFFERENT_KEY", "Test", ROLES_12);
  assertThat(token1.equals(token2)).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

private Authentication createAnonymous() {
  return new AnonymousAuthenticationToken("ignored", "ignored",
      AuthorityUtils.createAuthorityList("ignored"));
}

代码示例来源:origin: spring-projects/spring-security

private Authentication createAnonymousPrincipal() {
    return new AnonymousAuthenticationToken("key-1234", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
  }
}

代码示例来源:origin: spring-projects/spring-security

private Authentication createAnonymousPrincipal() {
    return new AnonymousAuthenticationToken("key-1234", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
public void constructorWhenEmptyAuthoritiesThenThrowIllegalArgumentException() throws Exception {
  new AnonymousAuthenticationToken("key", "principal", Collections.<GrantedAuthority>emptyList());
}

代码示例来源:origin: spring-projects/spring-security

@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();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testSetAuthenticatedIgnored() {
  AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  assertThat(token.isAuthenticated()).isTrue();
  token.setAuthenticated(false);
  assertThat(!token.isAuthenticated()).isTrue();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void principalIsEmptyForAnonymousUser() {
  AuthenticationSource source = new SpringSecurityAuthenticationSource();
  SecurityContextHolder.getContext().setAuthentication(
      new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils
          .createAuthorityList("ignored")));
  assertThat(source.getPrincipal()).isEqualTo("");
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testGetters() {
  AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key",
      "Test", ROLES_12);
  assertThat(token.getKeyHash()).isEqualTo("key".hashCode());
  assertThat(token.getPrincipal()).isEqualTo("Test");
  assertThat(token.getCredentials()).isEqualTo("");
  assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities())).contains(
      "ROLE_ONE", "ROLE_TWO");
  assertThat(token.isAuthenticated()).isTrue();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testNormalOperation() throws Exception {
  AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider(
      "qwerty");
  AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("qwerty",
      "Test", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
  Authentication result = aap.authenticate(token);
  assertThat(token).isEqualTo(result);
}

代码示例来源:origin: spring-projects/spring-security

@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();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void serializeAnonymousAuthenticationTokenTest() throws JsonProcessingException, JSONException {
  User user = createDefaultUser();
  AnonymousAuthenticationToken token = new AnonymousAuthenticationToken(
      HASH_KEY, user, user.getAuthorities()
  );
  String actualJson = mapper.writeValueAsString(token);
  JSONAssert.assertEquals(ANONYMOUS_JSON, actualJson, true);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void testCorrectOperationIsAnonymous() {
  AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
  assertThat(trustResolver.isAnonymous(new AnonymousAuthenticationToken("ignored",
      "ignored", AuthorityUtils.createAuthorityList("ignored")))).isTrue();
  assertThat(trustResolver.isAnonymous(new TestingAuthenticationToken("ignored",
      "ignored", AuthorityUtils.createAuthorityList("ignored")))).isFalse();
}

代码示例来源:origin: spring-projects/spring-security

@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);
  }
}

代码示例来源:origin: spring-projects/spring-security

@Before
public void setup() {
  handler = new DefaultMessageSecurityExpressionHandler<>();
  message = new GenericMessage<>("");
  authentication = new AnonymousAuthenticationToken("key", "anonymous",
      AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
}

代码示例来源:origin: spring-projects/spring-security

@Before
public void setup() {
  authentication = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
  messageBuilder = MessageBuilder.withPayload("payload");
  expectedAnonymous = new AnonymousAuthenticationToken("key", "anonymous",
      AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
  interceptor = new SecurityContextChannelInterceptor();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void preSendUsesCustomAnonymous() throws Exception {
  expectedAnonymous = new AnonymousAuthenticationToken("customKey",
      "customAnonymous", AuthorityUtils.createAuthorityList("ROLE_CUSTOM"));
  interceptor.setAnonymousAuthentication(expectedAnonymous);
  interceptor.preSend(messageBuilder.build(), channel);
  assertAnonymous();
}

相关文章