From: Xia Kaixiang Date: Fri, 19 Apr 2019 06:07:09 +0000 (+0800) Subject: 操作员、角色、功能表等 X-Git-Tag: 1.0.0^2~277 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=42a556e2aba3d8bf8e22c729e8027552e6d612b6;p=epayment%2Ffood_payapi.git 操作员、角色、功能表等 --- diff --git a/build.gradle b/build.gradle index 85ae14b6..c2dbbbc8 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ dependencies { implementation 'org.postgresql:postgresql:42.2.5' implementation 'com.jcabi:jcabi-manifests:1.1' implementation 'org.bitbucket.b_c:jose4j:0.6.3' + implementation 'org.springframework.social:spring-social-web:1.1.6.RELEASE' implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' implementation group: 'com.sun.jersey', name: 'jersey-client', version: '1.19' implementation group: 'javax.servlet', name: 'jstl', version: '1.2' diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/FunctionDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/FunctionDao.java new file mode 100644 index 00000000..d846c256 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/FunctionDao.java @@ -0,0 +1,9 @@ +package com.supwisdom.dlpay.framework.dao; + +import com.supwisdom.dlpay.framework.domain.TFunction; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FunctionDao extends JpaRepository { +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java new file mode 100644 index 00000000..72dc37ad --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java @@ -0,0 +1,15 @@ +package com.supwisdom.dlpay.framework.dao; + +import com.supwisdom.dlpay.framework.domain.TOperRole; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface OperRoleDao extends JpaRepository { + + @Query(value = "select distinct role_code from TB_OPER_ROLE a,TB_ROLE b where a.role_id=b.role_id and a.operid=?1", nativeQuery = true) + List getRolecodeByOperid(String operid); +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/OperatorDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/OperatorDao.java new file mode 100644 index 00000000..da67163f --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/OperatorDao.java @@ -0,0 +1,10 @@ +package com.supwisdom.dlpay.framework.dao; + +import com.supwisdom.dlpay.framework.domain.TOperator; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface OperatorDao extends JpaRepository { + TOperator findByOpercode(String opercode); +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ResourceDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ResourceDao.java new file mode 100644 index 00000000..b1a04a7c --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ResourceDao.java @@ -0,0 +1,9 @@ +package com.supwisdom.dlpay.framework.dao; + +import com.supwisdom.dlpay.framework.domain.TResource; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ResourceDao extends JpaRepository { +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/RoleDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/RoleDao.java new file mode 100644 index 00000000..25eee0d5 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/RoleDao.java @@ -0,0 +1,9 @@ +package com.supwisdom.dlpay.framework.dao; + +import com.supwisdom.dlpay.framework.domain.TRole; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RoleDao extends JpaRepository { +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TFunction.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TFunction.java new file mode 100644 index 00000000..7ccab750 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TFunction.java @@ -0,0 +1,100 @@ +package com.supwisdom.dlpay.framework.domain; + +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; + +@Entity +@Table(name = "TB_FUNCTION") +public class TFunction { + @Id + @GenericGenerator(name = "idGenerator", strategy = "uuid") + @GeneratedValue(generator = "idGenerator") + @Column(name="ID", nullable = false, length = 32) + private String id; + + @Column(name="PARENT_ID", length = 32) + private String parentId; + + @Column(name="NAME", length = 32) + private String name; + + @Column(name="MENU_URL", nullable = false, length = 60) + private String menuUrl; //菜单url + + @Column(name="IS_LEAF", nullable = false, precision = 1) + private Integer isLeaf; + + @Column(name="ORDER_NUM", precision = 9) + private Integer orderNum; + + @Column(name="CREATETIME", length = 14) + private String createtime; + + @Column(name="LASTSAVED", length = 14) + private String lastsaved; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getParentId() { + return parentId; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMenuUrl() { + return menuUrl; + } + + public void setMenuUrl(String menuUrl) { + this.menuUrl = menuUrl; + } + + public Integer getIsLeaf() { + return isLeaf; + } + + public void setIsLeaf(Integer isLeaf) { + this.isLeaf = isLeaf; + } + + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + public String getCreatetime() { + return createtime; + } + + public void setCreatetime(String createtime) { + this.createtime = createtime; + } + + public String getLastsaved() { + return lastsaved; + } + + public void setLastsaved(String lastsaved) { + this.lastsaved = lastsaved; + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TOperRole.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperRole.java new file mode 100644 index 00000000..f889fac2 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperRole.java @@ -0,0 +1,45 @@ +package com.supwisdom.dlpay.framework.domain; + +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; + +@Entity +@Table(name = "TB_OPER_ROLE") +public class TOperRole { + @Id + @GenericGenerator(name = "idGenerator", strategy = "uuid") + @GeneratedValue(generator = "idGenerator") + @Column(name="ID", nullable = false, length = 32) + private String id; + + @Column(name="ROLE_ID", nullable = false, length = 32) + private String roleId; + + @Column(name="OPERID", nullable = false, length = 32) + private String operid; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getRoleId() { + return roleId; + } + + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + public String getOperid() { + return operid; + } + + public void setOperid(String operid) { + this.operid = operid; + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java new file mode 100644 index 00000000..1da944b9 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java @@ -0,0 +1,146 @@ +package com.supwisdom.dlpay.framework.domain; + +import com.supwisdom.dlpay.framework.util.TradeDict; +import org.hibernate.annotations.GenericGenerator; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import javax.persistence.*; +import java.util.Collection; + +@Entity +@Table(name = "TB_OPERATOR") +public class TOperator implements UserDetails { + @Id + @GenericGenerator(name = "idGenerator", strategy = "uuid") + @GeneratedValue(generator = "idGenerator") + @Column(name="OPERID", nullable = false, length = 32) + private String operid; + + @Column(name="OPERCODE", nullable = false, length = 20) + private String opercode; + + @Column(name="OPERTYPE", nullable = false, length = 20) + private String opertype; + + @Column(name="OPERNAME", nullable = false, length = 100) + private String opername; + + @Column(name="OPERPWD", nullable = false, length = 32) + private String operpwd; + + @Column(name="STATUS", nullable = false, length = 32) + private String status; + + @Column(name="OPENDATE", length = 8) + private String opendate; + + @Column(name="CLOSEDATE", length = 8) + private String closedate; + + @Transient + private Collection authorities; //权限 + + public String getOperid() { + return operid; + } + + public void setOperid(String operid) { + this.operid = operid; + } + + public String getOpercode() { + return opercode; + } + + public void setOpercode(String opercode) { + this.opercode = opercode; + } + + public String getOpertype() { + return opertype; + } + + public void setOpertype(String opertype) { + this.opertype = opertype; + } + + public String getOpername() { + return opername; + } + + public void setOpername(String opername) { + this.opername = opername; + } + + public String getOperpwd() { + return operpwd; + } + + public void setOperpwd(String operpwd) { + this.operpwd = operpwd; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getOpendate() { + return opendate; + } + + public void setOpendate(String opendate) { + this.opendate = opendate; + } + + public String getClosedate() { + return closedate; + } + + public void setClosedate(String closedate) { + this.closedate = closedate; + } + + public void setAuthorities(Collection authorities) { + this.authorities = authorities; + } + + @Override + public Collection getAuthorities() { + return this.authorities; + } + + @Override + public String getPassword() { + return this.operpwd; + } + + @Override + public String getUsername() { + return this.opercode; + } + + @Override + public boolean isAccountNonExpired() { + return true; //账户不会过期 + } + + @Override + public boolean isAccountNonLocked() { + return !TradeDict.STATUS_LOCKED.equals(this.status); //true - 没锁定 + } + + @Override + public boolean isCredentialsNonExpired() { + return true; //TODO:密码是否未过期 + } + + @Override + public boolean isEnabled() { + return !TradeDict.STATUS_CLOSED.equals(this.status); //注销操作员不启用 + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TResource.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TResource.java new file mode 100644 index 00000000..889eacae --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TResource.java @@ -0,0 +1,66 @@ +package com.supwisdom.dlpay.framework.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "TB_RESOURCE") +public class TResource { + @Id + @Column(name = "ID", nullable = false, length = 32) + private String id; + + @Column(name = "CODE", nullable = false, length = 32) + private String code; + + @Column(name = "NAME", length = 32) + private String name; + + @Column(name = "URI", length = 32) + private String uri; + + @Column(name = "FUNCTION_ID", nullable = false, length = 32) + private String functionId; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getFunctionId() { + return functionId; + } + + public void setFunctionId(String functionId) { + this.functionId = functionId; + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TRole.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TRole.java new file mode 100644 index 00000000..6be9d78f --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TRole.java @@ -0,0 +1,89 @@ +package com.supwisdom.dlpay.framework.domain; + +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; + +@Entity +@Table(name = "TB_ROLE") +public class TRole { + @Id + @GenericGenerator(name = "idGenerator", strategy = "uuid") + @GeneratedValue(generator = "idGenerator") + @Column(name="ROLE_ID", nullable = false, length = 32) + private String roleId; + + @Column(name="ROLE_NAME", nullable = false, length = 60) + private String roleName; + + @Column(name="ROLE_CODE", nullable = false, length = 20) + private String roleCode; + + @Column(name="ROLE_DESC", length = 60) + private String roleDesc; + + @Column(name="EDITFLAG", length = 60) + private Integer editflag; + + @Column(name="CREATETIME", length = 14) + private String createtime; + + @Column(name="LASTSAVED", length = 14) + private String lastsaved; + + public String getRoleId() { + return roleId; + } + + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + public String getRoleCode() { + return roleCode; + } + + public void setRoleCode(String roleCode) { + this.roleCode = roleCode; + } + + public String getRoleDesc() { + return roleDesc; + } + + public void setRoleDesc(String roleDesc) { + this.roleDesc = roleDesc; + } + + public Integer getEditflag() { + return editflag; + } + + public void setEditflag(Integer editflag) { + this.editflag = editflag; + } + + public String getCreatetime() { + return createtime; + } + + public void setCreatetime(String createtime) { + this.createtime = createtime; + } + + public String getLastsaved() { + return lastsaved; + } + + public void setLastsaved(String lastsaved) { + this.lastsaved = lastsaved; + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java b/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java index e4e7afb8..fd8c4d1d 100755 --- a/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java +++ b/src/main/java/com/supwisdom/dlpay/framework/filter/ValidateCodeFilter.java @@ -4,6 +4,7 @@ package com.supwisdom.dlpay.framework.filter; import com.supwisdom.dlpay.exception.ValidateCodeException; import com.supwisdom.dlpay.framework.security.validate.ImageCode; import com.supwisdom.dlpay.framework.security.validate.ImageCodeUtil; +import com.supwisdom.dlpay.framework.security.validate.VerifyCode; import com.supwisdom.dlpay.framework.util.StringUtil; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; @@ -51,7 +52,7 @@ public class ValidateCodeFilter extends OncePerRequestFilter implements Initiali } private void validate(HttpServletRequest request) throws ValidateCodeException { - ImageCode imageCode = (ImageCode) request.getSession().getAttribute(ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY); + VerifyCode imageCode = (VerifyCode) request.getSession().getAttribute(ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY); String inputCode; try { inputCode = request.getParameter("imageCode"); @@ -64,11 +65,11 @@ public class ValidateCodeFilter extends OncePerRequestFilter implements Initiali if (null == imageCode) { throw new ValidateCodeException("验证码不存在"); } - if (imageCode.isExpried()) { + if (imageCode.isExpired()) { request.getSession().removeAttribute(ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY); throw new ValidateCodeException("验证码已过期"); } - if (!StringUtil.equalsIgnoreCase(imageCode.getCode(), inputCode)) { + if (!StringUtil.equalsIgnoreCase(imageCode.getText(), inputCode)) { throw new ValidateCodeException("验证码不匹配"); } request.getSession().removeAttribute(ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY); diff --git a/src/main/java/com/supwisdom/dlpay/framework/security/validate/ImageCodeUtil.java b/src/main/java/com/supwisdom/dlpay/framework/security/validate/ImageCodeUtil.java index 19fd80ac..0a105b9b 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/security/validate/ImageCodeUtil.java +++ b/src/main/java/com/supwisdom/dlpay/framework/security/validate/ImageCodeUtil.java @@ -1,7 +1,5 @@ package com.supwisdom.dlpay.framework.security.validate; -import org.springframework.web.context.request.ServletWebRequest; - import javax.servlet.http.HttpServletRequest; import java.awt.*; import java.awt.image.BufferedImage; diff --git a/src/main/java/com/supwisdom/dlpay/framework/security/validate/ValidateCode.java b/src/main/java/com/supwisdom/dlpay/framework/security/validate/ValidateCode.java index a26f63f7..b20eca2e 100755 --- a/src/main/java/com/supwisdom/dlpay/framework/security/validate/ValidateCode.java +++ b/src/main/java/com/supwisdom/dlpay/framework/security/validate/ValidateCode.java @@ -44,7 +44,7 @@ public class ValidateCode{ } @JsonIgnore - public boolean isExpried() { + public boolean isExpired() { return new Date().compareTo(expireTime) > 0; } diff --git a/src/main/java/com/supwisdom/dlpay/framework/security/validate/VerifyCode.java b/src/main/java/com/supwisdom/dlpay/framework/security/validate/VerifyCode.java new file mode 100644 index 00000000..30f368af --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/security/validate/VerifyCode.java @@ -0,0 +1,123 @@ +package com.supwisdom.dlpay.framework.security.validate; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.OutputStream; +import java.time.LocalDateTime; +import java.util.Random; + +public class VerifyCode { + private int w = 70; + private int h = 35; + private Random r = new Random(); + // {"宋体", "华文楷体", "黑体", "华文新魏", "华文隶书", "微软雅黑", "楷体_GB2312"} + private String[] fontNames = {"宋体", "华文楷体", "黑体", "微软雅黑", "楷体_GB2312"}; + // 可选字符 + private String codes = "0123456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ"; + // 背景色 + private Color bgColor = new Color(255, 255, 255); + // 验证码上的文本 + private String text ; + + public VerifyCode() { + } + public VerifyCode(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + public VerifyCode(int second) { + // 多少秒后 + this.localDateTime = LocalDateTime.now().plusSeconds(second); + } + + + //过期时间 + private LocalDateTime localDateTime; + // 生成随机的颜色 + private Color randomColor () { + int red = r.nextInt(150); + int green = r.nextInt(150); + int blue = r.nextInt(150); + return new Color(red, green, blue); + } + + // 生成随机的字体 + private Font randomFont () { + int index = r.nextInt(fontNames.length); + String fontName = fontNames[index];//生成随机的字体名称 + int style = r.nextInt(4);//生成随机的样式, 0(无样式), 1(粗体), 2(斜体), 3(粗体+斜体) + int size = r.nextInt(5) + 24; //生成随机字号, 24 ~ 28 + return new Font(fontName, style, size); + } + + // 画干扰线 + private void drawLine (BufferedImage image) { + int num = 3;//一共画3条 + Graphics2D g2 = (Graphics2D)image.getGraphics(); + for(int i = 0; i < num; i++) {//生成两个点的坐标,即4个值 + int x1 = r.nextInt(w); + int y1 = r.nextInt(h); + int x2 = r.nextInt(w); + int y2 = r.nextInt(h); + g2.setStroke(new BasicStroke(1.5F)); + g2.setColor(Color.BLUE); //干扰线是蓝色 + g2.drawLine(x1, y1, x2, y2);//画线 + } + } + + // 随机生成一个字符 + private char randomChar () { + int index = r.nextInt(codes.length()); + return codes.charAt(index); + } + + // 创建BufferedImage + private BufferedImage createImage () { + BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = (Graphics2D)image.getGraphics(); + g2.setColor(this.bgColor); + g2.fillRect(0, 0, w, h); + return image; + } + + // 调用这个方法得到验证码 + public BufferedImage getImage () { + BufferedImage image = createImage();//创建图片缓冲区 + Graphics2D g2 = (Graphics2D)image.getGraphics();//得到绘制环境 + StringBuilder sb = new StringBuilder();//用来装载生成的验证码文本 + // 向图片中画4个字符 + for(int i = 0; i < 4; i++) {//循环四次,每次生成一个字符 + String s = randomChar() + "";//随机生成一个字母 + sb.append(s); //把字母添加到sb中 + float x = i * 1.0F * w / 4; //设置当前字符的x轴坐标 + g2.setFont(randomFont()); //设置随机字体 + g2.setColor(randomColor()); //设置随机颜色 + g2.drawString(s, x, h-5); //画图 + } + this.text = sb.toString(); //把生成的字符串赋给了this.text + drawLine(image); //添加干扰线 + return image; + } + + // 返回验证码图片上的文本 + public String getText () { + return text; + } + + // 保存图片到指定的输出流 + public static void output (BufferedImage image, OutputStream out) + throws IOException { + ImageIO.write(image, "JPEG", out); + } + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + public boolean isExpired(){ + return LocalDateTime.now().isAfter(localDateTime); + } +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/service/OperatorDetailService.java b/src/main/java/com/supwisdom/dlpay/framework/service/OperatorDetailService.java new file mode 100644 index 00000000..bf72bfe0 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/service/OperatorDetailService.java @@ -0,0 +1,6 @@ +package com.supwisdom.dlpay.framework.service; + +import org.springframework.security.core.userdetails.UserDetailsService; + +public interface OperatorDetailService extends UserDetailsService { +} diff --git a/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java b/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java new file mode 100644 index 00000000..755828d2 --- /dev/null +++ b/src/main/java/com/supwisdom/dlpay/framework/service/impl/OperatorDetailServiceImpl.java @@ -0,0 +1,42 @@ +package com.supwisdom.dlpay.framework.service.impl; + +import com.supwisdom.dlpay.framework.dao.OperRoleDao; +import com.supwisdom.dlpay.framework.dao.OperatorDao; +import com.supwisdom.dlpay.framework.domain.TOperator; +import com.supwisdom.dlpay.framework.service.OperatorDetailService; +import com.supwisdom.dlpay.framework.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@Service +public class OperatorDetailServiceImpl implements OperatorDetailService { + @Autowired + private OperatorDao operatorDao; + @Autowired + private OperRoleDao operRoleDao; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + TOperator oper = operatorDao.findByOpercode(username); + if (null == oper) { + throw new UsernameNotFoundException("管理员不存在"); + } + Collection authorities = new ArrayList() { + }; + + List roles = operRoleDao.getRolecodeByOperid(oper.getOperid()); + if (!StringUtil.isEmpty(roles)) { + authorities = AuthorityUtils.createAuthorityList(roles.toArray(new String[0])); + } + oper.setAuthorities(authorities); + return oper; + } +} diff --git a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt index 9befb054..c13dae9c 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/DlpayApplication.kt @@ -1,5 +1,6 @@ package com.supwisdom.dlpay +import com.supwisdom.dlpay.framework.filter.ValidateCodeFilter import com.supwisdom.dlpay.framework.security.MyAuthenticationFailureHandler import com.supwisdom.dlpay.framework.security.MyAuthenticationSuccessHandler import io.lettuce.core.ReadFrom @@ -27,6 +28,7 @@ import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.provisioning.InMemoryUserDetailsManager import org.springframework.security.web.authentication.AuthenticationFailureHandler import org.springframework.security.web.authentication.logout.CookieClearingLogoutHandler +import javax.servlet.Filter @Configuration diff --git a/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt index 8c39312b..e776623e 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/framework/controller/security_controller.kt @@ -6,14 +6,17 @@ import com.supwisdom.dlpay.framework.dao.ApiClientDao import com.supwisdom.dlpay.framework.domain.AppClientRedis import com.supwisdom.dlpay.framework.redisrepo.AppClientRepository import com.supwisdom.dlpay.framework.security.validate.ImageCodeUtil +import com.supwisdom.dlpay.framework.security.validate.VerifyCode import com.supwisdom.dlpay.framework.service.SystemUtilService import com.supwisdom.dlpay.framework.util.HmacUtil import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.ResponseEntity +import org.springframework.social.connect.web.HttpSessionSessionStrategy import org.springframework.stereotype.Controller import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import org.springframework.web.context.request.ServletWebRequest import java.util.* import javax.imageio.ImageIO import javax.servlet.http.HttpServletRequest @@ -99,16 +102,19 @@ class ApiAuthController { class ValidateCodeController{ @GetMapping("/code/image") - fun createCode(request: HttpServletRequest,response: HttpServletResponse){ - val imageCode = ImageCodeUtil.generate(request) - request.getSession(true).setAttribute(ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY,imageCode) - ImageIO.write(imageCode.image,"JPEG", response.outputStream) + fun createCode(request: HttpServletRequest, response: HttpServletResponse) { + val imageCode = VerifyCode(60) + HttpSessionSessionStrategy().setAttribute(ServletWebRequest(request), ImageCodeUtil.LOGIN_IMAGECODE_SESSIONKEY, imageCode) + ImageIO.write(imageCode.image, "JPEG", response.outputStream) } } @Controller class WebHomeController { + @GetMapping("/{index}") + fun homeView() = "index" + @GetMapping("/login") fun loginView() = "login" } \ No newline at end of file