标签: pre-authentication

Spring安全性PreAuthentication Filter请求AuthenticationEntryPoint

我试图在Spring Security 3.0中使用PreAuthFilter(对于Siteminder).

 <http  use-expressions="true">
        <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
        <intercept-url pattern="/403.jsp" access="permitAll" />
        <!-- Allow non-secure access to static resources  -->
        <intercept-url pattern="/css/**" filters="none" />
        <intercept-url pattern="/images/**" filters="none" />

        <custom-filter ref="siteminderFilter" position="PRE_AUTH_FILTER"/>

<!--        <form-login  /> -->
        <logout logout-success-url="/index.jsp"/>
    </http>

    <beans:bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
        <beans:property name="principalRequestHeader" value="SM_USER"/>
        <beans:property name="authenticationManager" ref="authenticationManager" />
        <beans:property name="exceptionIfHeaderMissing" value="false"/>
    </beans:bean>

    <beans:bean id="AdminUserDetailsService" class="com.fw.security.auth.MyUserDetailsService">
    </beans:bean>

    <beans:bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
        <beans:property name="preAuthenticatedUserDetailsService">
            <beans:bean id="userDetailsServiceWrapper" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
                <beans:property name="userDetailsService" ref="AdminUserDetailsService"/>
            </beans:bean>
        </beans:property>
    </beans:bean>

    <authentication-manager alias="authenticationManager">
      <authentication-provider ref="preauthAuthProvider" />
    </authentication-manager>
Run Code Online (Sandbox Code Playgroud)

以上配置失败

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration …
Run Code Online (Sandbox Code Playgroud)

java spring siteminder spring-security pre-authentication

24
推荐指数
1
解决办法
2万
查看次数

如何在Spring Boot中设置预认证基于头的身份验证?

我的应用程序从Oracle Access Manager SSO获取带有用户名的AUTH_USER请求标头.Spring Security"附加主题"2.2.1有一个"PreAuth"的例子,它似乎是我需要的,但不是一个完整的工作示例.

下面的代码段来自docs/examples,而不是基于注释的配置.

Siteminder示例配置 - 使用带有RequestHeaderAuthenticationFilter的 XML 和PreAuthenticatedAuthenticationProvider以及UserDetailsS​​ervice来查找用户.

这如何映射到基于Java的配置?

<security:http>
  <!-- Additional http configuration omitted -->
  <security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>

<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
  <property name="principalRequestHeader" value="AUTH_USER"/>
  <property name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.    PreAuthenticatedAuthenticationProvider">
  <property name="preAuthenticatedUserDetailsService">
    <bean id="userDetailsServiceWrapper"
          class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
      <property name="userDetailsService" ref="userDetailsService"/>
    </bean>
  </property>
</bean>

<security:authentication-manager alias="authenticationManager">
   <security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
Run Code Online (Sandbox Code Playgroud)

Spring Security preauth示例具有完全不同的设置(XML配置更加令人生畏).没有提到pre-auth过滤器或如何设置标题名称.

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests() …
Run Code Online (Sandbox Code Playgroud)

java spring-security single-sign-on pre-authentication spring-boot

12
推荐指数
1
解决办法
1万
查看次数

如何在@Preauthorize中使用路径变量

我有一种情况,我需要将路径变量作为参数传递给预授权

    @RequestMapping(value="/page/{cmd}", method = RequestMethod.GET)
    @PreAuthorize("hasRole(#cmd)") 
     public void method(@PathVariable String cmd, HttpServletRequest request,  HttpServletResponse response){
// my stuff
}
Run Code Online (Sandbox Code Playgroud)

它没有工作.任何人都建议我如何在预授权中使用路径变量.

spring-security java-ee pre-authentication

9
推荐指数
1
解决办法
2173
查看次数

使用带有keycloak的spring安全注释

我只是一个Spring Security的初学者,但我想知道的是有可能的方式,我可以使用配置keycloak @PreAuthorize,@PostAuthorize,@Secured和其他注释.例如,我keycloak-spring-security-adapter在我的简单Spring Rest webapp中配置了Spring Security,以便我可以访问控制器中的Principal对象,如下所示:

@RestController
public class TMSRestController {

     @RequestMapping("/greeting")
     public Greeting greeting(Principal principal, @RequestParam(value="name") String name) {
        return new Greeting(String.format(template, name));
     }
...
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这个时(只是一个例子,实际上我想在授权之前执行自定义EL表达式):

@RestController
public class TMSRestController {

