Results 1 to 10 of 26

Thread: Authentication is not working, spring-security, spring mvc, hibernate, stringTemplate

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    23

    Default Authentication is not working, spring-security, spring mvc, hibernate, stringTemplate

    Hi, I am a newbie in spring,
    Authentication is not working, what is going on, i don`t know where is the problem. Help me I`m using spring mvc 2.5 spring-security 2.0, Hibernate 3.0 and stringTemplate.

    Here is my code:
    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    	 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<context-param> 
    		<param-name>contextConfigLocation</param-name> 
    		<param-value> 
    			/WEB-INF/jshop-servlet.xml,
    			/WEB-INF/applicationContext-security.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>encoding-filter</filter-name>
            <filter-class>
                org.springframework.web.filter.CharacterEncodingFilter
            </filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>encoding-filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
    	<servlet> 
    		<servlet-name>jshop</servlet-name> 
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    		<load-on-startup>1</load-on-startup> 
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>jshop</servlet-name> 
    		<url-pattern>*.html</url-pattern>
    	</servlet-mapping> 
    		
    	<welcome-file-list> 
    		<welcome-file>index.html</welcome-file>
    	</welcome-file-list> 
    	
    </web-app>
    applicationContext-security.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    
    <beans:beans xmlns="http://www.springframework.org/schema/security" 
    	xmlns:beans="http://www.springframework.org/schema/beans" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    		http://www.springframework.org/schema/security 
    		http://www.springframework.org/schema/security/spring-security-2.0.2.xsd"> 
    
    	<global-method-security secured-annotations="enabled"></global-method-security> 
    	<http auto-config="true">
    		 
    		<intercept-url pattern="/logged*" access="ROLE_USER,ROLE_ADMIN"  />
    		<intercept-url pattern="/**" access="ROLE_ANONYMOUS" /> 
    <!--		<intercept-url pattern="/add_product.html" access="ROLE_ADMIN" />-->
    		
    		<logout logout-success-url="/login.html" /> 
    		<form-login authentication-failure-url="/login.html?login_error=1" 
    		login-page="/login.html" default-target-url="/logged.html" /> 
    	</http> 
    	
    	
    	<authentication-provider> 
    		<jdbc-user-service data-source-ref="myDataSource" 
    			users-by-username-query="select username, password, enabled from users where username=?" /> 
    	</authentication-provider> 
    </beans:beans>
    login.st
    Code:
    	Log in: 
    	<form action="j_spring_security_check"> 
    	$if(login_error)$
    		<br />
    		<b>Wrong login or password!</b><br />
    	$endif$ 
    	
    	<table> 
    		<tr> 
    			<td> <label for="j_username">Username: </label> </td> 
    			<td> <input type="text" name="j_username" id="j_username" /> </td> 
    		</tr> 
    		<tr> 
    			<td> <label for="j_password">Password: </label> </td> 
    			<td> <input type="password" name="j_password" id="j_password"/> </td> 
    		</tr>
    		<!--<tr> <td> <input type='checkbox' name='_spring_security_remember_me'/>  </td><td> Remember me on this computer. </td></tr>-->
    		<tr> 
    			<td> <input class="button" type="submit" value="Login"/> </td> 
    		</tr> 
    	</table> 
    
    </form>
    logged.st
    Code:
    	<div id="posts">
    		 
    		[ <a href="j_spring_security_logout"><b>logout</b></a> ]								
    		
    		<br /><br /> You are logged! :) 
    		
    		<sec:authorize ifAllGranted="ROLE_ADMIN">
    			<p>Administrator</p>
    	    </sec:authorize>	
    		
    		<sec:authorize ifAllGranted="ROLE_USER">
    			<p>User</p>
    	    </sec:authorize>
    	    
    	</div>
    please help me!!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    For starters your setup is wrong. Don't let the contextloaderlistener load the servlet configuration, this will duplicate your beans and configuration.
    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
    Apr 2010
    Location
    Poland
    Posts
    23

    Default

    thanks for replay, but what do you mean by this?? if i remove listener then application stop working. sorry for this question, maybe stupid but as i wrote i am newbie in it.

  4. #4
    Join Date
    Apr 2010
    Posts
    22

    Default

    Quote Originally Posted by Marten Deinum View Post
    For starters your setup is wrong. Don't let the contextloaderlistener load the servlet configuration, this will duplicate your beans and configuration.
    Not if you have two different configurations. One for servlets and other for contextloaderlistener. Just don't put any beans to configuration that is meant for servlets, beans inside contextlistener loaded config will still be available to servlets.

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Your contextloaderlistener is configured to load 2 xmls files one is the -servlet.xml which is ALSO loaded by the dispatcherservlet. The contextloaderlistener mustn't load this xml file.
    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

  6. #6
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    23

    Default

    it`s not working i don`t know what to do ;/ maybe a don`t understand what you are talking about, please give me another hint, if you can of course

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    1) What isn't working?
    2) Post your configuration.
    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

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
  •