Я использую Spring Security, и безопасность на уровне моего метода не работает с использованием PreAuthorize или Secured.
@PreAuthorize("hasRole('ROLE_USER')")
Но он работает из файла security-context.xml следующим образом:
<security:intercept-url pattern="/fillinvoice" access="hasRole('ROLE_USER')"></security:intercept-url>
У меня есть глобальная безопасность как:
<global-method-security pre-post-annotations="enabled" secured-annotations="enabled" jsr250-annotations="enabled"/>
Я знаю, что есть много подобных сообщений, и я прочитал их и ответы на часто задаваемые вопросы Spring, но не смог понять. Пожалуйста, помогите .. Мой файл контекста, как показано ниже:
<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>