实现验证码功能
前面我们实现了登陆页面改造并实现登陆,但我们忽略了验证码那个地方。

从上图中我们可以看到,我们的图形验证码是一张静态图片且尚未实现验证码功能。开干!
修改application配置文件
spring:security:# 登陆路径login-url: /login# 登出路径logout-url: /logout# 免认证静态资源路径anon-resources-url: /css/**,/js/**,/skin/**,/images/**,/font/**,/fonts/**,/dist/**# 放行路径release-url: /login,/getVerificationCode# 记住我超时时间remember-me-timeout: 300#验证码相关配置code:#图形验证码相关配置image:# 图形验证码图片长度(px)width: 130# 图形验证码图片高度(px)hight: 40# 图形验证码由(n)组成字符位数length: 4# 图形验证码失效时间(秒)expiration-in: 60# 以下资源需要验证图形验证码url: /user,/user/*# 对应登录页面 form表单的 action属性login-processing-url: /authentication/form
从上面代码中可以看到,我在release-url加入了/getVerificationCode该路径,目的是为了放行生成验证码功能接口。并且将login-processing-url放到了验证码下面。
验证码属性
/*** @Package: com.zlx.bpms.validate.properties* @Author: LQW* @Date: 2020/3/24* @Description:验证码属性*/
@Data
public class ValidateCodeProperties {/*** 图形验证码属性*/ImageCodeProperties image = new ImageCodeProperties();
}
图形验证码属性
/*** @Package: com.zlx.bpms.validate.properties.image* @Author: LQW* @Date: 2020/3/24* @Description:图形验证码属性*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ImageCodeProperties extends CommonProperties {/**** 图形验证码图片长度*/private int width;/*** 图形验证码图片高度*/private int hight;/*** 处理登陆认证URL(页面的action属性值)*/private String loginProcessingUrl;public ImageCodeProperties() {setLength(BpmsConstant.TheNumberDevil.FOUR);}
}
修改BpmsSecurityProperties配置属性
/*** @Package: com.zlx.bpms.properties* @Author: LQW* @Date: 2020/3/17* @Description:权限认证属性*/
@ConfigurationProperties(prefix = "spring.security")
@Data
public class BpmsSecurityProperties {/*** 登录路径*/private String loginUrl;/*** 登出路径*/private String logoutUrl;/*** 免认证静态资源路径*/private String anonResourcesUrl;/*** 放行路径*/private String releaseUrl;/*** 记住我超时时间*/private int rememberMeTimeout;/*** 验证码配置*/private ValidateCodeProperties code;
}
生成验证码