3

I am upgrading the Spring-Security version from 3.2.5 to 4.0.1. Unfortunately I have stumbled across a road-block and I would appreciate your help. I am posting the error log, the securityApplicationContext.xml and pom.xml. Kindly have a look.

Error log :

javax.servlet.ServletException: java.lang.NoSuchMethodError: org.springframework.security.web.access.expression.WebSecurityExpressionRoot.setDefaultRolePrefix(Ljava/lang/String;)V
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.WEB_002dINF.views.common.footer_jsp._jspService(footer_jsp.java:231)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

SecurityApplicationContext.xml :

<security:http pattern="/resources/**" security="none"/>

    <security:http create-session="ifRequired" use-expressions="true" auto-config="false" disable-url-rewriting="true">
        <security:form-login login-page="/login" login-processing-url="/j_spring_security_check" default-target-url="/dashboard" always-use-default-target="false" authentication-failure-url="/denied" />
        <security:remember-me key="_spring_security_remember_me" user-service-ref="userDetailsService" token-validity-seconds="1209600" data-source-ref="dataSource"/>
        <security:logout delete-cookies="JSESSIONID" invalidate-session="true" logout-url="/j_spring_security_logout"/>
<!--     <security:intercept-url pattern="/**" requires-channel="https"/> -->
    <security:port-mappings>
        <security:port-mapping http="8080" https="8443"/>
    </security:port-mappings>
    <security:logout logout-url="/logout" logout-success-url="/" success-handler-ref="myLogoutHandler"/>

     <security:session-management session-fixation-protection="migrateSession">
         <security:concurrency-control session-registry-ref="sessionRegistry" max-sessions="5" expired-url="/login"/>
     </security:session-management>


    </security:http>

    <beans:bean id="rememberMeAuthenticationProvider" class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices">
        <beans:constructor-arg index="0" value="_spring_security_remember_me"/>
        <beans:constructor-arg index="1" ref="userDetailsService"/>
        <beans:constructor-arg index="2" ref="jdbcTokenRepository"/>
        <property name="alwaysRemember" value="true"/>
    </beans:bean>

    <!--Database management for remember-me -->
    <beans:bean id="jdbcTokenRepository"
                class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
        <beans:property name="createTableOnStartup" value="false"/>
        <beans:property name="dataSource" ref="dataSource" />
    </beans:bean>

    <!-- Remember me ends here -->
    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider user-service-ref="LoginServiceImpl">
           <security:password-encoder  ref="encoder"/>
        </security:authentication-provider>
    </security:authentication-manager>

    <beans:bean id="encoder"
                class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
        <beans:constructor-arg name="strength" value="11" />
    </beans:bean>

    <beans:bean id="daoAuthenticationProvider"
                class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
                <beans:property name="userDetailsService" ref="LoginServiceImpl"/>
               <beans:property name="passwordEncoder" ref="encoder"/>
    </beans:bean>
</beans>

And POM.xml :

<packaging>war</packaging>
    <properties>
        <java-version>1.8</java-version>
        <org.springframework-version>4.0.6.RELEASE</org.springframework-version>
        <org.aspectj-version>1.7.4</org.aspectj-version>
        <org.slf4j-version>1.7.5</org.slf4j-version>
        <hibernate.version>4.3.9.Final</hibernate.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <springsecurity.version>4.0.1.RELEASE</springsecurity.version>
    </properties>

    <dependencies>
<!-- Spring Mobile dependencies -->

        <dependency>
            <groupId>org.springframework.mobile</groupId>
            <artifactId>spring-mobile-device</artifactId>
            <version>1.1.3.RELEASE</version>
        </dependency>

        <!-- Spring mobile ends here -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
  <!-- Spring security dependenciey -->

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

If there is anything more required, kindly let me know. Thanks a lot. :-)

7
  • 1
    after @smoggers answered you, (he should get the credit), it is now a different question. however, "NoSuchMethodError" - it is a mixed versions of Spring. make sure you have in your classpath the correct versions.... Commented Jul 24, 2015 at 7:52
  • 1
    @OhadR : I will do that once smoggers posts an answer. About mixed versions, I am declaring versions on top and using them throughout. Can you please look at the pom.xml. Thanks.. I just added a spring-security-core dependency. Thanks. Commented Jul 24, 2015 at 7:55
  • 1
    the new error message is to do with incompatible versions between spring and spring-security as @OhadR suggests, I thought using <org.springframework-version>4.0.6.RELEASE</org.springframework-version> with <springsecurity.version>4.0.1.RELEASE</springsecurity.version> would work fine but then I noticed this line in the Spring-Security documentation regarding migration to Spring-Security 4: "Spring Security 4 now requires Spring 4. This means your first step is to update to Spring 4.1.x." My configuration also uses Spring version 4.1.1.RELEASE and works well with Spring-Security. Commented Jul 24, 2015 at 8:22
  • 1
    So in other words looks like you may also have to upgrade your <org.springframework-version> to version 4.1 or above, not 100% sure on this but I think it's your best bet Commented Jul 24, 2015 at 8:23
  • 1
    @smoggers : It worked, but with 4.1.6. About time you prepare an answer ... Thanks a lot.. :-) Commented Jul 24, 2015 at 8:26

2 Answers 2

7

Adding these security packages will solve the issue. more importantly, spring core should be there.

       <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.2.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.2.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>5.2.1.RELEASE</version>
        </dependency>
Sign up to request clarification or add additional context in comments.

Comments

6

Firstly, you also need the spring-security-core dependency within your pom.xml.

Secondly, the error message you are receiving is to do with incompatible versions between Spring and Spring-Security. I thought using

<org.springframework-version>4.0.6.RELEASE</org.springframework-version> with <springsecurity.version>4.0.1.RELEASE</springsecurity.version> as you currently have would work fine but then I noticed this line in the Spring-Security documentation regarding migration to Spring-Security 4:

"Spring Security 4 now requires Spring 4. This means your first step is to update to Spring 4.1.x."

My configuration also uses Spring version 4.1.1.RELEASE and works well with Spring-Security.

Therefore I'd say your best bet is to upgrade your <org.springframework-version> to version 4.1 or above.

4 Comments

Ok, Just one small thing, can you help me out with, then that would be all. The user is unable to login right now, as credentials passed are null, it worked before with 3.2.5 of Spring-security. Here is the log : pastebin.com/7XMrTdWW
I'm at work so will take a look when I can, if it's urgent though then maybe best posting as a new question
It's not urgent, as we are just in process of upgrading spring-security, but I have other tasks as well.. :D Please take a look when you have time. Thanks a lot... :-)
Solved.... Apparently, Spring-security 4.X requires j_username to be migrated to username and same for password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.