diff --git a/README.md b/README.md index 0ab222a..ea63a07 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,10 @@ ## 2018.03.05 spring boot 由1.5.10 升级到2.0.0 ## 2018.03.15上传文件的大小配置修改spring.http.multipart改为spring.servlet.multipart ## 2018.04.14 layui升级到2.2.6 +## 2018.05.16 修改druid +1. pom中删除druid依赖,改为druid-spring-boot-starter +2. 作废DruidConfig类,druid支持自动注入了,前缀spring.datasource.druid +源码com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper +3. 修改application.yml里的数据源配置,spring.datasource改为spring.datasource.druid + + diff --git a/pom.xml b/pom.xml index 3ec181a..7286cbc 100644 --- a/pom.xml +++ b/pom.xml @@ -1,148 +1,143 @@ - 4.0.0 - com.boot - boot-security - 1.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.boot + boot-security + 1.0 - - org.springframework.boot - spring-boot-starter-parent - 2.0.1.RELEASE - + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + - - 1.8 - 2.8.0 - 23.0 - 1.2.47 - 1.1.8 - 3.17 - 0.9.0 - 1.3.2 - + + 1.8 + 2.8.0 + 23.0 + 1.2.47 + 1.1.8 + 3.17 + 0.9.0 + 1.3.2 + - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-aop - - - org.springframework.boot - spring-boot-starter-actuator - - - com.google.guava - guava - ${google.guava} - - - org.apache.commons - commons-lang3 - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - - commons-codec - commons-codec - - - com.alibaba - fastjson - ${fastjson.version} - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-security - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis.version} - - - mysql - mysql-connector-java - runtime - - - com.alibaba - druid - ${druid.version} - - - - log4j - log4j - 1.2.17 + + + org.springframework.boot + spring-boot-starter-test + test - - io.springfox - springfox-swagger2 - ${swagger.version} - - - io.springfox - springfox-bean-validators - ${swagger.version} - - - io.springfox - springfox-swagger-ui - ${swagger.version} - - - org.springframework.boot - spring-boot-starter-mail - - - org.springframework.boot - spring-boot-starter-data-redis - - - org.quartz-scheduler - quartz - - - org.springframework - spring-context-support - - - org.apache.poi - poi - ${poi.version} - - - io.jsonwebtoken - jjwt - ${jwt.version} - - + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-actuator + + + com.google.guava + guava + ${google.guava} + + + org.apache.commons + commons-lang3 + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + + + commons-codec + commons-codec + + + com.alibaba + fastjson + ${fastjson.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis.version} + + + mysql + mysql-connector-java + runtime + + + + com.alibaba + druid-spring-boot-starter + 1.1.9 + + + io.springfox + springfox-swagger2 + ${swagger.version} + + + io.springfox + springfox-bean-validators + ${swagger.version} + + + io.springfox + springfox-swagger-ui + ${swagger.version} + + + org.springframework.boot + spring-boot-starter-mail + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.quartz-scheduler + quartz + + + org.springframework + spring-context-support + + + org.apache.poi + poi + ${poi.version} + + + io.jsonwebtoken + jjwt + ${jwt.version} + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + \ No newline at end of file diff --git a/src/main/java/com/boot/security/server/config/DruidConfig.java b/src/main/java/com/boot/security/server/config/DruidConfig.java index ba084ee..f9cf60f 100644 --- a/src/main/java/com/boot/security/server/config/DruidConfig.java +++ b/src/main/java/com/boot/security/server/config/DruidConfig.java @@ -1,258 +1,260 @@ package com.boot.security.server.config; -import java.sql.SQLException; - -import javax.sql.DataSource; - +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.support.http.StatViewServlet; -import com.alibaba.druid.support.http.WebStatFilter; +import javax.sql.DataSource; +import java.sql.SQLException; /** - * Druid数据源配置 - * - * @author 小威老师 + * Druid数据源配置
+ * 2018.05.16 作废该配置类,因为druid提供了druid-spring-boot-starter,看下pom.xml
+ * 直接在bootstrap.yml里就能配置druid数据源了
+ * 前缀spring.datasource.druid,具体看下druid自动注入源码 DruidDataSourceWrapper * + * @author 小威老师 + * @see com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper */ -@Configuration +//@Configuration +@Deprecated public class DruidConfig { - private static final Logger log = LoggerFactory.getLogger("adminLogger"); + private static final Logger log = LoggerFactory.getLogger("adminLogger"); - @Bean - public ServletRegistrationBean druidServlet() { - log.info("init Druid Servlet Configuration "); - ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>( - new StatViewServlet(), "/druid/*"); - // IP白名单 - servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); - // IP黑名单(共同存在时,deny优先于allow) + @Bean + public ServletRegistrationBean druidServlet() { + log.info("init Druid Servlet Configuration "); + ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>( + new StatViewServlet(), "/druid/*"); + // IP白名单 + servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); + // IP黑名单(共同存在时,deny优先于allow) // servletRegistrationBean.addInitParameter("deny", "192.168.27.26"); // // 控制台管理用户 // servletRegistrationBean.addInitParameter("loginUsername", "admin"); // servletRegistrationBean.addInitParameter("loginPassword", "admin"); // // 是否能够重置数据 禁用HTML页面上的“Reset All”功能 // servletRegistrationBean.addInitParameter("resetEnable", "false"); - return servletRegistrationBean; - } + return servletRegistrationBean; + } - @Bean - public FilterRegistrationBean filterRegistrationBean() { - FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>( - new WebStatFilter()); - filterRegistrationBean.addUrlPatterns("/*"); - filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); - return filterRegistrationBean; - } + @Bean + public FilterRegistrationBean filterRegistrationBean() { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>( + new WebStatFilter()); + filterRegistrationBean.addUrlPatterns("/*"); + filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); + return filterRegistrationBean; + } - /** - * 数据源配置 - * - * @author 小威老师 - * - */ - @ConfigurationProperties(prefix = "spring.datasource") - public class DataSourceProperties { - private String url; - private String username; - private String password; - private String driverClassName; - private int initialSize; - private int minIdle; - private int maxActive; - private int maxWait; - private int timeBetweenEvictionRunsMillis; - private int minEvictableIdleTimeMillis; - private String validationQuery; - private boolean testWhileIdle; - private boolean testOnBorrow; - private boolean testOnReturn; - private boolean poolPreparedStatements; - private int maxPoolPreparedStatementPerConnectionSize; - private String filters; - private String connectionProperties; + /** + * 数据源配置 + * + * @author 小威老师 + */ +// @ConfigurationProperties(prefix = "spring.datasource") + @Deprecated + public class DataSourceProperties { + private String url; + private String username; + private String password; + private String driverClassName; + private int initialSize; + private int minIdle; + private int maxActive; + private int maxWait; + private int timeBetweenEvictionRunsMillis; + private int minEvictableIdleTimeMillis; + private String validationQuery; + private boolean testWhileIdle; + private boolean testOnBorrow; + private boolean testOnReturn; + private boolean poolPreparedStatements; + private int maxPoolPreparedStatementPerConnectionSize; + private String filters; + private String connectionProperties; - public String getUrl() { - return url; - } + public String getUrl() { + return url; + } - public void setUrl(String url) { - this.url = url; - } + public void setUrl(String url) { + this.url = url; + } - public String getUsername() { - return username; - } + public String getUsername() { + return username; + } - public void setUsername(String username) { - this.username = username; - } + public void setUsername(String username) { + this.username = username; + } - public String getPassword() { - return password; - } + public String getPassword() { + return password; + } - public void setPassword(String password) { - this.password = password; - } + public void setPassword(String password) { + this.password = password; + } - public String getDriverClassName() { - return driverClassName; - } + public String getDriverClassName() { + return driverClassName; + } - public void setDriverClassName(String driverClassName) { - this.driverClassName = driverClassName; - } + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } - public int getInitialSize() { - return initialSize; - } + public int getInitialSize() { + return initialSize; + } - public void setInitialSize(int initialSize) { - this.initialSize = initialSize; - } + public void setInitialSize(int initialSize) { + this.initialSize = initialSize; + } - public int getMinIdle() { - return minIdle; - } + public int getMinIdle() { + return minIdle; + } - public void setMinIdle(int minIdle) { - this.minIdle = minIdle; - } + public void setMinIdle(int minIdle) { + this.minIdle = minIdle; + } - public int getMaxActive() { - return maxActive; - } + public int getMaxActive() { + return maxActive; + } - public void setMaxActive(int maxActive) { - this.maxActive = maxActive; - } + public void setMaxActive(int maxActive) { + this.maxActive = maxActive; + } - public int getMaxWait() { - return maxWait; - } + public int getMaxWait() { + return maxWait; + } - public void setMaxWait(int maxWait) { - this.maxWait = maxWait; - } + public void setMaxWait(int maxWait) { + this.maxWait = maxWait; + } - public int getTimeBetweenEvictionRunsMillis() { - return timeBetweenEvictionRunsMillis; - } + public int getTimeBetweenEvictionRunsMillis() { + return timeBetweenEvictionRunsMillis; + } - public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { - this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; - } + public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { + this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; + } - public int getMinEvictableIdleTimeMillis() { - return minEvictableIdleTimeMillis; - } + public int getMinEvictableIdleTimeMillis() { + return minEvictableIdleTimeMillis; + } - public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) { - this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; - } + public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) { + this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; + } - public String getValidationQuery() { - return validationQuery; - } + public String getValidationQuery() { + return validationQuery; + } - public void setValidationQuery(String validationQuery) { - this.validationQuery = validationQuery; - } + public void setValidationQuery(String validationQuery) { + this.validationQuery = validationQuery; + } - public boolean isTestWhileIdle() { - return testWhileIdle; - } + public boolean isTestWhileIdle() { + return testWhileIdle; + } - public void setTestWhileIdle(boolean testWhileIdle) { - this.testWhileIdle = testWhileIdle; - } + public void setTestWhileIdle(boolean testWhileIdle) { + this.testWhileIdle = testWhileIdle; + } - public boolean isTestOnBorrow() { - return testOnBorrow; - } + public boolean isTestOnBorrow() { + return testOnBorrow; + } - public void setTestOnBorrow(boolean testOnBorrow) { - this.testOnBorrow = testOnBorrow; - } + public void setTestOnBorrow(boolean testOnBorrow) { + this.testOnBorrow = testOnBorrow; + } - public boolean isTestOnReturn() { - return testOnReturn; - } + public boolean isTestOnReturn() { + return testOnReturn; + } - public void setTestOnReturn(boolean testOnReturn) { - this.testOnReturn = testOnReturn; - } + public void setTestOnReturn(boolean testOnReturn) { + this.testOnReturn = testOnReturn; + } - public boolean isPoolPreparedStatements() { - return poolPreparedStatements; - } + public boolean isPoolPreparedStatements() { + return poolPreparedStatements; + } - public void setPoolPreparedStatements(boolean poolPreparedStatements) { - this.poolPreparedStatements = poolPreparedStatements; - } + public void setPoolPreparedStatements(boolean poolPreparedStatements) { + this.poolPreparedStatements = poolPreparedStatements; + } - public int getMaxPoolPreparedStatementPerConnectionSize() { - return maxPoolPreparedStatementPerConnectionSize; - } + public int getMaxPoolPreparedStatementPerConnectionSize() { + return maxPoolPreparedStatementPerConnectionSize; + } - public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) { - this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; - } + public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) { + this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; + } - public String getFilters() { - return filters; - } + public String getFilters() { + return filters; + } - public void setFilters(String filters) { - this.filters = filters; - } + public void setFilters(String filters) { + this.filters = filters; + } - public String getConnectionProperties() { - return connectionProperties; - } + public String getConnectionProperties() { + return connectionProperties; + } - public void setConnectionProperties(String connectionProperties) { - this.connectionProperties = connectionProperties; - } + public void setConnectionProperties(String connectionProperties) { + this.connectionProperties = connectionProperties; + } - @Bean - @Primary - public DataSource dataSource() { - DruidDataSource datasource = new DruidDataSource(); - datasource.setUrl(url); - datasource.setUsername(username); - datasource.setPassword(password); - datasource.setDriverClassName(driverClassName); + // @Bean +// @Primary + @Deprecated + public DataSource dataSource() { + DruidDataSource datasource = new DruidDataSource(); + datasource.setUrl(url); + datasource.setUsername(username); + datasource.setPassword(password); + datasource.setDriverClassName(driverClassName); - datasource.setInitialSize(initialSize); - datasource.setMinIdle(minIdle); - datasource.setMaxActive(maxActive); - datasource.setMaxWait(maxWait); - datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); - datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); - datasource.setValidationQuery(validationQuery); - datasource.setTestWhileIdle(testWhileIdle); - datasource.setTestOnBorrow(testOnBorrow); - datasource.setTestOnReturn(testOnReturn); - datasource.setPoolPreparedStatements(poolPreparedStatements); - datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); - try { - datasource.setFilters(filters); - } catch (SQLException e) { - log.error("异常", e); - } - datasource.setConnectionProperties(connectionProperties); - return datasource; - } - } + datasource.setInitialSize(initialSize); + datasource.setMinIdle(minIdle); + datasource.setMaxActive(maxActive); + datasource.setMaxWait(maxWait); + datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); + datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); + datasource.setValidationQuery(validationQuery); + datasource.setTestWhileIdle(testWhileIdle); + datasource.setTestOnBorrow(testOnBorrow); + datasource.setTestOnReturn(testOnReturn); + datasource.setPoolPreparedStatements(poolPreparedStatements); + datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); + try { + datasource.setFilters(filters); + } catch (SQLException e) { + log.error("异常", e); + } + datasource.setConnectionProperties(connectionProperties); + return datasource; + } + } } diff --git a/src/main/java/com/boot/security/server/service/impl/TokenServiceImpl.java b/src/main/java/com/boot/security/server/service/impl/TokenServiceImpl.java index d75d1fd..9089b62 100644 --- a/src/main/java/com/boot/security/server/service/impl/TokenServiceImpl.java +++ b/src/main/java/com/boot/security/server/service/impl/TokenServiceImpl.java @@ -1,17 +1,15 @@ package com.boot.security.server.service.impl; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - import com.boot.security.server.dto.LoginUser; import com.boot.security.server.dto.Token; import com.boot.security.server.service.SysLogService; import com.boot.security.server.service.TokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; /** * token存到redis的实现类
@@ -21,7 +19,7 @@ import com.boot.security.server.service.TokenService; * */ @Deprecated -@Service +//@Service public class TokenServiceImpl implements TokenService { /** diff --git a/src/main/java/com/boot/security/server/service/impl/TokenServiceJWTImpl.java b/src/main/java/com/boot/security/server/service/impl/TokenServiceJWTImpl.java index e5e92bb..838062b 100644 --- a/src/main/java/com/boot/security/server/service/impl/TokenServiceJWTImpl.java +++ b/src/main/java/com/boot/security/server/service/impl/TokenServiceJWTImpl.java @@ -31,136 +31,135 @@ import io.jsonwebtoken.SignatureAlgorithm; /** * token存到redis的实现类
* jwt实现的token - * - * @author 小威老师 * + * @author 小威老师 */ @Primary @Service public class TokenServiceJWTImpl implements TokenService { - private static final Logger log = LoggerFactory.getLogger("adminLogger"); + private static final Logger log = LoggerFactory.getLogger("adminLogger"); - /** - * token过期秒数 - */ - @Value("${token.expire.seconds}") - private Integer expireSeconds; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private SysLogService logService; - /** - * 私钥 - */ - @Value("${token.jwtSecret}") - private String jwtSecret; + /** + * token过期秒数 + */ + @Value("${token.expire.seconds}") + private Integer expireSeconds; + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private SysLogService logService; + /** + * 私钥 + */ + @Value("${token.jwtSecret}") + private String jwtSecret; - private static Key KEY = null; - private static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; + private static Key KEY = null; + private static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; - @Override - public Token saveToken(LoginUser loginUser) { - loginUser.setToken(UUID.randomUUID().toString()); - cacheLoginUser(loginUser); - // 登陆日志 - logService.save(loginUser.getId(), "登陆", true, null); + @Override + public Token saveToken(LoginUser loginUser) { + loginUser.setToken(UUID.randomUUID().toString()); + cacheLoginUser(loginUser); + // 登陆日志 + logService.save(loginUser.getId(), "登陆", true, null); - String jwtToken = createJWTToken(loginUser); + String jwtToken = createJWTToken(loginUser); - return new Token(jwtToken, loginUser.getLoginTime()); - } + return new Token(jwtToken, loginUser.getLoginTime()); + } - /** - * 生成jwt - * - * @param loginUser - * @return - */ - private String createJWTToken(LoginUser loginUser) { - Map claims = new HashMap<>(); - claims.put(LOGIN_USER_KEY, loginUser.getToken());// 放入一个随机字符串,通过该串可找到登陆用户 + /** + * 生成jwt + * + * @param loginUser + * @return + */ + private String createJWTToken(LoginUser loginUser) { + Map claims = new HashMap<>(); + claims.put(LOGIN_USER_KEY, loginUser.getToken());// 放入一个随机字符串,通过该串可找到登陆用户 - String jwtToken = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS256, getKeyInstance()) - .compact(); + String jwtToken = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS256, getKeyInstance()) + .compact(); - return jwtToken; - } + return jwtToken; + } - private void cacheLoginUser(LoginUser loginUser) { - loginUser.setLoginTime(System.currentTimeMillis()); - loginUser.setExpireTime(loginUser.getLoginTime() + expireSeconds * 1000); - // 根据uuid将loginUser缓存 - redisTemplate.boundValueOps(getTokenKey(loginUser.getToken())).set(loginUser, expireSeconds, TimeUnit.SECONDS); - } + private void cacheLoginUser(LoginUser loginUser) { + loginUser.setLoginTime(System.currentTimeMillis()); + loginUser.setExpireTime(loginUser.getLoginTime() + expireSeconds * 1000); + // 根据uuid将loginUser缓存 + redisTemplate.boundValueOps(getTokenKey(loginUser.getToken())).set(loginUser, expireSeconds, TimeUnit.SECONDS); + } - /** - * 更新缓存的用户信息 - */ - @Override - public void refresh(LoginUser loginUser) { - cacheLoginUser(loginUser); - } + /** + * 更新缓存的用户信息 + */ + @Override + public void refresh(LoginUser loginUser) { + cacheLoginUser(loginUser); + } - @Override - public LoginUser getLoginUser(String jwtToken) { - String uuid = getUUIDFromJWT(jwtToken); - if (uuid != null) { - return redisTemplate.boundValueOps(getTokenKey(uuid)).get(); - } + @Override + public LoginUser getLoginUser(String jwtToken) { + String uuid = getUUIDFromJWT(jwtToken); + if (uuid != null) { + return redisTemplate.boundValueOps(getTokenKey(uuid)).get(); + } - return null; - } + return null; + } - @Override - public boolean deleteToken(String jwtToken) { - String uuid = getUUIDFromJWT(jwtToken); - if (uuid != null) { - String key = getTokenKey(uuid); - LoginUser loginUser = redisTemplate.opsForValue().get(key); - if (loginUser != null) { - redisTemplate.delete(key); - // 退出日志 - logService.save(loginUser.getId(), "退出", true, null); + @Override + public boolean deleteToken(String jwtToken) { + String uuid = getUUIDFromJWT(jwtToken); + if (uuid != null) { + String key = getTokenKey(uuid); + LoginUser loginUser = redisTemplate.opsForValue().get(key); + if (loginUser != null) { + redisTemplate.delete(key); + // 退出日志 + logService.save(loginUser.getId(), "退出", true, null); - return true; - } - } + return true; + } + } - return false; - } + return false; + } - private String getTokenKey(String uuid) { - return "tokens:" + uuid; - } + private String getTokenKey(String uuid) { + return "tokens:" + uuid; + } - private Key getKeyInstance() { - if (KEY == null) { - synchronized (TokenServiceJWTImpl.class) { - if (KEY == null) {// 双重锁 - byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(jwtSecret); - KEY = new SecretKeySpec(apiKeySecretBytes, SignatureAlgorithm.HS256.getJcaName()); - } - } - } + private Key getKeyInstance() { + if (KEY == null) { + synchronized (TokenServiceJWTImpl.class) { + if (KEY == null) {// 双重锁 + byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(jwtSecret); + KEY = new SecretKeySpec(apiKeySecretBytes, SignatureAlgorithm.HS256.getJcaName()); + } + } + } - return KEY; - } + return KEY; + } - private String getUUIDFromJWT(String jwtToken) { - if ("null".equals(jwtToken) || StringUtils.isBlank(jwtToken)) { - return null; - } + private String getUUIDFromJWT(String jwtToken) { + if ("null".equals(jwtToken) || StringUtils.isBlank(jwtToken)) { + return null; + } - try { - Map jwtClaims = Jwts.parser().setSigningKey(getKeyInstance()).parseClaimsJws(jwtToken).getBody(); - return MapUtils.getString(jwtClaims, LOGIN_USER_KEY); - } catch (ExpiredJwtException e) { - log.error("{}已过期", jwtToken); - } catch (Exception e) { - log.error("{}", e); - } + try { + Map jwtClaims = Jwts.parser().setSigningKey(getKeyInstance()).parseClaimsJws(jwtToken).getBody(); + return MapUtils.getString(jwtClaims, LOGIN_USER_KEY); + } catch (ExpiredJwtException e) { + log.error("{}已过期", jwtToken); + } catch (Exception e) { + log.error("{}", e); + } - return null; - } + return null; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 64a8e8e..3fa3e58 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,23 +1,24 @@ spring: datasource: - driver-class-name: com.mysql.jdbc.Driver - url: jdbc:mysql://localhost:3306/boot_security?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false - username: root - password: root - initialSize: 5 - minIdle: 5 - maxActive: 20 - maxWait: 60000 - timeBetweenEvictionRunsMillis: 60000 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 - testWhileIdle: true - testOnBorrow: true - testOnReturn: false - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - filters: stat,wall - connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + druid: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://localhost:3306/boot_security?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false + username: root + password: root + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 + testWhileIdle: true + testOnBorrow: true + testOnReturn: false + poolPreparedStatements: true + maxPoolPreparedStatementPerConnectionSize: 20 + filters: stat,wall + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 jackson: date-format: yyyy-MM-dd HH:mm:ss joda-date-time-format: yyyy-MM-dd HH:mm:ss @@ -32,6 +33,7 @@ spring: redis: host: localhost port: 6379 + password: mail: default-encoding: UTF-8 host: smtp.163.com diff --git a/文档和sql/01 安装运行.docx b/文档和sql/01 安装运行.docx index 8f5c379..6dbf004 100644 Binary files a/文档和sql/01 安装运行.docx and b/文档和sql/01 安装运行.docx differ diff --git a/文档和sql/02 框架及配置.docx b/文档和sql/02 框架及配置.docx index 902577c..a187be9 100644 Binary files a/文档和sql/02 框架及配置.docx and b/文档和sql/02 框架及配置.docx differ