org.springframework.security.config.annotation.web.configurers.X509Configurer类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(110)

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

X509Configurer介绍

[英]Adds X509 based pre authentication to an application. Since validating the certificate happens when the client connects, the requesting and validation of the client certificate should be performed by the container. Spring Security will then use the certificate to look up the Authentication for the user. Security Filters

The following Filters are populated

  • X509AuthenticationFilter

Shared Objects Created

The following shared objects are created

  • AuthenticationEntryPoint is populated with an Http403ForbiddenEntryPoint
  • A PreAuthenticatedAuthenticationProvider is populated into HttpSecurity#authenticationProvider(org.springframework.security.authentication.AuthenticationProvider)

Shared Objects Used

The following shared objects are used:

  • A UserDetailsService shared object is used if no AuthenticationUserDetailsService is specified
    [中]将基于X509的预身份验证添加到应用程序中。由于验证证书发生在客户端连接时,因此客户端证书的请求和验证应由容器执行。然后,Spring Security将使用该证书查找用户的身份验证。安全过滤器
    将填充以下过滤器
    *X509AuthenticationFilter
    创建的共享对象
    将创建以下共享对象
    *AuthenticationEntryPoint由Http403ForbiddenEntryPoint填充
    *预验证的身份验证提供者被填充到HttpSecurity#authenticationProvider(org.springframework.security.authentication.authenticationProvider)中
    使用的共享对象
    使用以下共享对象:
    *如果未指定AuthenticationUserDetailsService,则使用UserDetailsService共享对象

代码示例

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

private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> getAuthenticationUserDetailsService(
    H http) {
  if (authenticationUserDetailsService == null) {
    userDetailsService(http.getSharedObject(UserDetailsService.class));
  }
  return authenticationUserDetailsService;
}

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

/**
 * Shortcut for invoking
 * {@link #authenticationUserDetailsService(AuthenticationUserDetailsService)} with a
 * {@link UserDetailsByNameServiceWrapper}.
 *
 * @param userDetailsService the {@link UserDetailsService} to use
 * @return the {@link X509Configurer} for further customizations
 */
public X509Configurer<H> userDetailsService(UserDetailsService userDetailsService) {
  UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken> authenticationUserDetailsService = new UserDetailsByNameServiceWrapper<>();
  authenticationUserDetailsService.setUserDetailsService(userDetailsService);
  return authenticationUserDetailsService(authenticationUserDetailsService);
}

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

/**
 * Configures X509 based pre authentication.
 *
 * <h2>Example Configuration</h2>
 *
 * The following configuration will attempt to extract the username from the X509
 * certificate. Remember that the Servlet Container will need to be configured to
 * request client certificates in order for this to work.
 *
 * <pre>
 * &#064;Configuration
 * &#064;EnableWebSecurity
 * public class X509SecurityConfig extends WebSecurityConfigurerAdapter {
 *
 *     &#064;Override
 *     protected void configure(HttpSecurity http) throws Exception {
 *         http.authorizeRequests().antMatchers(&quot;/**&quot;).hasRole(&quot;USER&quot;).and()
 *         // Example x509() configuration
 *                 .x509();
 *     }
 * }
 * </pre>
 *
 * @return the {@link X509Configurer} for further customizations
 * @throws Exception
 */
public X509Configurer<HttpSecurity> x509() throws Exception {
  return getOrApply(new X509Configurer<>());
}

代码示例来源:origin: SpringOne2GX-2014/microservice-security

@Override
protected void configure(HttpSecurity http) throws Exception {
  UserDetailsService userDetails = new InMemoryUserDetailsManager(
      Arrays.<UserDetails> asList(new User("rod", "N/A", AuthorityUtils
          .commaSeparatedStringToAuthorityList("ROLE_USER"))));
  http.authorizeRequests().anyRequest().authenticated().and().x509()
      .userDetailsService(userDetails).and().sessionManagement()
      .sessionCreationPolicy(SessionCreationPolicy.NEVER).and().csrf()
      .disable();
}

代码示例来源:origin: org.opensingular/singular-support

@Override
protected void configure(HttpSecurity http) throws Exception {
  http.antMatcher(REST_ANT_PATTERN)
      .authorizeRequests().anyRequest().authenticated()
      .and()
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
      .and()
      .csrf().disable()
      .x509()
      .subjectPrincipalRegex(restUserDetailsService.getSubjectPrincipalRegex())
      .userDetailsService(restUserDetailsService);
}

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

@Override
public void init(H http) throws Exception {
  PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
  authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http));
  http
    .authenticationProvider(authenticationProvider)
    .setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
}
// @formatter:on

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

@Override
public void configure(H http) throws Exception {
  X509AuthenticationFilter filter = getFilter(http
      .getSharedObject(AuthenticationManager.class));
  http.addFilter(filter);
}

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

private X509AuthenticationFilter getFilter(AuthenticationManager authenticationManager) {
  if (x509AuthenticationFilter == null) {
    x509AuthenticationFilter = new X509AuthenticationFilter();
    x509AuthenticationFilter.setAuthenticationManager(authenticationManager);
    if (x509PrincipalExtractor != null) {
      x509AuthenticationFilter.setPrincipalExtractor(x509PrincipalExtractor);
    }
    if (authenticationDetailsSource != null) {
      x509AuthenticationFilter
          .setAuthenticationDetailsSource(authenticationDetailsSource);
    }
    x509AuthenticationFilter = postProcess(x509AuthenticationFilter);
  }
  return x509AuthenticationFilter;
}

代码示例来源:origin: com.netflix.genie/genie-web

