SpringSecurity3.X-前台与后台老板登录认证(转载)
SpringSecurity3.X--前台与后台登录认证(转载)不过一般我们在管理系统时都会分前台与后台,也就是说,前台与
SpringSecurity3.X--前台与后台登录认证(转载)
不过一般我们在管理系统时都会分前台与后台,也就是说,前台与后台的登录入口与注销地址都是不一样的,那么该如何使用SpringSecurity实现呢,参考了一些网络上的例子,将之前的小应用做了如下修改:
applicationContext-security.xml
public?class?LoginUrlEntryPoint?implements?AuthenticationEntryPoint?{????????public?void?commence(HttpServletRequest?request,?HttpServletResponse?response,????????????????AuthenticationException?authException)?throws?IOException,?ServletException?{??????????String?targetUrl?=?null;??????????String?url?=?request.getRequestURI();??????????????if(url.indexOf("admin")?!=?-1){??????????????//未登录而访问后台受控资源时,跳转到后台登录页面??????????????targetUrl?=?"/admin/login.do";??????????}else{??????????????//未登录而访问前台受控资源时,跳转到前台登录页面??????????????targetUrl?=?"/login.do";??????????}??????????????targetUrl?=?request.getContextPath()?+?targetUrl;??????????response.sendRedirect(targetUrl);??????}????}?