0

I am using Spring Security and my method level security is not working using PreAuthorize or Secured.

@PreAuthorize("hasRole('ROLE_USER')")

But it is working from the security-context.xml as:

<security:intercept-url pattern="/fillinvoice" access="hasRole('ROLE_USER')"></security:intercept-url>

I have global security on as :

<global-method-security pre-post-annotations="enabled" secured-annotations="enabled" jsr250-annotations="enabled"/>

I know there are many posts like this and I have read them and Spring FAQs but unable to figure out. Kindly help.. My context file as below:

<global-method-security pre-post-annotations="enabled" secured-annotations="enabled" jsr250-annotations="enabled"/>

<context:annotation-config/>
<context:component-scan base-package="com.inventory" />
    <security:http auto-config="false" use-expressions="true">
        <security:intercept-url pattern="/login" access="permitAll"></security:intercept-url>
        <security:intercept-url pattern="/fillinvoice" access="hasRole('ROLE_USER')"></security:intercept-url>


        <security:form-login login-page="/login"
            always-use-default-target="true" default-target-url="/fillinvoice"
            authentication-failure-url="/accessdenied"
            authentication-success-handler-ref="authSuccessHandler"></security:form-login>

        <security:logout  invalidate-session="true" success-handler-ref="myCustomLogoutSuccessHandler"></security:logout>


    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider user-service-ref="authenticationCheck" />
    </security:authentication-manager>

    <beans:bean id="authenticationCheck" class="com.inventory.dao.impl.HibernateDaoImpl" ></beans:bean>
    <beans:bean id="authSuccessHandler"  class="com.inventory.security.SuccessAuthenticationHandler"></beans:bean>
    <beans:bean id="myCustomLogoutSuccessHandler"  class="com.inventory.security.MyCustomLogoutSuccessHandler"></beans:bean>

</beans:beans>
Saurabh Singhal
  • 271
  • 1
  • 5
  • 18

0 Answers0