2009-11-18 53 views
0

我的系统有2个子系统。每个子系统都有不同的用户组。每个用户都有一个额外的字段“SystemName”,可用于了解该用户属于哪个系统。定制认证

在登录表单(每个子系统的1表单)中,我添加了一个指定表单类型(包含SystemName值)的隐藏字段。

一般来说,检查是相当简单:

if (user.systemName == params.systemName) { 
    proceed with regular login 
} else { 
    throw standard login error 
} 

我试图把那张支票到我的自定义DaoAuthenticationProvider的时候,但它有“params.systemName”无法访问。

我在哪里放置该代码以使Acegi通过此检查验证我的用户?

在此先感谢。

回答

1

这就是我在Java中所做的。扩展WebAuthenticationDetails

import javax.servlet.http.HttpServletRequest; 
import org.acegisecurity.ui.WebAuthenticationDetails; 

public class SystemNameWebAuthenticationDetails extends WebAuthenticationDetails { 

    public SystemNameWebAuthenticationDetails() { 
     super(); 
    } 

    public SystemNameWebAuthenticationDetails(HttpServletRequest request) { 
     super(request); 
     this.systemName = request.getParameter("systemName"); 
    } 

    public String getSystemName() { 
     return systemName; 
    } 

    private String systemName; 
} 

将其设置在验证过滤器:

<bean id="authenticationProcessingFilter" 
     class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"> 
     ... 
     <property name="authenticationDetailsSource"> 
     <bean class="org.acegisecurity.ui.AuthenticationDetailsSourceImpl"> 
      <property name="clazz" value="SystemNameWebAuthenticationDetails"/> 
     </bean> 
     </property> 
</bean> 

之后,您可以访问在认证过程中要求的细节,认证对象属性。或者这样做:

SecurityContextHolder.getContext().getAuthentication().getDetails()