From 5fed5c2744ebe8d4c1c7ce5f8b92f4deaf7f5489 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Fri, 20 Oct 2017 09:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E6=8B=93=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../token/DefaultUserTokenManager.java | 3 +- .../authorization/token/SimpleUserToken.java | 10 +++++ .../token/ThirdPartAuthenticationManager.java | 12 ++++++ .../web/authorization/token/UserToken.java | 4 ++ .../UserTokenAuthenticationSupplier.java | 40 +++++++++++++++---- .../authorization/token/UserTokenManager.java | 3 +- .../basic/web/AuthorizedToken.java | 6 +++ .../basic/web/GeneratedToken.java | 11 ++++- .../authorization/basic/web/ParsedToken.java | 2 + .../web/SessionIdUserTokenGenerator.java | 14 ++++--- .../basic/web/SessionIdUserTokenParser.java | 13 +++++- .../authorization/basic/web/UserOnSignIn.java | 10 ++--- .../basic/web/WebUserTokenInterceptor.java | 7 ++-- .../client/feign/FeignUserTokenManager.java | 28 ++++++------- .../cloud/server/UserTokenController.java | 31 +++++++------- .../jwt/DefaultAuthorizedToken.java | 5 +++ .../authorization/jwt/JwtTokenGenerator.java | 5 +++ 17 files changed, 147 insertions(+), 57 deletions(-) create mode 100644 hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java index cfd20f4c2..f92de1324 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/DefaultUserTokenManager.java @@ -168,8 +168,9 @@ public class DefaultUserTokenManager implements UserTokenManager { } @Override - public UserToken signIn(String token, String userId, long maxInactiveInterval) { + public UserToken signIn(String token, String type, String userId, long maxInactiveInterval) { SimpleUserToken detail = new SimpleUserToken(userId, token); + detail.setType(type); if (null != authorizationListenerDispatcher) { authorizationListenerDispatcher.doEvent(new UserSignInEvent(detail)); } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/SimpleUserToken.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/SimpleUserToken.java index f5ea602fe..9bab74334 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/SimpleUserToken.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/SimpleUserToken.java @@ -14,6 +14,8 @@ public class SimpleUserToken implements UserToken { private String token; + private String type = "default"; + private volatile TokenState state; private AtomicLong requestTimesCounter = new AtomicLong(0); @@ -102,4 +104,12 @@ public class SimpleUserToken implements UserToken { requestTimesCounter.addAndGet(1); lastRequestTime = System.currentTimeMillis(); } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java new file mode 100644 index 000000000..86a588632 --- /dev/null +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java @@ -0,0 +1,12 @@ +package org.hswebframework.web.authorization.token; + +import org.hswebframework.web.authorization.AuthenticationManager; + +/** + * @author zhouhao + * @since 1.0 + */ +public interface ThirdPartAuthenticationManager extends AuthenticationManager { + + String getTokenType(); +} diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserToken.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserToken.java index 406020226..c28d061a2 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserToken.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserToken.java @@ -44,6 +44,10 @@ public interface UserToken extends Serializable, Comparable { */ TokenState getState(); + /** + * @return 令牌类型, 默认:default + */ + String getType(); long getMaxInactiveInterval(); diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java index 7fdc4ea58..52ffb2fe4 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java @@ -4,9 +4,11 @@ import org.hswebframework.web.ThreadLocalUtils; import org.hswebframework.web.authorization.Authentication; import org.hswebframework.web.authorization.AuthenticationManager; import org.hswebframework.web.authorization.AuthenticationSupplier; -import org.hswebframework.web.authorization.token.UserToken; -import org.hswebframework.web.authorization.token.UserTokenHolder; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Optional; /** @@ -14,10 +16,19 @@ import java.util.Optional; */ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { - private AuthenticationManager authenticationManager; + private AuthenticationManager defaultAuthenticationManager; - public UserTokenAuthenticationSupplier(AuthenticationManager authenticationManager) { - this.authenticationManager = authenticationManager; + private Map thirdPartAuthenticationManager = new HashMap<>(); + + public UserTokenAuthenticationSupplier(AuthenticationManager defaultAuthenticationManager) { + this.defaultAuthenticationManager = defaultAuthenticationManager; + } + + @Autowired(required = false) + public void setThirdPartAuthenticationManager(List thirdPartAuthenticationManager) { + for (ThirdPartAuthenticationManager manager : thirdPartAuthenticationManager) { + this.thirdPartAuthenticationManager.put(manager.getTokenType(), manager); + } } @Override @@ -25,6 +36,16 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { if (userId == null) { return null; } + return get(this.defaultAuthenticationManager, userId); + } + + protected Authentication get(AuthenticationManager authenticationManager, String userId) { + if (null == userId) { + return null; + } + if (null == authenticationManager) { + authenticationManager = this.defaultAuthenticationManager; + } return authenticationManager.getByUserId(userId); } @@ -35,9 +56,12 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier { @Override public Authentication get() { return ThreadLocalUtils.get(Authentication.class.getName(), () -> - get(Optional.ofNullable(getCurrentUserToken()) + Optional.ofNullable(getCurrentUserToken()) .filter(UserToken::validate) //验证token,如果不是正常状态,将会抛出异常 - .map(UserToken::getUserId) - .orElse(null))); + .map(token -> + get(thirdPartAuthenticationManager + .get(token.getType()), token.getUserId()) + ) + .orElse(null)); } } diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenManager.java index 66bf8ae78..861f6550e 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenManager.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenManager.java @@ -105,9 +105,10 @@ public interface UserTokenManager { * 登记一个用户的token * * @param token token + * @param type 令牌类型 * @param userId 用户id */ - UserToken signIn(String token, String userId,long maxInactiveInterval); + UserToken signIn(String token, String type, String userId, long maxInactiveInterval); /** * 更新token,使其不过期 diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizedToken.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizedToken.java index 575566070..6c2c67367 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizedToken.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/AuthorizedToken.java @@ -2,8 +2,14 @@ package org.hswebframework.web.authorization.basic.web; /** * 已完成认证的令牌,如果返回此令牌,将直接使用{@link this#getUserId()}来绑定用户信息 + * * @author zhouhao */ public interface AuthorizedToken extends ParsedToken { String getUserId(); + + default long getMaxInactiveInterval() { + return -1; + } + } diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/GeneratedToken.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/GeneratedToken.java index 53f7685c5..1d213ee3d 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/GeneratedToken.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/GeneratedToken.java @@ -5,20 +5,27 @@ import java.util.Map; /** * 生成好的令牌信息 + * * @author zhouhao */ public interface GeneratedToken extends Serializable { /** * 要响应的数据,可自定义想要的数据给调用者 + * * @return {@link Map} */ - Map getResponse(); + Map getResponse(); /** - * @return 令牌字符串,令牌具有唯一性,不可逆,不包含敏感信息 + * @return 令牌字符串, 令牌具有唯一性, 不可逆, 不包含敏感信息 */ String getToken(); + /** + * @return 令牌类型 + */ + String getType(); + /** * @return 令牌有效期(单位毫秒) */ diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/ParsedToken.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/ParsedToken.java index f27c10115..874a9a673 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/ParsedToken.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/ParsedToken.java @@ -7,4 +7,6 @@ package org.hswebframework.web.authorization.basic.web; */ public interface ParsedToken { String getToken(); + + String getType(); } diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenGenerator.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenGenerator.java index 2bde1182a..20f7a565e 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenGenerator.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenGenerator.java @@ -11,7 +11,7 @@ import java.util.Map; /** * @author zhouhao */ -public class SessionIdUserTokenGenerator implements UserTokenGenerator ,Serializable { +public class SessionIdUserTokenGenerator implements UserTokenGenerator, Serializable { @Override public String getSupportTokenType() { @@ -20,13 +20,12 @@ public class SessionIdUserTokenGenerator implements UserTokenGenerator ,Serializ @Override public GeneratedToken generate(Authentication authentication) { - HttpServletRequest request= WebUtil.getHttpServletRequest(); - if(null==request) { + HttpServletRequest request = WebUtil.getHttpServletRequest(); + if (null == request) { throw new UnsupportedOperationException(); } - - int timeout =request.getSession().getMaxInactiveInterval()*1000; + int timeout = request.getSession().getMaxInactiveInterval() * 1000; String sessionId = request.getSession().getId(); @@ -41,6 +40,11 @@ public class SessionIdUserTokenGenerator implements UserTokenGenerator ,Serializ return sessionId; } + @Override + public String getType() { + return "session-id-default"; + } + @Override public int getTimeout() { return timeout; diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenParser.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenParser.java index a4de03917..a46e5e5b8 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenParser.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/SessionIdUserTokenParser.java @@ -14,9 +14,18 @@ public class SessionIdUserTokenParser implements UserTokenParser { HttpSession session = request.getSession(false); if (session != null) { - return session::getId; - } + return new ParsedToken() { + @Override + public String getToken() { + return session.getId(); + } + @Override + public String getType() { + return "session-id-default"; + } + }; + } return null; } } diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java index 6df0a9270..b60b8a233 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/UserOnSignIn.java @@ -15,11 +15,11 @@ import java.util.List; */ public class UserOnSignIn implements AuthorizationListener { - private String defaultTokenType="sessionId"; + private String defaultTokenType = "sessionId"; private UserTokenManager userTokenManager; - private List userTokenGenerators=new ArrayList<>(); + private List userTokenGenerators = new ArrayList<>(); public UserOnSignIn(UserTokenManager userTokenManager) { this.userTokenManager = userTokenManager; @@ -45,12 +45,12 @@ public class UserOnSignIn implements AuthorizationListenergenerator.getSupportTokenType().equals(tokenType)) + .filter(generator -> generator.getSupportTokenType().equals(tokenType)) .findFirst() - .orElseThrow(()->new UnsupportedOperationException(tokenType)) + .orElseThrow(() -> new UnsupportedOperationException(tokenType)) .generate(event.getAuthentication()); //登入 - userTokenManager.signIn(newToken.getToken(), event.getAuthentication().getUser().getId(),newToken.getTimeout()); + userTokenManager.signIn(newToken.getToken(), newToken.getType(), event.getAuthentication().getUser().getId(), newToken.getTimeout()); //响应结果 event.getResult().putAll(newToken.getResponse()); diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/WebUserTokenInterceptor.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/WebUserTokenInterceptor.java index fa376bd30..419ffe225 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/WebUserTokenInterceptor.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/web/WebUserTokenInterceptor.java @@ -43,9 +43,10 @@ public class WebUserTokenInterceptor extends HandlerInterceptorAdapter { if (userTokenManager.tokenIsLoggedIn(token)) { userToken = userTokenManager.getByToken(token); } -// if ((userToken == null || userToken.isExpired()) && parsedToken instanceof AuthorizedToken) { -// userToken = userTokenManager.signIn(parsedToken.getToken(), ((AuthorizedToken) parsedToken).getUserId(), -1); -// } + if ((userToken == null || userToken.isExpired()) && parsedToken instanceof AuthorizedToken) { + userToken = userTokenManager + .signIn(parsedToken.getToken(), parsedToken.getType(), ((AuthorizedToken) parsedToken).getUserId(), ((AuthorizedToken) parsedToken).getMaxInactiveInterval()); + } if (null != userToken) { userTokenManager.touch(token); UserTokenHolder.setCurrent(userToken); diff --git a/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/client/feign/FeignUserTokenManager.java b/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/client/feign/FeignUserTokenManager.java index ffcaa6054..d958803fa 100644 --- a/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/client/feign/FeignUserTokenManager.java +++ b/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/client/feign/FeignUserTokenManager.java @@ -16,54 +16,54 @@ import java.util.List; public interface FeignUserTokenManager extends UserTokenManager { @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}", method = RequestMethod.GET) UserToken getByToken(@PathVariable("token") String token); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}", method = RequestMethod.GET) List getByUserId(@PathVariable("userId") String userId); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}/logged",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}/logged", method = RequestMethod.GET) boolean userIsLoggedIn(@PathVariable("userId") String userId); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}/logged",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}/logged", method = RequestMethod.GET) boolean tokenIsLoggedIn(@PathVariable("token") String token); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/total",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/total", method = RequestMethod.GET) long totalUser(); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/total",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/total", method = RequestMethod.GET) long totalToken(); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token", method = RequestMethod.GET) List allLoggedUser(); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}",method = RequestMethod.DELETE) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}", method = RequestMethod.DELETE) void signOutByUserId(@PathVariable("userId") String userId); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}",method = RequestMethod.DELETE) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}", method = RequestMethod.DELETE) void signOutByToken(@PathVariable("token") String token); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}/{state}",method = RequestMethod.PUT) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/user/{userId}/{state}", method = RequestMethod.PUT) void changeUserState(@PathVariable("userId") String userId, @PathVariable("state") TokenState state); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}/{state}",method = RequestMethod.PUT) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/token/{token}/{state}", method = RequestMethod.PUT) void changeTokenState(@PathVariable("token") String token, @PathVariable("state") TokenState state); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/{token}/{userId}/{maxInactiveInterval}",method = RequestMethod.POST) - UserToken signIn(@PathVariable("token") String token, @PathVariable("userId") String userId, @PathVariable("maxInactiveInterval") long maxInactiveInterval); + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/{token}/{type}/{userId}/{maxInactiveInterval}", method = RequestMethod.POST) + UserToken signIn(@PathVariable("token") String token, @PathVariable("type") String type, @PathVariable("userId") String userId, @PathVariable("maxInactiveInterval") long maxInactiveInterval); @Override - @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/{token}/touch",method = RequestMethod.GET) + @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-token/{token}/touch", method = RequestMethod.GET) void touch(@PathVariable("token") String token); } diff --git a/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/server/UserTokenController.java b/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/server/UserTokenController.java index b881ee026..7dfc5c3f4 100644 --- a/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/server/UserTokenController.java +++ b/hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/server/UserTokenController.java @@ -36,59 +36,58 @@ public class UserTokenController { } @GetMapping("/user-token/user/{userId}") - public List getByUserId(@PathVariable String userId){ + public List getByUserId(@PathVariable String userId) { return userTokenManager.getByUserId(userId); } @GetMapping("/user-token/user/{userId}/logged") - public boolean userIsLoggedIn(@PathVariable String userId){ + public boolean userIsLoggedIn(@PathVariable String userId) { return userTokenManager.userIsLoggedIn(userId); } @GetMapping("/user-token/token/{token}/logged") - public boolean tokenIsLoggedIn(@PathVariable String token){ + public boolean tokenIsLoggedIn(@PathVariable String token) { return userTokenManager.tokenIsLoggedIn(token); } @GetMapping("/user-token/user/total") - public long totalUser(){ + public long totalUser() { return userTokenManager.totalUser(); } @GetMapping("/user-token/token/total") - public long totalToken(){ + public long totalToken() { return userTokenManager.totalToken(); } @GetMapping("/user-token}") - public List allLoggedUser(){ + public List allLoggedUser() { return userTokenManager.allLoggedUser(); } @DeleteMapping("/user-token/user/{userId}") - public void signOutByUserId(@PathVariable String userId){ + public void signOutByUserId(@PathVariable String userId) { userTokenManager.signOutByUserId(userId); } @DeleteMapping("/user-token/token/{token}") - public void signOutByToken(@PathVariable String token){ + public void signOutByToken(@PathVariable String token) { userTokenManager.signOutByToken(token); } @PutMapping("/user-token/user/{userId}/{state}") - public void changeUserState(@PathVariable String userId, @PathVariable TokenState state){ + public void changeUserState(@PathVariable String userId, @PathVariable TokenState state) { userTokenManager.changeUserState(userId, state); } @PutMapping("/user-token/token/{token}/{state}") - public void changeTokenState(String token, TokenState state){ - userTokenManager.changeTokenState(token,state); + public void changeTokenState(String token, TokenState state) { + userTokenManager.changeTokenState(token, state); } - @PostMapping("/user-token/{token}/{userId}/{maxInactiveInterval}") - public UserToken signIn(@PathVariable String token, @PathVariable String userId, @PathVariable long maxInactiveInterval) - { - return userTokenManager.signIn(token,userId,maxInactiveInterval); + @PostMapping("/user-token/{token}/{type}/{userId}/{maxInactiveInterval}") + public UserToken signIn(@PathVariable String token, @PathVariable String type, @PathVariable String userId, @PathVariable long maxInactiveInterval) { + return userTokenManager.signIn(token, type, userId, maxInactiveInterval); } @GetMapping("/user-token/{token}/touch") @@ -97,7 +96,7 @@ public class UserTokenController { } @GetMapping("/user-auth/{userId}") - public Authentication userAuthInfo(@PathVariable String userId){ + public Authentication userAuthInfo(@PathVariable String userId) { return authenticationManager.getByUserId(userId); } diff --git a/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/DefaultAuthorizedToken.java b/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/DefaultAuthorizedToken.java index c6a09ce7c..15a080292 100644 --- a/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/DefaultAuthorizedToken.java +++ b/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/DefaultAuthorizedToken.java @@ -36,4 +36,9 @@ public class DefaultAuthorizedToken implements AuthorizedToken { public void setUserId(String userId) { this.userId = userId; } + + @Override + public String getType() { + return "jwt-default"; + } } diff --git a/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/JwtTokenGenerator.java b/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/JwtTokenGenerator.java index ce06e157e..12cfbe4c8 100644 --- a/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/JwtTokenGenerator.java +++ b/hsweb-authorization/hsweb-authorization-jwt/src/main/java/org/hswebframework/web/authorization/jwt/JwtTokenGenerator.java @@ -61,6 +61,11 @@ public class JwtTokenGenerator implements UserTokenGenerator { return token; } + @Override + public String getType() { + return "jwt-default"; + } + @Override public int getTimeout() { return timeout;