Spring + Spring Security + Tile. How to set login form with tile page definition?

I have a spring_tiles web application and am trying to add spring security to it:

This is the world of my TilesConfig.xml:

 <definition name="loginPage" extends="commonPage">
  <put-attribute name="body" value="/WEB-INF/tiles/jsp/login_body.jsp" />
 </definition> 

Here is my spring mapping part:

<bean id="urlMapping"
  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="interceptors">
   <list>
    <ref bean="openSessionInViewInterceptor" />
   </list>
  </property>
  <property name="mappings">
   <props>
    <prop key="/main.htm">mainController</prop>
    <prop key="/category.htm">viewCategoryController</prop>
    <prop key="/good.htm">goodController</prop>
    <prop key="/registration.htm">registrationController</prop>
    <prop key="/login.htm">?</prop>
   </props>
  </property>
 </bean>

And here is the part from the context-security.xml application:

 <http auto-config='true'>
  <intercept-url pattern="/**" access="ROLE_USER" />
  <intercept-url pattern="/css/**" filters="none"/>
  <intercept-url pattern="/js/**" filters="none"/>
  <intercept-url pattern="/login.htm*" filters="none"/>
  <form-login login-page="/login.htm" />
 </http>

But I am wondering how can I configure the definition of the tile page for matching. I have used controllers on all other pages, but I believe that in this case I should not use loginController, because spring Security is instead.

So here is my question: how to map loginPage tiles to /login.htm in spring security?

+3
source share
3 answers

. spring :

<bean id="loginController"
    class="org.springframework.web.servlet.mvc.ParameterizableViewController">
    <property name="viewName" value="loginPage" />
</bean>

:

<prop key="/login.htm">loginController</prop>

.

0

spring spring .

loginPage, , - applicationContext-security.xml

<intercept-url pattern="/loginPage" filters="none"/>
<form-login login-page="/loginPage" />

spring, URL- POST, /j_spring_security_check ( ). loginController.

+2

- :

@Controller
@RequestMapping("/login")
public class LoginController {

    @RequestMapping(method = RequestMethod.GET)
    public String login(Locale locale, Model model) {
        return "login";
    }

    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public String loginWithError(Locale locale, Model model) {
        model.addAttribute("error", true);
        return "login";
    }
}

security-context.xml -login :

<form-login login-page="/login" authentication-failure-url="/login/error" />

views.xml :

<definition name="login" extends="template">
    <put-attribute name="title" value="Nuevo Usuario"/>
    <put-attribute name="body" value="/login.jsp"/>
</definition>

, login.jsp, , , :

<c:if test="${not empty error}">
    <font color="red"> Error al ingresar. <br /> Motivo :
        ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
    </font>
</c:if>
+1

Source: https://habr.com/ru/post/1788127/


All Articles