refactor: 删除不用的代码
This commit is contained in:
parent
432d13fb1d
commit
bf554738cd
|
@ -35,7 +35,6 @@ public class ShiroConfig implements EnvironmentAware {
|
||||||
@Bean
|
@Bean
|
||||||
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager sessionManager) {
|
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager sessionManager) {
|
||||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||||
// shiroFilterFactoryBean.getFilters().put("authc", new LoginFilter());
|
|
||||||
shiroFilterFactoryBean.setLoginUrl("/login");
|
shiroFilterFactoryBean.setLoginUrl("/login");
|
||||||
shiroFilterFactoryBean.setSecurityManager(sessionManager);
|
shiroFilterFactoryBean.setSecurityManager(sessionManager);
|
||||||
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
||||||
|
@ -44,7 +43,6 @@ public class ShiroConfig implements EnvironmentAware {
|
||||||
shiroFilterFactoryBean.getFilters().put("apikey", new ApiKeyFilter());
|
shiroFilterFactoryBean.getFilters().put("apikey", new ApiKeyFilter());
|
||||||
Map<String, String> filterChainDefinitionMap = shiroFilterFactoryBean.getFilterChainDefinitionMap();
|
Map<String, String> filterChainDefinitionMap = shiroFilterFactoryBean.getFilterChainDefinitionMap();
|
||||||
ShiroUtils.loadBaseFilterChain(filterChainDefinitionMap);
|
ShiroUtils.loadBaseFilterChain(filterChainDefinitionMap);
|
||||||
// filterChainDefinitionMap.put("/**", "apikey, authc");
|
|
||||||
filterChainDefinitionMap.put("/**", "apikey");
|
filterChainDefinitionMap.put("/**", "apikey");
|
||||||
return shiroFilterFactoryBean;
|
return shiroFilterFactoryBean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue