Spring security 更改Spring安全配置
我们在应用程序中有一个典型的需求 我们有两种Spring安全配置: 1.CAS服务器 2.LDAP(NTLM) 因此,现在我们需要检查CAS服务器是否可用,并根据CAS服务器的可用性使用CAS或LDAP安全配置 我试图动态更改入口点url,但是,两个配置文件都使用不同的bean/类 有没有其他方法可以做到这一点 请让我知道我们如何才能实现这一目标,以及如何实现 提前谢谢Spring security 更改Spring安全配置,spring-security,Spring Security,我们在应用程序中有一个典型的需求 我们有两种Spring安全配置: 1.CAS服务器 2.LDAP(NTLM) 因此,现在我们需要检查CAS服务器是否可用,并根据CAS服务器的可用性使用CAS或LDAP安全配置 我试图动态更改入口点url,但是,两个配置文件都使用不同的bean/类 有没有其他方法可以做到这一点 请让我知道我们如何才能实现这一目标,以及如何实现 提前谢谢 Raj您可以创建一个DelegatingAuthenticationEntryPoint,该EntryPoint将在CAS服务
Raj您可以创建一个DelegatingAuthenticationEntryPoint,该EntryPoint将在CAS服务器启动时委托给标准CasAuthenticationEntryPoint,或者以其他方式委托给LoginUrauThenticationEntryPoint。实现如下所示
public class DelegatingAuthenticationEntryPoint implements AuthenticationEntryPoint {
private AuthenticationEntryPoint casAuthenticationEntryPoint;
private AuthenticationEntryPoint ldapAuthenticationEntryPoint;
public DelegatingAuthenticationEntryPoint(AuthenticationEntryPoint casAuthenticationEntryPoint,
AuthenticationEntryPoint ldapAuthenticationEntryPoint) {
this.casAuthenticationEntryPoint = casAuthenticationEntryPoint;
this.ldapAuthenticationEntryPoint = ldapAuthenticationEntryPoint;
}
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
if(casServerAvailable()) {
casAuthenticationEntryPoint.commence(request, response, authException);
} else {
ldapAuthenticationEntryPoint.commence(request, response, authException);
}
}
private boolean casServerAvailable() {
// TODO implement this method
return false;
}
}
然后使用入口点ref属性连接DelegatingAuthenticationEntryPoint,类似于以下内容:
<sec:http entry-point-ref="delegateEntryPoint">
...
</sec:http>
<bean id="delegateEntryPoint" class="sample.DelegatingAuthenticationEntryPoint">
<constructor-arg>
<bean class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"
p:serviceProperties-ref="serviceProperties"
p:loginUrl="https://example.com/cas/login" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"
p:loginFormUrl="/login"/>
</constructor-arg>
</bean>
...