spring-mvcspring-securitysitemesh

Sitemesh header and footer should not append to login screen


I am using sitemesh in my project. Everything working fine but decorator page appending to login screen. I don't want header and footer for my login screen as i am using spring security for login. Please help me how to omit login screen from sitemesh decorator.

I am attaching all my files here.

web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-config.xml</param-value>
    </context-param> 

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>
            com.opensymphony.module.sitemesh.filter.PageFilter
        </filter-class>
    </filter>

    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>springmvcdispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvcdispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  

</web-app>

Spring-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


    <context:property-placeholder location="classpath:resources/database.properties" />
    <tx:annotation-driven transaction-manager="hibernateTransactionManager"/>


    <security:http auto-config="true">
        <security:intercept-url pattern="/index*" access="ROLE_ADMIN,ROLE_USER" />
        <security:form-login login-page="/login" default-target-url="/index"
            authentication-failure-url="/loginError"/>
            <security:logout logout-success-url="/logout" />
    </security:http>

    <!-- <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="Admin" password="Admin" authorities="ROLE_ADMIN" />
                <security:user name="main" password="password" authorities="ROLE_ADMIN" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager> -->


    <security:authentication-manager>
      <security:authentication-provider>       
        <security:jdbc-user-service data-source-ref="dataSource"  
            users-by-username-query="select username,password, enabled from user where username=?" 
            authorities-by-username-query="select username, role from user_role where username =?" 
        />
      </security:authentication-provider>
    </security:authentication-manager>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />     
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>     
                <prop key="hibernate.query_factory_class">${hibernate.query_factory_class}</prop>
                <prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>       
            </props>
        </property>
        <property name="packagesToScan" value="com.dineshonjava.model"></property>
    </bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
        <mvc:resources mapping="/views/**" location="/WEB-INF/views/"/>
        <mvc:resources mapping="/Design/**" location="/Design/" />
         <mvc:default-servlet-handler />
     <mvc:annotation-driven/>   

</beans>

sitemesh.xml

<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml"/>
<excludes file="${decorators-file}"/>
<page-parsers>
    <parser default="true"
        class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
    <parser content-type="text/html"
        class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
</page-parsers>

<decorator-mappers>
    <mapper   class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
        <param name="config" value="${decorators-file}"/>
    </mapper>
</decorator-mappers>
</sitemesh>

decorators.xml

<decorators defaultdir="/WEB-INF/decorators">
    <decorator name="default" page="MyDecorator.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

MyDecorator.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <!DOCTYPE html>
    <html>
    <head>
        <title><decorator:title default="SiteMesh Integration"/></title>
       <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
       <decorator:head/>
    </head>
    <body>

        <div id="header">
            <h1>Header Added By Sitemesh</h1>
        </div>

        <div id="content">
            <decorator:body/>
        </div>

        <div id="Footer">
            <h2>Some Copyright Added By Sitemesh</h2>
        </div>

    </body>
    </html>

Solution

  • I think you can use the exclude to omit login page:

    <decorators defaultdir="/WEB-INF/decorators">
    
        <excludes>
            <pattern>login.jsp</pattern>  <!--exclude login jsp-->
        </excludes>
    
        <decorator name="default" page="MyDecorator.jsp">
            <pattern>/*</pattern>
        </decorator>
    </decorators>