Search in sources :

Example 1 with AgileBaseException

use of com.jeeagile.core.exception.AgileBaseException in project jeeagile by jeeagile.

the class AgileUserDetailsServiceImpl method userLogin.

@Override
public AgileBaseUser userLogin(String loginName, String userPassword) {
    try {
        AgileSysUser agileSysUser = this.getAgileSysUser(loginName);
        if (agileSysUser == null) {
            throw new AgileAuthException("用户《" + loginName + "》不存在,请核实!");
        }
        this.checkAgileSysUser(agileSysUser);
        String md5Password = AgileSecurityUtil.encryptPassword(userPassword);
        if (!md5Password.equals(agileSysUser.getUserPwd())) {
            throw new AgileAuthException(AgileResultCode.FAIL_USER_PWD, "用户密码错误!");
        }
        return getAgileUserData(agileSysUser);
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new AgileAuthException("用户登录异常!");
    }
}
Also used : AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileSysUser(com.jeeagile.system.entity.AgileSysUser) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 2 with AgileBaseException

use of com.jeeagile.core.exception.AgileBaseException in project jeeagile by jeeagile.

the class AgileUserDetailsServiceImpl method getUserPerm.

@Override
public List<String> getUserPerm(AgileBaseUser agileBaseUser) {
    try {
        if (agileBaseUser != null) {
            if (agileBaseUser.isSuperAdmin()) {
                List<String> userPermList = new ArrayList<>();
                userPermList.add("*:*:*");
                return userPermList;
            } else {
                return agileUserDetailsMapper.getUserPermByUserId(agileBaseUser.getUserId());
            }
        } else {
            throw new AgileAuthException(AgileResultCode.FAIL_USER_INFO);
        }
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new AgileAuthException("加载用户权限信息异常!");
    }
}
Also used : AgileBaseException(com.jeeagile.core.exception.AgileBaseException) ArrayList(java.util.ArrayList) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 3 with AgileBaseException

use of com.jeeagile.core.exception.AgileBaseException in project jeeagile by jeeagile.

the class AgileSecurityInterceptor method checkUserSecurity.

/**
 * 权限校验
 *
 * @param handlerMethod
 */
private void checkUserSecurity(HandlerMethod handlerMethod) {
    try {
        // 获取当前用户安全认证
        IAgileSecurity agileSecurity = AgileSecurityUtil.getAgileSecurity();
        if (agileSecurity == null) {
            throw new AgileAuthException("请设置用户安全接口类《UserSecurity》");
        }
        // 当前线程存放用户信息
        AgileSecurityContext.putCurrentUser(agileSecurity.getUserData());
        // 演示模式拦截
        AgileDemo agileDemo = handlerMethod.getMethodAnnotation(AgileDemo.class);
        if (agileDemo != null && AgileUtil.isDemoEnabled()) {
            throw new AgileDemoException();
        }
        // 如果为超管用户则不在进行权限校验
        if (agileSecurity.getUserData().isSuperAdmin()) {
            return;
        }
        AgileRequiresGuest agileRequiresGuest = handlerMethod.getBeanType().getAnnotation(AgileRequiresGuest.class);
        if (agileRequiresGuest != null) {
            return;
        }
        agileRequiresGuest = handlerMethod.getMethodAnnotation(AgileRequiresGuest.class);
        if (agileRequiresGuest != null) {
            return;
        }
        AgileRequiresAuthentication agileRequiresAuthentication = handlerMethod.getMethodAnnotation(AgileRequiresAuthentication.class);
        if (agileRequiresAuthentication != null && !agileSecurity.checkAuthenticated()) {
            throw new AgileAuthException("用户未验证通过!");
        }
        AgileRequiresUser agileRequiresUser = handlerMethod.getMethodAnnotation(AgileRequiresUser.class);
        if (agileRequiresUser != null) {
            agileSecurity.checkUser();
        }
        AgileRequiresRoles agileRequiresRoles = handlerMethod.getMethodAnnotation(AgileRequiresRoles.class);
        if (agileRequiresRoles != null) {
            agileSecurity.checkRole(agileRequiresRoles);
        }
        AgilePermissionsPrefix agilePermissionsPrefix = handlerMethod.getBeanType().getAnnotation(AgilePermissionsPrefix.class);
        AgileRequiresPermissions agileRequiresPermissions = handlerMethod.getMethodAnnotation(AgileRequiresPermissions.class);
        if (agileRequiresPermissions != null) {
            if (agilePermissionsPrefix != null) {
                agileSecurity.checkPermission(agilePermissionsPrefix, agileRequiresPermissions);
            } else {
                agileSecurity.checkPermission(agileRequiresPermissions);
            }
        }
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        logger.error("用户权限验证异常", ex);
        throw new AgileAuthException("用户权限验证异常!");
    }
}
Also used : IAgileSecurity(com.jeeagile.core.security.IAgileSecurity) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileDemoException(com.jeeagile.core.exception.AgileDemoException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileDemo(com.jeeagile.frame.annotation.AgileDemo) AgileDemoException(com.jeeagile.core.exception.AgileDemoException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 4 with AgileBaseException

use of com.jeeagile.core.exception.AgileBaseException in project jeeagile by jeeagile.

the class AgileScheduleUtil method createScheduleJob.

/**
 * 创建定时任务
 */
public static void createScheduleJob(AgileQuartzJob agileQuartzJob) {
    try {
        // 如果任务存在进行移除
        if (AgileScheduleUtil.checkJobExists(agileQuartzJob)) {
            AgileScheduleUtil.deleteScheduleJob(agileQuartzJob);
        }
        Class<? extends Job> jobClass = getAgileJobClass(agileQuartzJob);
        JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(agileQuartzJob)).build();
        // 表达式调度构建器
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(agileQuartzJob.getJobCron());
        cronScheduleBuilder = initCronScheduleMisfirePolicy(agileQuartzJob, cronScheduleBuilder);
        // 构建trigger
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(agileQuartzJob)).withSchedule(cronScheduleBuilder).build();
        // 放入运行参数
        jobDetail.getJobDataMap().put(AgileScheduleConstants.TASK_JOB_PROPERTIES, agileQuartzJob);
        agileScheduler.scheduleJob(jobDetail, cronTrigger);
        // 暂停任务
        if (agileQuartzJob.getJobStatus().equals(AgileStatusEnum.DISABLE.getCode())) {
            AgileScheduleUtil.pauseJob(agileQuartzJob);
        }
    } catch (SchedulerException ex) {
        throw new AgileFrameException("创建任务失败:" + ex.getMessage());
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new AgileFrameException("创建任务发生未知异常:" + ex.getMessage());
    }
}
Also used : AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 5 with AgileBaseException