.anyRequest().hasRole(USER_ROLE)
.and()
  .x509().authenticationUserDetailsService(x509UserDetailsService)
.and()
  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)

代码示例来源:origin: org.springframework.security/spring-security-config

@Override
public void init(H http) throws Exception {
  PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
  authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http));
  http
    .authenticationProvider(authenticationProvider)
    .setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
}
// @formatter:on

代码示例来源:origin: org.springframework.security/spring-security-config

@Override
public void configure(H http) throws Exception {
  X509AuthenticationFilter filter = getFilter(http
      .getSharedObject(AuthenticationManager.class));
  http.addFilter(filter);
}

代码示例来源:origin: org.springframework.security/spring-security-config

private X509AuthenticationFilter getFilter(AuthenticationManager authenticationManager) {
  if (x509AuthenticationFilter == null) {
    x509AuthenticationFilter = new X509AuthenticationFilter();
    x509AuthenticationFilter.setAuthenticationManager(authenticationManager);
    if (x509PrincipalExtractor != null) {
      x509AuthenticationFilter.setPrincipalExtractor(x509PrincipalExtractor);
    }
    if (authenticationDetailsSource != null) {
      x509AuthenticationFilter
          .setAuthenticationDetailsSource(authenticationDetailsSource);
    }
    x509AuthenticationFilter = postProcess(x509AuthenticationFilter);
  }
  return x509AuthenticationFilter;
}

代码示例来源:origin: org.springframework.security/spring-security-config

private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> getAuthenticationUserDetailsService(
    H http) {
  if (authenticationUserDetailsService == null) {
    userDetailsService(http.getSharedObject(UserDetailsService.class));
  }
  return authenticationUserDetailsService;
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Shortcut for invoking
 * {@link #authenticationUserDetailsService(AuthenticationUserDetailsService)} with a
 * {@link UserDetailsByNameServiceWrapper}.
 *
 * @param userDetailsService the {@link UserDetailsService} to use
 * @return the {@link X509Configurer} for further customizations
 */
public X509Configurer<H> userDetailsService(UserDetailsService userDetailsService) {
  UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken> authenticationUserDetailsService = new UserDetailsByNameServiceWrapper<>();
  authenticationUserDetailsService.setUserDetailsService(userDetailsService);
  return authenticationUserDetailsService(authenticationUserDetailsService);
}

代码示例来源:origin: org.springframework.security/spring-security-javaconfig

@Override
public void init(H http) throws Exception {
  PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
  authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http));
  http
    .authenticationProvider(authenticationProvider)
    .setSharedObject(AuthenticationEntryPoint.class,new Http403ForbiddenEntryPoint());
}

代码示例来源:origin: org.springframework.security/spring-security-javaconfig

@Override
public void configure(H http) throws Exception {
  X509AuthenticationFilter filter = getFilter(http.getAuthenticationManager());
  http.addFilter(filter);
}

代码示例来源:origin: apache/servicemix-bundles

private X509AuthenticationFilter getFilter(AuthenticationManager authenticationManager) {
  if (x509AuthenticationFilter == null) {
    x509AuthenticationFilter = new X509AuthenticationFilter();
    x509AuthenticationFilter.setAuthenticationManager(authenticationManager);
    if (x509PrincipalExtractor != null) {
      x509AuthenticationFilter.setPrincipalExtractor(x509PrincipalExtractor);
    }
    if (authenticationDetailsSource != null) {
      x509AuthenticationFilter
          .setAuthenticationDetailsSource(authenticationDetailsSource);
    }
    x509AuthenticationFilter = postProcess(x509AuthenticationFilter);
  }
  return x509AuthenticationFilter;
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Configures X509 based pre authentication.
 *
 * <h2>Example Configuration</h2>
 *
 * The following configuration will attempt to extract the username from the X509
 * certificate. Remember that the Servlet Container will need to be configured to
 * request client certificates in order for this to work.
 *
 * <pre>
 * &#064;Configuration
 * &#064;EnableWebSecurity
 * public class X509SecurityConfig extends WebSecurityConfigurerAdapter {
 *
 *     &#064;Override
 *     protected void configure(HttpSecurity http) throws Exception {
 *         http.authorizeRequests().antMatchers(&quot;/**&quot;).hasRole(&quot;USER&quot;).and()
 *         // Example x509() configuration
 *                 .x509();
 *     }
 * }
 * </pre>
 *
 * @return the {@link X509Configurer} for further customizations
 * @throws Exception
 */
public X509Configurer<HttpSecurity> x509() throws Exception {
  return getOrApply(new X509Configurer<>());
}

代码示例来源:origin: org.springframework.security/spring-security-javaconfig

private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> getAuthenticationUserDetailsService(H http) {
  if(authenticationUserDetailsService == null) {
    userDetailsService(http.getSharedObject(UserDetailsService.class));
  }
  return authenticationUserDetailsService;
}

代码示例来源:origin: org.springframework.security/spring-security-javaconfig

/**
 * Shortcut for invoking {@link #authenticationUserDetailsService(AuthenticationUserDetailsService)} with a {@link UserDetailsByNameServiceWrapper}.
 *
 * @param userDetailsService the {@link UserDetailsService} to use
 * @return the {@link X509Configurer} for further customizations
 */
public X509Configurer<H> userDetailsService(
    UserDetailsService userDetailsService) {
  UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken> authenticationUserDetailsService = new UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken>();
  authenticationUserDetailsService.setUserDetailsService(userDetailsService);
  return authenticationUserDetailsService(authenticationUserDetailsService);
}

相关文章