2015-08-31 235 views
1

在我的应用程序要进行身份验证的索引页面,以便在上下文中我添加如何验证索引页:使用弹簧安全

<!-- Security --> 
<security:http create-session="never" use-expressions="true"> 
    <security:intercept-url pattern="/index.jsp" access="hasRole('MY_ROLE')" /> 
    <security:http-basic entry-point-ref="basicAuthenticationEntryPoint" /> 
</security:http> 

该工程确定,当我去地址:http://localhost:31103/my_app/index.jsp

问题当我输入地址http://localhost:31103/my_app/哪些重定向到索引然后没有验证。那么我应该如何验证这些情况呢?

回答

0

尝试改变intercept-url pattern"/"

0

相反,当用户进入http://localhost:31103/my_app/他重定向到登录页面,然后检查,如果用户已经通过身份验证,如果是他重定向到索引页面重定向用户到索引页。

@RequestMapping(value = "/login") 
public ModelAndView login(HttpServletRequest arg0, HttpServletResponse arg1) { 

    ModelAndView model = new ModelAndView("login"); 
    Authentication auth=SecurityContextHolder.getContext().getAuthentication(); 

    if(!(auth instanceof AnonymousAuthenticationToken)){ 
     model.setViewName("redirect:/index"); 
    } 

    return model; 
} 
+0

我有没有登录页面。我正在使用基本身份验证 – hudi

+0

@hudi尝试将索引页放在新文件夹中,让我们调用该文件夹的管理员,然后像这样设置安全性。' – redMist

+0

sory我不能移动索引页面 – hudi