    @RequestMapping("/greeting")
    @PreAuthorize("hasRole('ADMIN')")
    public Greeting greeting(Principal principal, @RequestParam(value="name") String name) {
        return new Greeting(String.format(template, name));
    }
...
}
Run Code Online (Sandbox Code Playgroud)

我得到例外:

org.springframework.security.authentication.AuthenticationCredentialsNotFoundException:在SecurityContext中找不到Authentication对象

在我的spring安全配置中,我启用了全局方法安全性:

我需要做什么才能使这个弹簧安全注释工作?是否可以在此上下文中使用此注释?

spring spring-security pre-authentication keycloak

7
推荐指数
2
解决办法
4725
查看次数

如何在ASP.Net MVC 3 _Intranet_应用程序中重新验证用户?

让我解释一下:应用程序已经在使用Windows集成安全性,而不是Forms.我想要完成的是所谓的"升级"身份验证,或针对以下场景的"强制重新身份验证":

  1. 用户正在浏览网站,做一些普通的,琐碎的事情
  2. 突然,用户必须执行敏感操作,例如授权资源分配或确认汽车贷款或类似的东西
  3. 在将用户重定向到敏感页面之前,系统会提示用户输入凭据,其方式类似于SharePoint的"以其他用户身份登录"
  4. 如果且仅当输入的凭证与当前登录的用户相同时,应用程序才会进入敏感区域.

这样可以防止以下两个问题:

  1. 用户去参加会议或喝咖啡并忘记锁定工作站,同事使用会话来访问敏感区域
  2. 用户输入他或她的老板的凭证(因为,让我们说他偷看了老板的sholder)来访问敏感区域.

我知道,有些人会认为这是"偏执狂",但有些人会说它是常识,应该在某个地方构建(jQuery或.NET)

我真的很感激任何输入.谢谢!

asp.net-mvc windows-authentication pre-authentication

6
推荐指数
1
解决办法
1326
查看次数

Spring Security Java配置

我正在尝试使用JavaConfig代替Spring配置的XML配置.我想@PreAuthorization用于声明访问权限.

我的Spring Security Config看起来像这样:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity( prePostEnabled = true )
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void registerAuthentication( AuthenticationManagerBuilder auth ) throws Exception {
        auth
            .inMemoryAuthentication()
            .withUser( "user" ).password( "password" ).roles( "USER" );
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用.部署Web应用程序后,我收到错误消息Error creating bean with name 'methodSecurityInterceptor' defined in class path resource.

经过一些研究,我发现我必须将aopalliance库添加到我的项目中.不幸的是,这并没有解决我的问题.

这是完整的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method …
Run Code Online (Sandbox Code Playgroud)

spring spring-security pre-authentication spring-java-config

5
推荐指数
2
解决办法
2万
查看次数

Spring Security中有多个pre-auth过滤器?

我需要有多个PRE_AUTHSpring Security过滤器.特别是PRE_AUTH除了PRE_AUTH在Spring Security 3.0的SAML扩展中配置的两个过滤器之外,我还需要使用过滤器.现有的SAML配置如下.

<security:http entry-point-ref="samlEntryPoint">
    <!-- snip intercepts -->
    <security:custom-filter after="BASIC_AUTH_FILTER" ref="samlProcessingFilter"/>
    <security:custom-filter before="PRE_AUTH_FILTER" ref="samlEntryPoint"/>
    <security:custom-filter position="PRE_AUTH_FILTER" ref="metadataFilter"/>
    <security:custom-filter after="LOGOUT_FILTER" ref="samlLogoutFilter"/>
    <security:custom-filter before="LOGOUT_FILTER" ref="samlLogoutProcessingFilter"/>
</security:http>
Run Code Online (Sandbox Code Playgroud)

PRE_AUTH需要在任一现有过滤器之前检查附加过滤器(即:使用此身份验证方法进行身份验证的用户不应有机会使用SAML.

我考虑过以下方式改变它.

<!-- snip -->
<security:custom-filter before="PRE_AUTH_FILTER" ref="newPreAuthFilter"/>
<security:custom-filter position="PRE_AUTH_FILTER" ref="samlEntryPoint"/>
<security:custom-filter after="PRE_AUTH_FILTER" ref="metadataFilter"/>
<!-- snip -->
Run Code Online (Sandbox Code Playgroud)

这是否有效,或者是否需要更复杂的解决方案.

spring-security saml pre-authentication spring-saml

5
推荐指数
1
解决办法
7384
查看次数

WebSphere 上的 Spring Security 预身份验证过滤器示例?

有人有适用于 WebSphere 的 Spring Security 示例 PreAuthentication Filter (WebSpherePreAuthenticatedProcessingFilter) 吗?关于它的文档很少,我似乎无法确定它。我正在寻找能够正常工作并且可能愿意提供您的配置示例的人。非常适合 Spring 3.1 和 WAS 7 或 8。

我有一个配置,看起来它“有点”工作。我可以使用 WebSphere 进行身份验证,然后在我的应用程序中点击 URL,但浏览器返回以下消息:

错误 500:java.lang.RuntimeException:查找用户组时发生异常

我得到如下异常堆栈跟踪:

java.lang.RuntimeException: Error while invoking method java.lang.reflect.Method.getGroupsForUser([UNAUTHENTICATED])
    at org.springframework.security.web.authentication.preauth.websphere.DefaultWASUsernameAndGroupsExtractor.invokeMethod(DefaultWASUsernameAndGroupsExtractor.java:147) [spring-security-web-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.security.web.authentication.preauth.websphere.DefaultWASUsernameAndGroupsExtractor.getWebSphereGroups(DefaultWASUsernameAndGroupsExtractor.java:115) [spring-security-web-3.1.3.RELEASE.jar:3.1.3.RELEASE]
    at org.springframework.security.web.authentication.preauth.websphere.DefaultWASUsernameAndGroupsExtractor.getWebSphereGroups(
...

Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) ~[na:1.6.0]
...

Caused by: com.ibm.websphere.security.EntryNotFoundException: null
    at com.ibm.ws.wim.registry.util.MembershipBridge.getGroupsForUser(MembershipBridge.java:293) ~[com.ibm.ws.runtime.wim.core.jar:201207200704]
...

[12/28/12 14:05:15:879 CST] 00000055 LocalTranCoor E   WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[12/28/12 14:05:15:879 CST] 00000055 webapp        E …
Run Code Online (Sandbox Code Playgroud)

websphere spring-security websphere-7 pre-authentication websphere-8

5
推荐指数
1
解决办法
7016
查看次数

使用Spring Security进行预身份验证/单点登录

我正在开发两个Web应用程序,其中一个是服务器应用程序,另一个是客户端应用程序,两者都使用Spring Security.我的用例是这样的,用户登录服务器应用程序后,用户可以从服务器应用程序内的链接访问客户端应用程序.由于用户在点击这些链接(我的部分要求)时不必再次登录,因此我决定使用类似于Single SignOn的策略,以便将其身份验证信息从服务器应用转发到客户端应用.

在客户端应用程序上,我使用Spring Security RequestHeaderAuthenticationFilter来查找由服务器应用程序设置的自定义请求标头.

  1. 如果找到此自定义标头,是否必须进一步验证此请求是否值得信任?在Spring的预身份验证文档中, RequestHeaderAuthenticationFilter不执行任何身份验证,并假定请求来自SM_USER属性中指定的用户.我如何确保请求是真实的?

  2. 如何使用http请求中的自定义标头将用户从一个应用程序发送到另一个应用程序?重定向请求不起作用,因为标头信息将丢失.转发不起作用,因为转发的请求不通过客户端应用程序上配置的Spring Security过滤器,因此请求永远不会"经过身份验证",也不会创建会话.

spring-security single-sign-on pre-authentication

3
推荐指数
1
解决办法
1万
查看次数

Spring Security 预认证账户锁检查

新手问题...我已经成功实现了自定义处理程序和服务(自定义用户详细信息服务、身份验证成功、身份验证失败)并且一切正常。我现在还实现了一个功能,如果他们 3 次并发身份验证失败,将锁定一个帐户(一段时间)。

我现在继续处理用户在拥有帐户锁定时尝试进行身份验证的情况。如果锁定处于活动状态,则不应尝试进行身份验证并将用户重定向到锁定的帐户页面/错误。如果锁已过期 > 应移除锁并正常进行身份验证

在帐户锁定处于活动状态的情况下 - 我已经尝试在我的自定义身份验证成功处理程序中实现这一点,但尽管已成功将用户转发到帐户锁定错误页面 - 但为时已晚,因为应用程序已经对用户进行了身份验证并且用户是成功地能够直接访问安全页面(这显然是错误的,因为他们的帐户应该被锁定)。

我开始玩,但我想我会先在这里查看更标准/优雅的解决方案/方法。我应该在自定义用户详细信息服务中执行此检查和操作,还是可以在用户点击自定义用户详细信息服务之前实施预身份验证处理程序?关于我在哪里/如何处理这个问题的任何帮助或建议将不胜感激

spring-security pre-authentication

2
推荐指数
1
解决办法
9757
查看次数