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("用户登录异常!");
}
}
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("加载用户权限信息异常!");
}
}
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("用户权限验证异常!");
}
}
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());
}
}
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);
}
}
}
Aggregations