我只是使用spring-security来授权url资源取决于用户相关的角色,但我的登录不依赖于spring-security。 但是我的授权网址没有输入用于授权网址的JWTAuthenticationFilter。我不知道我的代码中有什么问题,请查看下面的代码并指出我的配置或JWTAuthenticationFilter中的问题,非常有帮助。 或者任何相关的参考链接也将非常感激。非常感谢你!
我的配置文件:
@Log4j2
public class JWTAuthenticationFilter extends AbstractSecurityInterceptor implements Filter{
@Autowired
private FilterInvocationSecurityMetadataSource securityMetadataSource;
@Autowired
private SmcAccessDecisionManager smcAccessDecisionManager;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
super.setAccessDecisionManager(smcAccessDecisionManager);
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
log.info("进入SmcSecurityFilter");
FilterInvocation fi = new FilterInvocation( request, response, chain );
invoke(fi);
}
public void invoke( FilterInvocation object ) throws IOException, ServletException{
super.beforeInvocation(object);
Collection<ConfigAttribute> attributes = securityMetadataSource.getAttributes(object);
this.smcAccessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(), object, attributes);
InterceptorStatusToken token = super.beforeInvocation(object);
try{
object.getChain().doFilter(object.getRequest(), object.getResponse());
}finally{
super.afterInvocation(token, null);
}
}
public FilterInvocationSecurityMetadataSource getSecurityMetadataSource(){
return this.securityMetadataSource;
}
public void setSecurityMetadataSource(FilterInvocationSecurityMetadataSource securityMetadataSource) {
this.securityMetadataSource = securityMetadataSource;
}
@Override
public void destroy() {
}
@Override
public Class<?> getSecureObjectClass() {
return FilterInvocation.class;
}
@Override
public SecurityMetadataSource obtainSecurityMetadataSource() {
return this.securityMetadataSource;
}
}
我的JWTAuthenticationFilter:
function wp_get_menu_array($current_menu) {
$array_menu = wp_get_nav_menu_items($current_menu);
$menu = array();
foreach ($array_menu as $m1) {
if (empty($m1->menu_item_parent)) {
$menu[$m1->ID] = array();
$menu[$m1->ID]['ID'] = $m1->ID;
$menu[$m1->ID]['title'] = $m1->title;
$menu[$m1->ID]['url'] = $m1->url;
$menu[$m1->ID]['children'] = array();
$childMenu = array();
foreach ($array_menu as $m2) {
if ($m2->menu_item_parent == $m1->ID) {
$childMenu[$m2->ID] = array();
$childMenu[$m2->ID]['ID'] = $m2->ID;
$childMenu[$m2->ID]['title'] = $m2->title;
$childMenu[$m2->ID]['url'] = $m2->url;
$childMenu[$m2->ID]['children'] = array();
$grandChildMenu = array();
foreach ($array_menu as $m3) {
if ($m3->menu_item_parent == $m2->ID) {
$grandChildMenu[$m3->ID] = array();
$grandChildMenu[$m3->ID]['ID'] = $m3->ID;
$grandChildMenu[$m3->ID]['title'] = $m3->title;
$grandChildMenu[$m3->ID]['url'] = $m3->url;
$childMenu[$m3->menu_item_parent]['children'][$m3->ID] = $grandChildMenu[$m3->ID];
}
}
$menu[$m2->menu_item_parent]['children'][$m2->ID] = $childMenu[$m2->ID];
}
}
}
}
return $menu;
}
答案 0 :(得分:0)
尝试将doFilter()更改为如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/hk-grotesk" type="text/css"/>
<link rel="stylesheet" href="css/untitled.css">
<title>Document</title>
</head>
<body>
<div class="mainwrap">
<!--Header-->
<header class="header-area">
<div class="logo-wrap">
<div class="main-logo">
<a href="#"><img src="Assets/logo.png" alt="pd-logo"></a>
</div>
</div>
<div class="header-left">
<nav class="main-nav">
<ul id="menu-main-menu" class="menu">
<li><a href="#">link1</a></li>
<li><a href="#">link2</a></li>
<li><a href="#">link3</a></li>
</ul>
</nav>
</div>
<div class="header-right">
<a href="#">Give us a Call<img class="phone" src="Assets/Phone.svg">0123456789</a>
</div>
</header>
</div>
</body>
</html>
你的invoke()方法如下:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
log.info("进入SmcSecurityFilter");
FilterInvocation fi = new FilterInvocation( request, response, chain );
invoke(fi, chain, request, response);
}