Spring 安全,如何处理基于网络服务的身份验证
Spring Security, how to handle web-service based authentication
我们正尝试在我们的 webflow 应用程序中使用 spring 安全性来实施身份验证和授权。有一项服务将验证用户和 return 相应的用户角色。
但是在这个调用之后是否可以在我们的应用程序中使用 Spring 安全配置,因为所有与 Spring 安全相关的文档都告诉我们需要用户名和密码以及在 xml、属性文件或数据库中预定义的角色。
我可以在会话中存储 returned roll 并完全避免 spring security.But 我想加强应用程序的安全性并让黑客远离。
那么在这种情况下是否可以使用 Spring 安全性?另外,在会话中保留角色的想法怎么样?
请查找示例 Spring 安全性 xml below.Is 验证后 uname/psswrd/role 可以赋值,运行-时间。这样所有后续调用都将由 spring 安全部门处理。
<security:http auto-config="true">
<security:form-login login-page="/spring/login"
login-processing-url="/spring/loginProcess"
default-target-url="/spring/main"
authentication-failure-url="/spring/login?login_error=1" />
<security:logout logout-url="/spring/logout" logout-success-url="/spring/logout-success" />
</security:http>
<security:authentication-provider>
<security:password-encoder hash="md5" />
<security:user-service>
<security:user name="keith" password="417c7382b16c395bc25b5da1398cf076"
authorities="ROLE_USER,ROLE_SUPERVISOR" />
<security:user name="erwin" password="12430911a8af075c6f41c6976af22b09"
authorities="ROLE_USER,ROLE_SUPERVISOR" />
<security:user name="jeremy" password="57c6cbff0d421449be820763f03139eb"
authorities="ROLE_USER" />
<security:user name="scott" password="942f2339bf50796de535a384f0d1af3e"
authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
http://www.baeldung.com/spring-security-authentication-provider,这会涵盖我的情况吗?
您可以使用 Spring- 安全。如果你可以 tweek 你的服务,以便它提供密码而不是检查它,你唯一需要做的就是实现你自己的 UserDetailsService
.
仅以 Spring 安全配置为例,使用 JdbcDaoImpl
-UserDetailsService
或 InMemoryDaoImpl
-UserDetailsService
,然后替换它们通过您调用网络服务的 UserDetailsService
。
如果您无法提供密码,则需要 implement/configure 自己 AuthenticationProvider
. Either you use the RemoteAuthenticationProvider
or implement a subclass of AbstractUserDetailsAuthenticationProvider
。
我推荐RemoteAuthenticationProvider
方式:
<http>
...
<security:authentication-provider ref="remoteAuthenticationProvider" />
</http>
<bean id="remoteAuthenticationProvider" class="org.springframework.security.authentication.rcp.RemoteAuthenticationProvider">
<property name="remoteAuthenticationManager" ref="myRemoteAuthenticationManager" />
</bean>
<bean id="myRemoteAuthenticationManager" class="MyRemoteAuthenticationManager"/>
您只需实施实施 RemoteAuthenticationManager
的 MyRemoteAuthenticationManager
。接口 RemoteAuthenticationManager
只有一种方法:
Collection<? extends GrantedAuthority> attemptAuthentication(String username,
String password)
throws RemoteAuthenticationException;
在您的实现中,此方法必须调用您的网络服务。
我们正尝试在我们的 webflow 应用程序中使用 spring 安全性来实施身份验证和授权。有一项服务将验证用户和 return 相应的用户角色。
但是在这个调用之后是否可以在我们的应用程序中使用 Spring 安全配置,因为所有与 Spring 安全相关的文档都告诉我们需要用户名和密码以及在 xml、属性文件或数据库中预定义的角色。
我可以在会话中存储 returned roll 并完全避免 spring security.But 我想加强应用程序的安全性并让黑客远离。
那么在这种情况下是否可以使用 Spring 安全性?另外,在会话中保留角色的想法怎么样?
请查找示例 Spring 安全性 xml below.Is 验证后 uname/psswrd/role 可以赋值,运行-时间。这样所有后续调用都将由 spring 安全部门处理。
<security:http auto-config="true">
<security:form-login login-page="/spring/login"
login-processing-url="/spring/loginProcess"
default-target-url="/spring/main"
authentication-failure-url="/spring/login?login_error=1" />
<security:logout logout-url="/spring/logout" logout-success-url="/spring/logout-success" />
</security:http>
<security:authentication-provider>
<security:password-encoder hash="md5" />
<security:user-service>
<security:user name="keith" password="417c7382b16c395bc25b5da1398cf076"
authorities="ROLE_USER,ROLE_SUPERVISOR" />
<security:user name="erwin" password="12430911a8af075c6f41c6976af22b09"
authorities="ROLE_USER,ROLE_SUPERVISOR" />
<security:user name="jeremy" password="57c6cbff0d421449be820763f03139eb"
authorities="ROLE_USER" />
<security:user name="scott" password="942f2339bf50796de535a384f0d1af3e"
authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
http://www.baeldung.com/spring-security-authentication-provider,这会涵盖我的情况吗?
您可以使用 Spring- 安全。如果你可以 tweek 你的服务,以便它提供密码而不是检查它,你唯一需要做的就是实现你自己的 UserDetailsService
.
仅以 Spring 安全配置为例,使用 JdbcDaoImpl
-UserDetailsService
或 InMemoryDaoImpl
-UserDetailsService
,然后替换它们通过您调用网络服务的 UserDetailsService
。
如果您无法提供密码,则需要 implement/configure 自己 AuthenticationProvider
. Either you use the RemoteAuthenticationProvider
or implement a subclass of AbstractUserDetailsAuthenticationProvider
。
我推荐RemoteAuthenticationProvider
方式:
<http>
...
<security:authentication-provider ref="remoteAuthenticationProvider" />
</http>
<bean id="remoteAuthenticationProvider" class="org.springframework.security.authentication.rcp.RemoteAuthenticationProvider">
<property name="remoteAuthenticationManager" ref="myRemoteAuthenticationManager" />
</bean>
<bean id="myRemoteAuthenticationManager" class="MyRemoteAuthenticationManager"/>
您只需实施实施 RemoteAuthenticationManager
的 MyRemoteAuthenticationManager
。接口 RemoteAuthenticationManager
只有一种方法:
Collection<? extends GrantedAuthority> attemptAuthentication(String username,
String password)
throws RemoteAuthenticationException;
在您的实现中,此方法必须调用您的网络服务。