Announcement Announcement Module
Collapse
No announcement yet.
integrading interceptor to web requests in spring 3.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • integrading interceptor to web requests in spring 3.0

    Hi,

    Currently I am working on a web project and using spring 3.0 with annotation bases controllers.

    1. I am trying to use intercept for login.
    2. No url can be directly hit but from login using interceptor.

    I am able to write an interceptor which won't let pass anyone to move into website without giving required parameters for login. But problem is that, remaining pages can also be accessed directly.

    I am sharing with you my servlet.xml

    I am also wondering why I have to defien URL mappings to get interceptor working, otherwise it goes into a unlimited loop.

    please help me out in solving this issue, if you have any working example for this requirement, then please share it too.

    Thank you in advance.

    springmvc-servlet.xml

    Code:
    <?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"
        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">
     
        <context:component-scan
            base-package="com.waqas.app.controller" />
     
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass"
                value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
        
        
          
           	<bean id="urlMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="urlMap">
    			<map>
    		<!--  -->	
    			<entry key="contacts.htm"><ref bean="contactController" /></entry>
    			 		<entry key="users.htm"><ref bean="loginController" /></entry>
    			 		
    					 		<entry key="hello.htm"><ref bean="helloController" /></entry>
    		 
    				
    			</map>
    		</property>
    	</bean>
       
        	
      	<bean name="contactController" class="com.waqas.app.controller.ContactController" />
    	
         	<bean name="helloController" class="com.waqas.app.controller.HelloWorldController" />
       
       
       <bean name="loginController" class="com.waqas.app.controller.LoginController" />
         
         
            
            <bean id="handlerMapping"
              class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="loginInterceptor"/>
                </list>
            </property>
              <property name="mappings">
                <value>
        
                *.htm=contactController
                
                </value>
            </property>
    
        </bean>
        
      
    
        <bean id="loginInterceptor"
              class="com.waqas.app.interceptor.LoginInterceptor">
        
        </bean>
       
            
        
        
        
        
    </beans>

    index.html

    HTML Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <jsp:forward page="contacts.htm"></jsp:forward>

  • #2
    The only page protected is the contacts page everything else is freely available, there is no interceptor for those pages.

    Also why are you reinventing the wheel, why not simply use Spring Security....

    Comment


    • #3
      how can I protect other pages along with contact page.

      I was looking into this, but can't find anything about it.

      I'll be grateful if you help me in this.

      Kind Regards,
      qasibeat

      Comment


      • #4
        As I stated...

        Originally posted by mdeinum

        The only page protected is the contacts page everything else is freely available, there is no interceptor for those pages.
        YOu haven't defined an interceptor..

        I also still strongly suggest spring security instead of reinventing the wheel...

        Comment


        • #5
          Code:
          YOu haven't defined an interceptor..
          
          I also still strongly suggest spring security instead of reinventing the wheel...
          Can You/anyone please guide me how to define interceptor and whats wrong in my configuration.

          Comment

          Working...
          X