refactor: 删除不用的代码

This commit is contained in:
Captain.B 2020-10-10 14:44:37 +08:00
parent 432d13fb1d
commit bf554738cd
2 changed files with 0 additions and 38 deletions

View File

@ -35,7 +35,6 @@ public class ShiroConfig implements EnvironmentAware {
@Bean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager sessionManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// shiroFilterFactoryBean.getFilters().put("authc", new LoginFilter());
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setSecurityManager(sessionManager);
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
@ -44,7 +43,6 @@ public class ShiroConfig implements EnvironmentAware {
shiroFilterFactoryBean.getFilters().put("apikey", new ApiKeyFilter());
Map<String, String> filterChainDefinitionMap = shiroFilterFactoryBean.getFilterChainDefinitionMap();
ShiroUtils.loadBaseFilterChain(filterChainDefinitionMap);
// filterChainDefinitionMap.put("/**", "apikey, authc");
filterChainDefinitionMap.put("/**", "apikey");
return shiroFilterFactoryBean;
}

View File

@ -1,36 +0,0 @@
package io.metersphere.security;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.controller.ResultHolder;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginFilter extends FormAuthenticationFilter {
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
if (((HttpServletRequest) request).getMethod().toUpperCase().equals("OPTIONS")) {
return true;
}
return super.isAccessAllowed(request, response, mappedValue);
}
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
if (httpServletRequest.getServletPath().endsWith("login")) {
return super.onAccessDenied(request, response);
}
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("application/json");
httpServletResponse.setHeader("authentication-status", "invalid");
ResultHolder result = ResultHolder.error("Authentication Status Invalid");
httpServletResponse.getWriter().write(JSONObject.toJSON(result).toString());
return true;
}
}