From 41035ba23e17a630cf0671acc494cbf220763787 Mon Sep 17 00:00:00 2001 From: jeesun Date: Mon, 8 Jul 2019 10:39:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BB=99t=5Fusers=E8=A1=A8=E7=9A=84usernam?= =?UTF-8?q?e=E5=88=97=E6=B7=BB=E5=8A=A0=E5=94=AF=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schema-mysql-20190613.sql" | 5 ++++- .../schema-oracle-20190613.sql" | 5 ++++- .../schema-postgresql-20190613.sql" | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-mysql-20190613.sql" "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-mysql-20190613.sql" index f9ea9ce..2a25c6f 100644 --- "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-mysql-20190613.sql" +++ "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-mysql-20190613.sql" @@ -415,4 +415,7 @@ ALTER TABLE t_news_info CHANGE status news_status int4; -- 2019-06-18 by simon t_users创建唯一键。 update t_users set email='18800000003@163.com' where id=1000000001; ALTER TABLE t_users RENAME INDEX phone TO uk_t_users_phone; -alter table t_users drop index email,add unique index uk_t_users_email(email) USING BTREE; \ No newline at end of file +alter table t_users drop index email,add unique index uk_t_users_email(email) USING BTREE; + +-- 2019-07-08 by simon t_users给username列创建唯一键。 +create unique index uk_t_users_username on t_users(username); \ No newline at end of file diff --git "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-oracle-20190613.sql" "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-oracle-20190613.sql" index 9f65d53..863c983 100644 --- "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-oracle-20190613.sql" +++ "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-oracle-20190613.sql" @@ -460,4 +460,7 @@ ALTER TABLE T_NEWS_INFO rename column status to news_status; -- 2019-06-18 by simon t_users创建唯一键。 update t_users set email='18800000003@163.com' where id=1000000001; CREATE UNIQUE INDEX uk_t_users_phone ON T_USERS ("PHONE"); -CREATE UNIQUE INDEX uk_t_useers_email ON T_USERS ("EMAIL"); \ No newline at end of file +CREATE UNIQUE INDEX uk_t_useers_email ON T_USERS ("EMAIL"); + +-- 2019-07-08 by simon t_users给username列创建唯一键。 +create unique index uk_t_users_username on T_USERS("USERNAME"); \ No newline at end of file diff --git "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-postgresql-20190613.sql" "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-postgresql-20190613.sql" index 8ed92e5..cafd5b9 100644 --- "a/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-postgresql-20190613.sql" +++ "b/SQL\345\242\236\351\207\217\346\233\264\346\226\260/schema-postgresql-20190613.sql" @@ -444,4 +444,7 @@ DROP INDEX email; CREATE UNIQUE INDEX uk_t_users_email ON t_users USING btree ( "email" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST ); -ALTER INDEX "public"."phone" RENAME TO "uk_t_users_phone"; \ No newline at end of file +ALTER INDEX "public"."phone" RENAME TO "uk_t_users_phone"; + +-- 2019-07-08 by simon t_users给username列创建唯一键。 +create unique index uk_t_users_username on t_users(username); \ No newline at end of file -- Gitee From 4e107af3ec3e7e871e02a8121843d808ae485c64 Mon Sep 17 00:00:00 2001 From: jeesun Date: Mon, 8 Jul 2019 10:41:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8refresh?= =?UTF-8?q?=5Ftoken=E5=88=B7=E6=96=B0access=5Ftoken=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=8A=A5=E2=80=9C=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=96=B9=E5=BC=8F=E2=80=9D=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/UsernamePasswordAuthenticator.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/com/simon/common/plugins/oauth/UsernamePasswordAuthenticator.java b/api/src/main/java/com/simon/common/plugins/oauth/UsernamePasswordAuthenticator.java index 4b21eeb..2d5c719 100644 --- a/api/src/main/java/com/simon/common/plugins/oauth/UsernamePasswordAuthenticator.java +++ b/api/src/main/java/com/simon/common/plugins/oauth/UsernamePasswordAuthenticator.java @@ -2,7 +2,6 @@ package com.simon.common.plugins.oauth; import com.simon.common.config.AppConfig; import com.simon.common.domain.UserEntity; -import com.simon.common.exception.BusinessException; import com.simon.common.utils.DateUtil; import com.simon.common.utils.ValidUtil; import com.simon.model.Authority; @@ -47,15 +46,15 @@ public class UsernamePasswordAuthenticator extends AbstractPreparableIntegration private final static String PASSWORD_AUTH_TYPE = "password"; - public UsernamePasswordAuthenticator(){ + public UsernamePasswordAuthenticator() { sqlLoadUserByPhone = "select id,username,password,enabled,area_code,phone,email,address,birth,age,head_photo,person_brief,sex from t_users where phone=?"; sqlLoadUserByEmail = "select id,username,password,enabled,area_code,phone,email,address,birth,age,head_photo,person_brief,sex from t_users where email=?"; sqlLoadUserByName = "select id,username,password,enabled,area_code,phone,email,address,birth,age,head_photo,person_brief,sex from t_users where username=?"; sqlLoadAuthorities = "select user_id,authority from t_authorities where user_id = ?"; - myUserDetailsRowMapper = (rs, i) -> new UserEntity(rs.getLong(1), rs.getString(2), rs.getString(3), rs.getBoolean(4), rs.getString("area_code"), rs.getString("phone"), rs.getString("email"),rs.getString("address"), DateUtil.dateToLocalDate(rs.getDate("birth")), rs.getInt("age"), rs.getString("head_photo"), rs.getString("person_brief"), rs.getBoolean("sex")); + myUserDetailsRowMapper = (rs, i) -> new UserEntity(rs.getLong(1), rs.getString(2), rs.getString(3), rs.getBoolean(4), rs.getString("area_code"), rs.getString("phone"), rs.getString("email"), rs.getString("address"), DateUtil.dateToLocalDate(rs.getDate("birth")), rs.getInt("age"), rs.getString("head_photo"), rs.getString("person_brief"), rs.getBoolean("sex")); - authorityRowMapper = (rs,i) -> { + authorityRowMapper = (rs, i) -> { Authority authority = new Authority(); authority.setUserId(rs.getLong(1)); authority.setAuthority(rs.getString(2)); @@ -66,18 +65,18 @@ public class UsernamePasswordAuthenticator extends AbstractPreparableIntegration @Override public UserEntity authenticate(IntegrationAuthentication integrationAuthentication) { log.info("password authenticate"); - try{ + try { UserEntity userFromQuery = null; if (StringUtils.isEmpty(integrationAuthentication.getUsername())) { throw new UsernameNotFoundException(messageSource.getMessage("usernameNotFound", null, locale)); } - if(ValidUtil.isEmail(integrationAuthentication.getUsername())){ + log.info(integrationAuthentication.getUsername()); + if (ValidUtil.isEmail(integrationAuthentication.getUsername())) { userFromQuery = jdbcTemplate.queryForObject(sqlLoadUserByEmail, myUserDetailsRowMapper, integrationAuthentication.getUsername()); - }else if(ValidUtil.isMobile(integrationAuthentication.getUsername())){ + } else if (ValidUtil.isMobile(integrationAuthentication.getUsername())) { userFromQuery = jdbcTemplate.queryForObject(sqlLoadUserByPhone, myUserDetailsRowMapper, integrationAuthentication.getUsername()); - }else{ - //userFromQuery = jdbcTemplate.queryForObject(sqlLoadUserByName, myUserDetailsRowMapper, integrationAuthentication.getUsername()); - throw new BusinessException("不支持的登录方式"); + } else { + userFromQuery = jdbcTemplate.queryForObject(sqlLoadUserByName, myUserDetailsRowMapper, integrationAuthentication.getUsername()); } log.info("查询得到用户:{}", userFromQuery); @@ -85,7 +84,7 @@ public class UsernamePasswordAuthenticator extends AbstractPreparableIntegration log.info("得到其权限:{}", authorities); return new UserEntity(userFromQuery.getId(), userFromQuery.getUsername(), userFromQuery.getPassword(), userFromQuery.isEnabled(), userFromQuery.getAreaCode(), userFromQuery.getPhone(), userFromQuery.getEmail(), userFromQuery.getAddress(), userFromQuery.getBirth(), userFromQuery.getAge(), userFromQuery.getHeadPhoto(), userFromQuery.getPersonBrief(), userFromQuery.getSex(), authorities); - }catch (EmptyResultDataAccessException e){ + } catch (EmptyResultDataAccessException e) { log.info("查询结果集为空:{}", integrationAuthentication.getUsername()); throw new InvalidGrantException(messageSource.getMessage("usernameNotFound", null, locale)); } -- Gitee