Commit 83dc7f8a authored by zhengjie's avatar zhengjie
Browse files

优化user列表中的岗位DTO,修改@author信息,新增验证码登录

parent c01435a0
......@@ -8,7 +8,7 @@ import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
@Entity
......
......@@ -3,28 +3,16 @@ package me.zhengjie.modules.quartz.repository;
import me.zhengjie.modules.quartz.domain.QuartzJob;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
public interface QuartzJobRepository extends JpaRepository<QuartzJob,Long>, JpaSpecificationExecutor {
/**
* 更新状态
* @param id
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query(value = "update quartz_job set is_pause = 1 where id = ?1",nativeQuery = true)
void updateIsPause(Long id);
/**
* 查询不是启用的任务
* 查询启用的任务
* @return
*/
List<QuartzJob> findByIsPauseIsFalse();
......
......@@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
public interface QuartzLogRepository extends JpaRepository<QuartzLog,Long>, JpaSpecificationExecutor {
......
......@@ -15,7 +15,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
@Slf4j
......
......@@ -9,7 +9,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
@CacheConfig(cacheNames = "quartzJob")
......
......@@ -4,7 +4,7 @@ import lombok.Data;
import me.zhengjie.annotation.Query;
/**
* @author jie
* @author Zheng Jie
* @date 2019-6-4 10:33:02
*/
@Data
......
......@@ -19,7 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
@Service(value = "quartzJobService")
......
......@@ -5,7 +5,7 @@ import org.springframework.stereotype.Component;
/**
* 测试用
* @author jie
* @author Zheng Jie
* @date 2019-01-08
*/
@Slf4j
......
......@@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author jie
* @author Zheng Jie
* @date 2018-12-25
*/
@Component
......
......@@ -11,7 +11,7 @@ import java.util.Date;
import static org.quartz.TriggerBuilder.newTrigger;
/**
* @author jie
* @author Zheng Jie
* @date 2019-01-07
*/
@Slf4j
......
......@@ -92,14 +92,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
).anonymous()
.antMatchers( HttpMethod.POST,"/auth/"+loginPath).anonymous()
.antMatchers("/websocket/**").anonymous()
.antMatchers("/auth/vCode").anonymous()
// 支付宝回调
.antMatchers("/api/aliPay/return").anonymous()
.antMatchers("/api/aliPay/notify").anonymous()
// 系统监控
.antMatchers("/actuator/**").anonymous()
// swagger start
.antMatchers("/swagger-ui.html").anonymous()
.antMatchers("/swagger-resources/**").anonymous()
......
package me.zhengjie.modules.security.rest;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.IdUtil;
import com.wf.captcha.Captcha;
import com.wf.captcha.SpecCaptcha;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.aop.log.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.monitor.service.RedisService;
import me.zhengjie.modules.security.security.AuthenticationInfo;
import me.zhengjie.modules.security.security.AuthorizationUser;
import me.zhengjie.modules.security.security.ImgResult;
import me.zhengjie.modules.security.security.JwtUser;
import me.zhengjie.utils.EncryptUtils;
import me.zhengjie.modules.security.utils.JwtTokenUtil;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
......@@ -16,9 +24,12 @@ import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* @author jie
* @author Zheng Jie
* @date 2018-11-23
* 授权、根据token获取用户详细信息
*/
......@@ -33,6 +44,9 @@ public class AuthenticationController {
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Autowired
private RedisService redisService;
@Autowired
@Qualifier("jwtUserDetailsService")
private UserDetailsService userDetailsService;
......@@ -46,6 +60,16 @@ public class AuthenticationController {
@PostMapping(value = "${jwt.auth.path}")
public ResponseEntity login(@Validated @RequestBody AuthorizationUser authorizationUser){
// 查询验证码
String code = redisService.getCodeVal(authorizationUser.getUuid());
// 清除验证码
redisService.delete(authorizationUser.getUuid());
if (StringUtils.isBlank(code)) {
throw new BadRequestException("验证码已过期");
}
if (StringUtils.isBlank(authorizationUser.getCode()) || !authorizationUser.getCode().equalsIgnoreCase(code)) {
throw new BadRequestException("验证码错误");
}
final JwtUser jwtUser = (JwtUser) userDetailsService.loadUserByUsername(authorizationUser.getUsername());
if(!jwtUser.getPassword().equals(EncryptUtils.encryptPassword(authorizationUser.getPassword()))){
......@@ -72,4 +96,33 @@ public class AuthenticationController {
JwtUser jwtUser = (JwtUser)userDetailsService.loadUserByUsername(SecurityUtils.getUsername());
return ResponseEntity.ok(jwtUser);
}
/**
* 获取验证码
*/
@GetMapping(value = "vCode")
public ImgResult getCode(HttpServletResponse response) throws IOException {
// 三个参数分别为宽、高、位数
SpecCaptcha specCaptcha = new SpecCaptcha(105, 33, 4);
// 设置类型,纯数字、纯字母、字母数字混合
specCaptcha.setCharType(Captcha.TYPE_DEFAULT);
// 生成的验证码
String code = specCaptcha.text();
String uuid = IdUtil.simpleUUID();
redisService.saveCode(uuid,code);
response.addHeader("codeUuid",uuid);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
specCaptcha.out(stream);
return new ImgResult(Base64.encode(stream.toByteArray()),uuid);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
stream.close();
}
}
}
......@@ -5,7 +5,7 @@ import lombok.Getter;
import java.io.Serializable;
/**
* @author jie
* @author Zheng Jie
* @date 2018-11-23
* 返回token
*/
......
......@@ -6,7 +6,7 @@ import lombok.Setter;
import javax.validation.constraints.NotBlank;
/**
* @author jie
* @author Zheng Jie
* @date 2018-11-30
*/
@Getter
......@@ -19,6 +19,10 @@ public class AuthorizationUser {
@NotBlank
private String password;
private String code;
private String uuid = "";
@Override
public String toString() {
return "{username=" + username + ", password= ******}";
......
package me.zhengjie.modules.security.security;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Zheng Jie
* @date 2019-6-5 17:29:57
*/
@Data
@AllArgsConstructor
public class ImgResult {
private String img;
private String uuid;
}
......@@ -11,7 +11,7 @@ import java.util.Date;
import java.util.stream.Collectors;
/**
* @author jie
* @author Zheng Jie
* @date 2018-11-23
*/
@Getter
......
package me.zhengjie.modules.security.service;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.modules.security.security.JwtUser;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.JobDTO;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
......@@ -16,7 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/**
* @author jie
* @author Zheng Jie
* @date 2018-11-22
*/
@Service
......@@ -48,8 +45,8 @@ public class JwtUserDetailsService implements UserDetailsService {
user.getAvatar(),
user.getEmail(),
user.getPhone(),
Optional.ofNullable(user.getDept()).map(DeptDTO::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(JobDTO::getName).orElse(null),
Optional.ofNullable(user.getDept()).map(DeptSmallDTO::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(JobSmallDTO::getName).orElse(null),
permissionService.mapToGrantedAuthorities(user),
user.getEnabled(),
user.getCreateTime(),
......
......@@ -11,7 +11,7 @@ import java.io.Serializable;
import java.util.Set;
/**
* @author jie
* @author Zheng Jie
* @date 2019-03-25
*/
@Entity
......
......@@ -10,7 +10,7 @@ import java.util.List;
import java.util.Set;
/**
* @author jie
* @author Zheng Jie
* @date 2019-04-10
*/
@Entity
......
......@@ -6,7 +6,7 @@ import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author jie
* @author Zheng Jie
* @date 2019-04-10
*/
@Entity
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment