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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations