规范化名称

v1.4.1
Parker 4 years ago
parent 5f2cd1e0d3
commit 3455d9fe1f

@ -19,7 +19,6 @@ package org.opsli.core.base.concroller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.TypeUtil;
import com.alibaba.excel.support.ExcelTypeEnum;
@ -42,7 +41,7 @@ import org.opsli.core.base.service.interfaces.CrudServiceInterface;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.realm.OAuth2Realm;
import org.opsli.core.security.shiro.realm.JwtRealm;
import org.opsli.core.utils.ExcelUtil;
import org.opsli.core.utils.UserUtil;
import org.opsli.plugins.excel.exception.ExcelPluginException;
@ -284,16 +283,16 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
}
// Token 认证
OAuth2Realm.authToken();
JwtRealm.authToken();
RequiresPermissionsCus permissionsCus = method.getAnnotation(RequiresPermissionsCus.class);
if(permissionsCus != null){
// 方法权限认证
OAuth2Realm.authPerms(permissionsCus.value());
JwtRealm.authPerms(permissionsCus.value());
}
}catch (TokenException e){
// 推送错误信息
OAuth2Realm.exceptionResponse(e.getMessage(), response);
JwtRealm.exceptionResponse(e.getMessage(), response);
return;
}
@ -343,7 +342,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
// 导出异常
if(!resultVo.isSuccess()){
// 无权访问该方法
OAuth2Realm.exceptionResponse(resultVo.getMsg(), response);
JwtRealm.exceptionResponse(resultVo.getMsg(), response);
}
}

@ -10,7 +10,7 @@ import org.opsli.common.constants.SignConstants;
import org.opsli.common.constants.TokenTypeConstants;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.token.ExternalToken;
import org.opsli.core.security.shiro.token.OAuth2Token;
import org.opsli.core.security.shiro.token.JwtToken;
import org.opsli.core.utils.JwtUtil;
import org.opsli.core.utils.UserTokenUtil;
import org.springframework.web.bind.annotation.RequestMethod;
@ -46,13 +46,13 @@ public class CustomShiroFilter extends AuthenticatingFilter {
// 分析token
String claim = JwtUtil.getClaim(token, SignConstants.TYPE);
// 第三方登录
// 手机登录
if(TokenTypeConstants.TYPE_EXTERNAL.equals(claim)){
return new ExternalToken(token);
}
// .... 追加登录方式
return new OAuth2Token(token);
return new JwtToken(token);
}
@Override

@ -1,96 +0,0 @@
package org.opsli.core.security.shiro.filter;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
import org.opsli.api.base.result.ResultVo;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.token.OAuth2Token;
import org.opsli.core.utils.UserTokenUtil;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* oauth2
*
* 401
*
*
*
* @author
* @date 2017-05-20 13:00
*/
public class OAuth2Filter extends AuthenticatingFilter {
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
//获取请求token
String token = UserTokenUtil.getRequestToken((HttpServletRequest) request);
if(StringUtils.isBlank(token)){
return null;
}
return new OAuth2Token(token);
}
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
if(((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())){
return true;
}
// remeberMe ,remeberMe特殊页面需要授权
return false;
}
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
//获取请求token如果token不存在直接返回401
String token = UserTokenUtil.getRequestToken((HttpServletRequest) request);
if(StringUtils.isBlank(token)){
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
httpResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));
httpResponse.setContentType("application/json; charset=utf-8");
// 401 Token失效请重新登录
ResultVo<Object> error = ResultVo.error(TokenMsg.EXCEPTION_TOKEN_LOSE_EFFICACY.getCode(),
TokenMsg.EXCEPTION_TOKEN_LOSE_EFFICACY.getMessage());
httpResponse.getWriter().print(error.toJsonStr());
return false;
}
return executeLogin(request, response);
}
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
httpResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));
httpResponse.setContentType("application/json; charset=utf-8");
try {
//处理登录失败的异常
Throwable throwable = e.getCause() == null ? e : e.getCause();
ResultVo<Object> error = ResultVo.error(401, throwable.getMessage());
httpResponse.getWriter().print(error.toJsonStr());
} catch (IOException e1) {
}
return false;
}
}

@ -12,7 +12,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.api.TokenThreadLocal;
import org.opsli.common.exception.TokenException;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.token.OAuth2Token;
import org.opsli.core.security.shiro.token.JwtToken;
import org.opsli.core.utils.UserTokenUtil;
import org.opsli.core.utils.UserUtil;
import org.springframework.stereotype.Component;
@ -30,14 +30,14 @@ import java.util.List;
*/
@Component
@Slf4j
public class OAuth2Realm extends AuthorizingRealm implements FlagRealm {
public class JwtRealm extends AuthorizingRealm implements FlagRealm {
/** 账号锁定状态 */
public static final String LOCK_VAL = "1";
@Override
public boolean supports(AuthenticationToken token) {
return token instanceof OAuth2Token;
return token instanceof JwtToken;
}
/**
@ -115,7 +115,7 @@ public class OAuth2Realm extends AuthorizingRealm implements FlagRealm {
UserModel user = UserUtil.getUser(userId);
// 3. 校验账户是否锁定
if(user == null || user.getLocked().equals(OAuth2Realm.LOCK_VAL)){
if(user == null || user.getLocked().equals(JwtRealm.LOCK_VAL)){
// 账号已被锁定,请联系管理员
// token失效请重新登录
throw new TokenException(

@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
/**
*
*
*
* @author Parker
@ -21,7 +21,7 @@ import org.springframework.stereotype.Component;
*/
@Component
@Slf4j
public class ExternalRealm extends AuthorizingRealm implements FlagRealm {
public class TelRealm extends AuthorizingRealm implements FlagRealm {
/** 账号锁定状态 */
public static final char LOCK_VAL = '1';

@ -6,15 +6,15 @@ import org.apache.shiro.authc.AuthenticationToken;
/**
* OAuth2 token
*
* @author
* @author Parker
* @date 2017-05-20 13:22
*/
public class OAuth2Token implements AuthenticationToken {
public class JwtToken implements AuthenticationToken {
private final String token;
public OAuth2Token(String token){
public JwtToken(String token){
this.token = token;
}

@ -28,7 +28,7 @@ import org.opsli.common.exception.TokenException;
import org.opsli.common.thread.refuse.AsyncProcessQueueReFuse;
import org.opsli.common.utils.IPUtil;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.realm.OAuth2Realm;
import org.opsli.core.security.shiro.realm.JwtRealm;
import org.opsli.core.utils.CaptchaUtil;
import org.opsli.core.utils.TenantUtil;
import org.opsli.core.utils.UserTokenUtil;
@ -102,7 +102,7 @@ public class LoginRestController {
UserTokenUtil.clearLockAccount(form.getUsername());
// 账号锁定
if(OAuth2Realm.LOCK_VAL.equals(user.getLocked())){
if(JwtRealm.LOCK_VAL.equals(user.getLocked())){
throw new TokenException(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCKED);
}

Loading…
Cancel
Save