@Controllerのメソッドで@Securedが読み込まれていないように見えます。 sec:intercept-urlに基づくセキュリティフィルタリングが使用されている場合、これは正常に動作しているようです。@Securedはコントローラでは機能しませんが、intercept-urlは正常に動作しているようです。
DEBUG:: - 公共オブジェクト - 認証
ウェブをしようとしないorg.springframework.security.web.access.intercept.FilterSecurityInterceptor春のセキュリティに次のコードの結果は、私にこのログエントリを与えます。 XML
contextConfigLocation /WEB-INF/spring/root-context.xml
<!-- 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
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Filter security -->
<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>
サーブレットのcontext.xmlはviewResolversと、すべてのマーシャリングの設定を保持します。この設定はアノテーション駆動です。
ルートのcontext.xml
<sec:global-method-security secured-annotations="enabled" />
<sec:http auto-config="true">
<sec:http-basic/>
</sec:http>
<!-- Declare an authentication-manager to use a custom userDetailsService -->
<sec:authentication-manager>
<sec:authentication-provider
user-service-ref="userDetailsService">
<sec:password-encoder ref="passwordEncoder" />
</sec:authentication-provider>
</sec:authentication-manager>
<bean
class="org.springframework.security.authentication.encoding.PlaintextPasswordEncoder"
id="passwordEncoder" />
<sec:user-service id="userDetailsService">
<sec:user name="john" password="john" authorities="ROLE_USER, ROLE_ADMIN" />
<sec:user name="jane" password="jane" authorities="ROLE_USER" />
</sec:user-service>
PingController.java
@Controller
public class PingController {
@Secured("ROLE_ADMIN")
@RequestMapping(value = "/ping", method = RequestMethod.GET)
public void ping() {
}
}
これは私が使用している認証方式とは関係を持っているように見える、そうしませんbasic-http-tagを見落とすことができます。
@Securedは、セキュリティが設定されているroot-context.xml以外のコンテキストで使用されているため、@ Secureが機能しないという考えがあります。この設定をservlet-context.xmlに移そうとしましたが、springSecurityFilterChainに到達していないようです。問題と私の理論の考え?
スポットオン。ありがとう、@axtavt! – kareblak
素晴らしい!ありがとう:) – Athar
Javaの設定方法を使用している場合は、 'WebMvcConfigurerAdapter'を拡張する設定クラスに' @ EnableGlobalMethodSecurity'アノテーションを追加することができます。 – beat