Search in sources :

Example 16 with CustomException

use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.

the class QuartzManage method runAJobNow.

/**
 * 立即执行job
 */
public void runAJobNow(QuartzJob quartzJob) {
    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
        CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
        // 如果不存在则创建一个定时任务
        if (trigger == null)
            addJob(quartzJob);
        JobDataMap dataMap = new JobDataMap();
        dataMap.put(QuartzJob.JOB_KEY, quartzJob);
        JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
        scheduler.triggerJob(jobKey, dataMap);
    } catch (Exception e) {
        log.error("定时任务执行失败", e);
        throw new CustomException("定时任务执行失败");
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) JobDataMap(org.quartz.JobDataMap) JobKey(org.quartz.JobKey) CustomException(com.dimple.common.exception.CustomException) CustomException(com.dimple.common.exception.CustomException)

Example 17 with CustomException

use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.

the class QuartzManage method pauseJob.

/**
 * 暂停一个job
 *
 * @param quartzJob /
 */
public void pauseJob(QuartzJob quartzJob) {
    try {
        JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
        scheduler.pauseJob(jobKey);
    } catch (Exception e) {
        log.error("定时任务暂停失败", e);
        throw new CustomException("定时任务暂停失败");
    }
}
Also used : JobKey(org.quartz.JobKey) CustomException(com.dimple.common.exception.CustomException) CustomException(com.dimple.common.exception.CustomException)

Example 18 with CustomException

use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.

the class QuartzManage method resumeJob.

/**
 * 恢复一个job
 */
public void resumeJob(QuartzJob quartzJob) {
    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
        CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
        // 如果不存在则创建一个定时任务
        if (trigger == null)
            addJob(quartzJob);
        JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
        scheduler.resumeJob(jobKey);
    } catch (Exception e) {
        log.error("恢复定时任务失败", e);
        throw new CustomException("恢复定时任务失败");
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) JobKey(org.quartz.JobKey) CustomException(com.dimple.common.exception.CustomException) CustomException(com.dimple.common.exception.CustomException)

Example 19 with CustomException

use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.

the class SysLoginService method login.

/**
 * 登录验证
 *
 * @param username 用户名
 * @param password 密码
 * @param captcha  验证码
 * @param uuid     唯一标识
 * @return 结果
 */
public String login(String username, String password, String code, String uuid) {
    String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
    String captcha = redisCacheService.getCacheObject(verifyKey);
    redisCacheService.deleteObject(verifyKey);
    if (captcha == null) {
        AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.FAILED, MessageUtils.message("user.captcha.error")));
        throw new CaptchaExpireException();
    }
    if (!code.equalsIgnoreCase(captcha)) {
        AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.FAILED, MessageUtils.message("user.captcha.expire")));
        throw new CaptchaException();
    }
    // 用户验证
    Authentication authentication = null;
    try {
        // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
        authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    } catch (Exception e) {
        if (e instanceof BadCredentialsException) {
            AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.FAILED, MessageUtils.message("user.password.not.match")));
            throw new UserPasswordNotMatchException();
        } else {
            AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.FAILED, e.getMessage()));
            throw new CustomException(e.getMessage());
        }
    }
    AsyncManager.me().execute(AsyncFactory.recordLoginLog(username, Constants.SUCCESS, MessageUtils.message("user.login.success")));
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    // 生成token
    return tokenService.createToken(loginUser);
}
Also used : CaptchaExpireException(com.dimple.common.exception.user.CaptchaExpireException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) CustomException(com.dimple.common.exception.CustomException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) UserPasswordNotMatchException(com.dimple.common.exception.user.UserPasswordNotMatchException) LoginUser(com.dimple.framework.security.LoginUser) CaptchaException(com.dimple.common.exception.user.CaptchaException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) CaptchaExpireException(com.dimple.common.exception.user.CaptchaExpireException) CaptchaException(com.dimple.common.exception.user.CaptchaException) CustomException(com.dimple.common.exception.CustomException) UserPasswordNotMatchException(com.dimple.common.exception.user.UserPasswordNotMatchException)

Aggregations

CustomException (com.dimple.common.exception.CustomException)19 QiNiuConfig (com.dimple.project.common.domain.QiNiuConfig)4 QiNiuContent (com.dimple.project.tool.domain.QiNiuContent)4 Auth (com.qiniu.util.Auth)4 CronTrigger (org.quartz.CronTrigger)4 JobKey (org.quartz.JobKey)4 QuartzJob (com.dimple.project.tool.domain.QuartzJob)3 Configuration (com.qiniu.storage.Configuration)3 Date (java.util.Date)3 TriggerKey (org.quartz.TriggerKey)3 LocalStorage (com.dimple.project.tool.domain.LocalStorage)2 QiniuException (com.qiniu.common.QiniuException)2 BucketManager (com.qiniu.storage.BucketManager)2 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)2 CaptchaException (com.dimple.common.exception.user.CaptchaException)1 CaptchaExpireException (com.dimple.common.exception.user.CaptchaExpireException)1 UserPasswordNotMatchException (com.dimple.common.exception.user.UserPasswordNotMatchException)1 CacheExpire (com.dimple.framework.config.redis.CacheExpire)1 LoginUser (com.dimple.framework.security.LoginUser)1 Config (com.dimple.project.system.domain.Config)1