Kopiuj
@Controller
@SessionAttributes({"imie", "nazwisko", "listklasy"})
public class HomeController {
public ModelAndView modelAndView;
@Autowired
public SessionGuard sessiong;
@PreAuthorize("hasRole('ROLE_USER')")
public void Test(){
System.out.println("testCONTROLLER");
}
@RequestMapping(value="/", method = RequestMethod.GET)
public String Glowna(Model model)
{
sessiong.tescik(); // Test 1
this.Test(); // Test 2
return "firstpage";
}
}
Kontroler posiada szereg innych metod, jednak nie wnoszą nic one do sprawy, więc pozwoliłem sobie zostawić dwie istotne, wraz ze wszystkimi adnotacjami.
UPDATE
Po skonfigurowaniu WEB.XML w taki sposób zaczyna stosować się do adnotacji:
Kopiuj
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml
/WEB-INF/spring/appServlet/security-context.xml // TO BYLO WCZESNIJ
</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>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml
/WEB-INF/spring/appServlet/security-context.xml // TU DODALEM LINIJKE
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Efektem jak już wspomniałem jest stosowanie się do adnotacji, ale gdy zaloguje się z rolą inna niż wskazana w adnotacji to dostaję 403 - Access is denied.
Kopiuj
DEBUG o.s.s.w.a.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
Konfiguracja intercept-url jest prawodłowa.
Jeżeli nie wywołam metody tescik() oraz Test() wszystko jest ok.
Możliwe, że te konteksty się przełączają i jeden nie wie nic o drugim ?? Od niedawna usiadłem przy tej technologi i za mało czasu jeszcze upłynęło żebym to ogarnął w takim stopniu w jakim bym sobie tego życzył ;) Będę wdzięczny za każdą wskazówkę.