Search in sources :

Example 6 with AgileFrameException

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

the class AgileAuthorizingRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) {
    if (agileUserDetailsService == null) {
        throw new AgileFrameException(AgileResultCode.FAIL_SERVER_EXCEPTION, "请设置用户验证接口实现类!");
    }
    // 获取用户名
    String loginName = (String) authenticationToken.getPrincipal();
    // 字符类型密码获取(用户输入的密码)
    char[] credentials = (char[]) authenticationToken.getCredentials();
    if (credentials == null || credentials.length < 1) {
        return null;
    }
    // 把字符数组转换为String类型(用户输入的密码)
    String password = new String(credentials);
    try {
        AgileBaseUser userData = agileUserDetailsService.getUserDataByLoginName(loginName);
        if (userData != null && AgileStringUtil.isNotEmpty(userData.getUserId())) {
            if (AgileSecurityUtil.encryptPassword(password).equals(userData.getPassword())) {
                userData.setUserToken(SecurityUtils.getSubject().getSession().getId().toString());
                userData.setUserPerm(agileUserDetailsService.getUserPerm(userData));
                userData.setUserRole(agileUserDetailsService.getUserRole(userData));
                HttpServletRequest httpServletRequest = AgileServletUtil.getHttpServletRequest();
                if (httpServletRequest != null) {
                    UserAgent userAgent = AgileAgentUtil.getUserAgent(httpServletRequest);
                    userData.setLoginIp(AgileAgentUtil.getUserClientIp(httpServletRequest));
                    userData.setLoginAddress(AgileNetUtil.getAddressByIp(userData.getLoginIp()));
                    userData.setOsName(userAgent.getOperatingSystem().getName());
                    userData.setDeviceName(userAgent.getOperatingSystem().getDeviceType().getName());
                    userData.setBrowserName(userAgent.getBrowser().getName());
                }
                return new SimpleAuthenticationInfo(userData, password, userData.getUserName());
            } else {
                throw new AgileAuthException(AgileResultCode.FAIL_USER_PWD);
            }
        } else {
            throw new AgileAuthException(AgileResultCode.FAIL_USER_NAME);
        }
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new AgileAuthException(AgileResultCode.FAIL_AUTH_EXCEPTION, ex);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) UserAgent(eu.bitwalker.useragentutils.UserAgent) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseUser(com.jeeagile.core.security.user.AgileBaseUser) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 7 with AgileFrameException

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

the class AgileUserDetailsServiceImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String loginName) throws UsernameNotFoundException {
    try {
        if (agileUserDetailsService == null) {
            throw new AgileFrameException(AgileResultCode.FAIL_SERVER_EXCEPTION, "请设置用户验证接口实现类!");
        }
        AgileBaseUser userData = agileUserDetailsService.getUserDataByLoginName(loginName);
        if (userData != null && AgileStringUtil.isNotEmpty(userData.getUserId())) {
            userData.setUserToken(AgileStringUtil.getUuid());
            userData.setUserPerm(agileUserDetailsService.getUserPerm(userData));
            userData.setUserRole(agileUserDetailsService.getUserRole(userData));
            HttpServletRequest httpServletRequest = AgileServletUtil.getHttpServletRequest();
            if (httpServletRequest != null) {
                UserAgent userAgent = AgileAgentUtil.getUserAgent(httpServletRequest);
                userData.setLoginIp(AgileAgentUtil.getUserClientIp(httpServletRequest));
                userData.setOsName(userAgent.getOperatingSystem().getName());
                userData.setDeviceName(userAgent.getOperatingSystem().getDeviceType().getName());
                userData.setBrowserName(userAgent.getBrowser().getName());
            }
            List<SimpleGrantedAuthority> authorities = userData.getUserRole().stream().map(role -> new SimpleGrantedAuthority(role)).collect(Collectors.toList());
            AgileUserDetails agileUserDetails = new AgileUserDetails();
            agileUserDetails.setUserData(userData);
            agileUserDetails.setAuthorities(authorities);
            return agileUserDetails;
        } else {
            throw new AgileAuthException(AgileResultCode.FAIL_USER_NAME);
        }
    } catch (AgileBaseException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new AgileAuthException(AgileResultCode.FAIL_AUTH_EXCEPTION, ex);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) AgileStringUtil(com.jeeagile.core.util.AgileStringUtil) AgileReference(com.jeeagile.core.protocol.annotation.AgileReference) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) AgileResultCode(com.jeeagile.core.result.AgileResultCode) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) AgileServletUtil(com.jeeagile.core.util.spring.AgileServletUtil) AgileBaseUser(com.jeeagile.core.security.user.AgileBaseUser) Collectors(java.util.stream.Collectors) UserAgent(eu.bitwalker.useragentutils.UserAgent) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) IAgileUserDetailsService(com.jeeagile.core.security.userdetails.IAgileUserDetailsService) UserDetails(org.springframework.security.core.userdetails.UserDetails) Lazy(org.springframework.context.annotation.Lazy) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) AgileAgentUtil(com.jeeagile.core.util.AgileAgentUtil) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) AgileBaseException(com.jeeagile.core.exception.AgileBaseException) UserAgent(eu.bitwalker.useragentutils.UserAgent) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseUser(com.jeeagile.core.security.user.AgileBaseUser) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) AgileAuthException(com.jeeagile.core.exception.AgileAuthException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileBaseException(com.jeeagile.core.exception.AgileBaseException)

Example 8 with AgileFrameException

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

the class AgileKaptchaUtil method createImage.

/**
 * 生成验证码
 */
public static AgileKaptchaInfo createImage(AgileKaptchaProducer agileKaptchaProducer) {
    AgileKaptchaInfo agileKaptchaInfo = null;
    switch(agileKaptchaProducer.getAgileKaptchaType()) {
        case arithmetic:
            agileKaptchaInfo = new AgileKaptchaInfo();
            agileKaptchaInfo.setUuid(AgileStringUtil.getUuid());
            String capText = agileKaptchaProducer.createText();
            String capStr = capText.substring(0, capText.lastIndexOf("@"));
            agileKaptchaInfo.setCode(capText.substring(capText.lastIndexOf("@") + 1));
            BufferedImage bufferedImage = agileKaptchaProducer.createImage(capStr);
            agileKaptchaInfo.setImage(createBase64Image(bufferedImage));
            break;
        case chinese:
            // captcha.setLen(loginCode.getLength());
            break;
        default:
            throw new AgileFrameException("验证码配置信息错误!");
    }
    return agileKaptchaInfo;
}
Also used : AgileFrameException(com.jeeagile.core.exception.AgileFrameException) BufferedImage(java.awt.image.BufferedImage)

Example 9 with AgileFrameException

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

the class AgileGeneratorUtil method initVelocity.

/**
 * 初始化Velocity
 */
private static void initVelocity() {
    try {
        Properties properties = new Properties();
        // 加载classpath目录下的vm文件
        properties.setProperty(VELOCITY_INIT_CLASS_KEY, VELOCITY_INIT_CLASS_NAME);
        // 定义字符集
        properties.setProperty(RuntimeConstants.ENCODING_DEFAULT, AgileConstants.UTF8);
        properties.setProperty(RuntimeConstants.OUTPUT_ENCODING, AgileConstants.UTF8);
        // 初始化Velocity引擎,指定配置Properties
        Velocity.init(properties);
    } catch (Exception ex) {
        throw new AgileFrameException("Velocity初始化异常!", ex);
    }
}
Also used : AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) IOException(java.io.IOException)