use of com.jeeagile.core.exception.AgileBaseException in project jeeagile by jeeagile.

the class AgileExceptionFilter method onResponse.

@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
    if (appResponse.hasException() && GenericService.class != invoker.getInterface()) {
        try {
            Throwable exception = appResponse.getException();
            // directly throw if it's checked exception
            if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
                return;
            }
            // directly throw if the exception appears in the signature
            try {
                Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                Class<?>[] exceptionClassses = method.getExceptionTypes();
                for (Class<?> exceptionClass : exceptionClassses) {
                    if (exception.getClass().equals(exceptionClass)) {
                        return;
                    }
                }
            } catch (NoSuchMethodException e) {
                return;
            }
            // for the exception not found in method's signature, print ERROR message in server's log.
            logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception);
            // directly throw if exception class and interface class are in the same jar file.
            String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
            String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
            if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) {
                return;
            }
            // directly throw if it's JDK exception
            String className = exception.getClass().getName();
            if (className.startsWith("java.") || className.startsWith("javax.")) {
                return;
            }
            // directly throw if it's dubbo exception
            if (exception instanceof RpcException) {
                return;
            }
            if (exception instanceof AgileBaseException) {
                AgileBaseException agileBaseException = (AgileBaseException) exception;
                appResponse.setException(agileBaseException);
                return;
            }
            // otherwise, wrap with RuntimeException and throw back to the client
            appResponse.setException(new RuntimeException(StringUtils.toString(exception)));
        } catch (Throwable e) {
            logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
        }
    }
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) Method(java.lang.reflect.Method) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Aggregations

AgileBaseException (com.jeeagile.core.exception.AgileBaseException)13 AgileAuthException (com.jeeagile.core.exception.AgileAuthException)11 AgileFrameException (com.jeeagile.core.exception.AgileFrameException)4 AgileBaseUser (com.jeeagile.core.security.user.AgileBaseUser)3 AgileSysUser (com.jeeagile.system.entity.AgileSysUser)3 UserAgent (eu.bitwalker.useragentutils.UserAgent)2 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 AgileDemoException (com.jeeagile.core.exception.AgileDemoException)1 AgileReference (com.jeeagile.core.protocol.annotation.AgileReference)1 AgileResultCode (com.jeeagile.core.result.AgileResultCode)1 IAgileSecurity (com.jeeagile.core.security.IAgileSecurity)1 IAgileUserDetailsService (com.jeeagile.core.security.userdetails.IAgileUserDetailsService)1 AgileAgentUtil (com.jeeagile.core.util.AgileAgentUtil)1 AgileStringUtil (com.jeeagile.core.util.AgileStringUtil)1 AgileServletUtil (com.jeeagile.core.util.spring.AgileServletUtil)1 AgileDemo (com.jeeagile.frame.annotation.AgileDemo)1 AgileUserDetails (com.jeeagile.springsecurity.userdetails.AgileUserDetails)1 Method (java.lang.reflect.Method)1 List (java.util.List)1