use of com.ikoori.vip.server.core.shiro.ShiroUser in project vip by guangdada.
the class PermissionCheckFactory method checkAll.
@Override
public boolean checkAll() {
HttpServletRequest request = HttpKit.getRequest();
ShiroUser user = ShiroKit.getUser();
if (null == user) {
return false;
}
String requestURI = request.getRequestURI().replace(ConfigListener.getConf().get("contextPath"), "");
String[] str = requestURI.split("/");
if (str.length > 3) {
requestURI = "/" + str[1] + "/" + str[2];
}
if (ShiroKit.hasPermission(requestURI)) {
return true;
}
return false;
}
use of com.ikoori.vip.server.core.shiro.ShiroUser in project vip by guangdada.
the class PermissionCheckFactory method check.
@Override
public boolean check(Object[] permissions) {
ShiroUser user = ShiroKit.getUser();
if (null == user) {
return false;
}
String join = CollectionKit.join(permissions, ",");
if (ShiroKit.hasAnyRoles(join)) {
return true;
}
return false;
}
use of com.ikoori.vip.server.core.shiro.ShiroUser in project vip by guangdada.
the class LogAop method handle.
private void handle(ProceedingJoinPoint point) throws Exception {
// 获取拦截的方法名
Signature sig = point.getSignature();
MethodSignature msig = null;
if (!(sig instanceof MethodSignature)) {
throw new IllegalArgumentException("该注解只能用于方法");
}
msig = (MethodSignature) sig;
Object target = point.getTarget();
Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
String methodName = currentMethod.getName();
// 如果当前用户未登录,不做日志
ShiroUser user = ShiroKit.getUser();
if (null == user) {
return;
}
// 获取拦截方法的参数
String className = point.getTarget().getClass().getName();
Object[] params = point.getArgs();
// 获取操作名称
BussinessLog annotation = currentMethod.getAnnotation(BussinessLog.class);
String bussinessName = annotation.value();
String key = annotation.key();
String dictClass = annotation.dict();
StringBuilder sb = new StringBuilder();
for (Object param : params) {
sb.append(param);
sb.append(" & ");
}
// 如果涉及到修改,比对变化
String msg;
if (bussinessName.indexOf("修改") != -1 || bussinessName.indexOf("编辑") != -1) {
Object obj1 = LogObjectHolder.me().get();
Map<String, String> obj2 = HttpKit.getRequestParameters();
msg = Contrast.contrastObj(dictClass, key, obj1, obj2);
} else {
Map<String, String> parameters = HttpKit.getRequestParameters();
AbstractDictMap dictMap = DictMapFactory.createDictMap(dictClass);
msg = Contrast.parseMutiKey(dictMap, key, parameters);
}
LogManager.me().executeLog(LogTaskFactory.bussinessLog(user.getId(), bussinessName, className, methodName, msg));
}
use of com.ikoori.vip.server.core.shiro.ShiroUser in project vip by guangdada.
the class ShiroFactroy method shiroUser.
@Override
public ShiroUser shiroUser(User user) {
ShiroUser shiroUser = new ShiroUser();
// 账号id
shiroUser.setId(user.getId());
// 账号
shiroUser.setAccount(user.getAccount());
// 部门id
shiroUser.setDeptId(user.getDeptid());
// 部门名称
shiroUser.setDeptName(ConstantFactory.me().getDeptName(user.getDeptid()));
// 用户名称
shiroUser.setName(user.getName());
// 角色集合
Integer[] roleArray = Convert.toIntArray(user.getRoleid());
List<Integer> roleList = new ArrayList<Integer>();
List<String> roleNameList = new ArrayList<String>();
for (int roleId : roleArray) {
roleList.add(roleId);
roleNameList.add(ConstantFactory.me().getSingleRoleName(roleId));
}
shiroUser.setRoleList(roleList);
shiroUser.setRoleNames(roleNameList);
return shiroUser;
}
use of com.ikoori.vip.server.core.shiro.ShiroUser in project vip by guangdada.
the class LoginController method loginVali.
/**
* 点击登录执行的动作
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginVali() {
String username = super.getPara("username").trim();
String password = super.getPara("password").trim();
// 验证验证码是否正确
if (ToolUtil.getKaptchaOnOff()) {
String kaptcha = super.getPara("kaptcha").trim();
String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equals(code)) {
throw new InvalidKaptchaException();
}
}
Subject currentUser = ShiroKit.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());
token.setRememberMe(true);
currentUser.login(token);
ShiroUser shiroUser = ShiroKit.getUser();
super.getSession().setAttribute("shiroUser", shiroUser);
super.getSession().setAttribute("username", shiroUser.getAccount());
LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), getIp()));
ShiroKit.getSession().setAttribute("sessionFlag", true);
return REDIRECT + "/";
}
Aggregations