Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT&x2B;注销后的Spring安全登录问题_Spring_Gwt_Login_Spring Security - Fatal编程技术网

GWT&x2B;注销后的Spring安全登录问题

GWT&x2B;注销后的Spring安全登录问题,spring,gwt,login,spring-security,Spring,Gwt,Login,Spring Security,我正在使用Spring Security来保护对GWT的第一页应用程序的访问“/HumanResources.html”。它检查用户的凭据是否正确(通过将其与ldap内容进行比较),并查看数据库(自定义授权表)中是否存在该用户 用户首次登录时,没有问题,然后用户注销并显示“.jsp”页面。 但当他想再次访问“HumanResources.html”页面时,身份验证显然被忽略(登录表单不显示),页面被显示。只有接口可见,数据由安全RPC服务检索 这个问题出现在外部Tomcat服务器上(在Firef

我正在使用Spring Security来保护对GWT的第一页应用程序的访问“/HumanResources.html”。它检查用户的凭据是否正确(通过将其与ldap内容进行比较),并查看数据库(自定义授权表)中是否存在该用户

用户首次登录时,没有问题,然后用户注销并显示“.jsp”页面。 但当他想再次访问“HumanResources.html”页面时,身份验证显然被忽略(登录表单不显示),页面被显示。只有接口可见,数据由安全RPC服务检索

这个问题出现在外部Tomcat服务器上(在Firefox和Chrome上测试),但在GWT开发模式下不会出现。CTRL+F5似乎可以工作,我查找了其他缓存问题,但没有帮助

有人能帮我吗

我的安全应用程序context.xml的一部分:

<http use-expressions="true" auto-config="false">
    <intercept-url pattern="/HumanResources.html" access="isAuthenticated()" />
    <form-login 
        login-page='/login.jsp'
        authentication-failure-url = "/login.jsp?login_error=1"
        authentication-success-handler-ref="HRAuthenticationHandler" />
    <logout 
        logout-url="/logout" 
        logout-success-url="/logout.jsp" 
        delete-cookies="JSESSIONID"/>
</http>

<beans:bean id="HRAuthenticationHandler" class="lu.sfeir.candidate.server.auth.HRAuthenticationHandler">
    <beans:property name="useReferer" value="true" />
</beans:bean>

<ldap-server url="${ldap.serverUrl}" manager-dn="${ldap.adminLogin}" manager-password="${ldap.adminPassword}" />

<authentication-manager>
    <ldap-authentication-provider 
        group-search-base="${ldap.groups}"
        user-search-base="${ldap.users}"
        user-search-filter="${ldap.userId}">
    </ldap-authentication-provider>
</authentication-manager>
public class HRAuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Autowired
    private AuthorizedUsersDao usersDao;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException,
            ServletException {

        // Check if the user exist in the DB
        if(usersDao.findUser(((UserDetails)authentication.getPrincipal()).getUsername())) {
            // Redirect to home page
            super.onAuthenticationSuccess(request, response, authentication);
        } else {
            // Redirect to error page
            response.sendRedirect("/spring_security_login?login_error");
        }
    }
}
编辑: 对不起,误会了你。 我挖掘了一下,发现安全性不起作用,因为用户浏览器正在缓存xxx.html页面、js、css等 你可以: 1) 通过设置html标题强制刷新页面: 这是最简单的解决方案,而且由于您使用的是安全的RPC服务,因此应该为您启用。 或者完全禁用缓存

注意它会增加你的网络流量

(二) 我们的应用程序正在检查RPC中是否出现安全错误:

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.InvocationException;

public abstract class CustomAsyncCallback<T> implements AsyncCallback<T> {
    @Override
    public void onFailure(Throwable caught) {
        if (caught instanceof InvocationException) {
            InvocationException ie = (InvocationException) caught;
            if(ie.getMessage().contains("j_spring_security_check")) {
                Window.alert("User session expired, please login again");
                Window.open(GWT.getHostPageBaseURL() + "login.jsp", "_self", null);
                return;
            }
        }
    }
}
import com.google.gwt.core.client.gwt;
导入com.google.gwt.user.client.Window;
导入com.google.gwt.user.client.rpc.AsyncCallback;
导入com.google.gwt.user.client.rpc.InvocationException;
公共抽象类CustomAsyncCallback实现AsyncCallback{
@凌驾
失败时的公共无效(可丢弃){
如果(捕获到调用异常的实例){
调用异常ie=(调用异常)被捕获;
如果(即getMessage()包含(“j_spring\u security\u check”)){
Window.alert(“用户会话已过期,请重新登录”);
open(GWT.getHostPageBaseURL()+“login.jsp”,“self”,null);
返回;
}
}
}
}
在显示当前登录用户时,您必须在某处调用它:

    userSecurityService.getUser(new CustomAsyncCallback<String>() {
        @Override
        public void onSuccess(String result) {
            usrLoginLbl.setText(result);
        }
    });
userSecurityService.getUser(新的CustomAsyncCallback(){
@凌驾
成功时的公共void(字符串结果){
usrloginbl.setText(结果);
}
});

或者您可能会发现您的onFailure方法出现此异常

谢谢您的回复,我已经尝试了您的解决方案,在HumanResources.html中添加了一个访问角色(role_HR),但没有成功:/I重新登录时,身份验证阶段被“跳过”…再次感谢!Html标题可能是最好的解决方案(很少有用户连接到应用程序)。我一直在考虑这个解决方案,但上次尝试时它没有起作用(也许我做错了)。你能告诉我怎么处理吗?我们按照我帖子中的代码来处理。在RPC-In-onFailure中,我们处理安全异常好的!问题是:我不能这样做,因为我没有实现通用自定义RPC,编辑所有onFailure RPC调用可能需要很长时间:/