我想一個CustomWebSecurityExpressionRootUnsupportedOperationException異常javax.servlet.ServletRequest.getServerName()不支持
request.getServerName()
這裏中訪問HttpServletRequest.getServerName()是我的代碼:
public class CustomWebSecurityExpressionRoot extends WebSecurityExpressionRoot {
public CustomWebSecurityExpressionRoot(Authentication a, FilterInvocation fi) {
super(a, fi);
}
public boolean isLocal() {
return "localhost".equals(request.getServerName());
}
}
此表達式根目前正在FilterSecurityInterceptor中設置
@Override
public void configure(final WebSecurity web) throws Exception {
final HttpSecurity http = getHttp();
web.postBuildAction(() -> {
FilterSecurityInterceptor fsi = http.getSharedObject(FilterSecurityInterceptor.class);
fsi.setSecurityMetadataSource(metadataSource);
web.securityInterceptor(fsi);
});
}
然後,我有一個數據庫條目設置「本地和hasRole(」ADMIN「)」它調用此表達式。
看起來有代理包裝ServletRequest作爲「DummyRequest」,並且所有其他方法都不受支持。
但是,當這個被執行,我得到以下錯誤:
java.lang.UnsupportedOperationException: public abstract java.lang.String javax.servlet.ServletRequest.getServerName() is not supported
at org.springframework.security.web.UnsupportedOperationExceptionInvocationHandler.invoke(FilterInvocation.java:235) ~[spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at com.sun.proxy.$Proxy134.getServerName(Unknown Source) ~[na:na]
at javax.servlet.ServletRequestWrapper.getServerName(ServletRequestWrapper.java:207) ~[tomcat-embed-core-8.5.16.jar:8.5.16]
有一個問題,從哪裏調用isLocal()方法?它是否構成攔截器?你能分享那部分嗎?並且'CustomWebSecurityExpressionRoot'是一個組件?被注射? –