Example 10 with AgileFrameException

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

the class AgileAbstractJob method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) {
    JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
    AgileQuartzJob agileQuartzJob = (AgileQuartzJob) jobDataMap.get(AgileScheduleConstants.TASK_JOB_PROPERTIES);
    Throwable throwable = null;
    Date startTime = new Date();
    try {
        if (agileQuartzJob != null && agileQuartzJob.isNotEmptyPk()) {
            doExecute(jobExecutionContext, agileQuartzJob);
        } else {
            throw new AgileFrameException("任务调度参数为空!");
        }
    } catch (Exception ex) {
        log.error("任务执行异常:", ex);
        throwable = ex;
    } finally {
        saveJobLog(agileQuartzJob, startTime, throwable);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) AgileFrameException(com.jeeagile.core.exception.AgileFrameException) AgileQuartzJob(com.jeeagile.quartz.entity.AgileQuartzJob) AgileFrameException(com.jeeagile.core.exception.AgileFrameException)

Aggregations

AgileFrameException (com.jeeagile.core.exception.AgileFrameException)11 JSONObject (com.alibaba.fastjson.JSONObject)3 AgileBaseException (com.jeeagile.core.exception.AgileBaseException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AgileAuthException (com.jeeagile.core.exception.AgileAuthException)2 AgileBaseUser (com.jeeagile.core.security.user.AgileBaseUser)2 UserAgent (eu.bitwalker.useragentutils.UserAgent)2 IOException (java.io.IOException)2 AgileValidateException (com.jeeagile.core.exception.AgileValidateException)1 AgileReference (com.jeeagile.core.protocol.annotation.AgileReference)1 AgileResultCode (com.jeeagile.core.result.AgileResultCode)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 SingleRequestBody (com.jeeagile.frame.support.resolver.annotation.SingleRequestBody)1 AgileGeneratorTableInfo (com.jeeagile.generator.vo.AgileGeneratorTableInfo)1 AgileQuartzJob (com.jeeagile.quartz.entity.AgileQuartzJob)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1