Znalazłem wiele podobnych pytań, ale żaden nie rozwiązał mojego problemu. Mój problem jest ROLE_USER
mogą uzyskać dostęp do funkcji ROLE_ADMIN
@PreAuthorize adnotacji nie działa ochrona wiosny
mojego kodu wiosna-security.xml jest następujący.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<s:http auto-config="true" use-expressions="true">
<s:intercept-url pattern="/index.jsp" access="permitAll" />
<s:intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')" />
<s:intercept-url pattern="/helloadmin*" access="hasRole('ROLE_ADMIN')" />
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:authentication-manager>
<s:authentication-provider>
<s:user-service>
<s:user name="asif" password="123456" authorities="ROLE_USER,ROLE_ADMIN" />
<s:user name="raheel" password="123456" authorities="ROLE_USER" />
</s:user-service>
</s:authentication-provider>
</s:authentication-manager>
kiedy dodać <s:global-method-security pre-post-annotations="enabled"/>
mój kod pokazuje zasobu nie znaleziono błąd i kiedy usunąć mój kod wykonać pomyślnie ale ROLE_USER
mogą uzyskać dostęp ROLE_ADMIN
funkcje
Moja funkcja jest kontroler.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value="/delete", method = RequestMethod.GET)
public String DeleteAll(ModelMap model, Principal principal) {
org.springframework.security.core.userdetails.User activeUser = (org.springframework.security.core.userdetails.User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
System.out.println("Active user is "+activeUser.getUsername()+"Authorities are "+activeUser.getAuthorities());
return "deleteUsers";
}
Tak wiem, ale kiedy dodać mój kod pokazuje zasobu nie znaleziono błąd, wiesz jak to naprawić? –
Raheel
Zainicjowane zdarzenie inicjowania kontekstu wyjątku do instancji odbiornika klasy org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: nieoczekiwane przetwarzanie wyjątku dokumentu XML z zasobu ServletContext [/WEB-INF/spring-security.xml ]; Zagnieżdżony wyjątek to java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor – Raheel
i używam zabezpieczenia spring3.07 – Raheel