Results 1 to 5 of 5

Thread: integrading interceptor to web requests in spring 3.0

  1. #1
    Join Date
    Jul 2010
    Posts
    4

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2010
    Posts
    4

    Default

    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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    As I stated...

    Quote 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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jul 2010
    Posts
    4

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •