Search in sources :

Example 1 with ShiroUser

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser)

Example 2 with ShiroUser

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;
}
Also used : ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser)

Example 3 with ShiroUser

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));
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) AbstractDictMap(com.ikoori.vip.common.constant.dictmap.base.AbstractDictMap) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser) Method(java.lang.reflect.Method) BussinessLog(com.ikoori.vip.common.annotion.log.BussinessLog)

Example 4 with ShiroUser

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;
}
Also used : ArrayList(java.util.ArrayList) ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser)

Example 5 with 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 + "/";
}
Also used : InvalidKaptchaException(com.ikoori.vip.common.exception.InvalidKaptchaException) ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ShiroUser (com.ikoori.vip.server.core.shiro.ShiroUser)5 BussinessLog (com.ikoori.vip.common.annotion.log.BussinessLog)1 AbstractDictMap (com.ikoori.vip.common.constant.dictmap.base.AbstractDictMap)1 InvalidKaptchaException (com.ikoori.vip.common.exception.InvalidKaptchaException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 Signature (org.aspectj.lang.Signature)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1