diff --git a/authorize/src/test/resources/create_h2.sql b/authorize/src/test/resources/create_h2.sql index fa7b6aa7..705b8c92 100644 --- a/authorize/src/test/resources/create_h2.sql +++ b/authorize/src/test/resources/create_h2.sql @@ -46,6 +46,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/cache/src/main/java/com/networknt/oauth/cache/RefreshTokenMapStore.java b/cache/src/main/java/com/networknt/oauth/cache/RefreshTokenMapStore.java index 6d4669e4..45236e7c 100644 --- a/cache/src/main/java/com/networknt/oauth/cache/RefreshTokenMapStore.java +++ b/cache/src/main/java/com/networknt/oauth/cache/RefreshTokenMapStore.java @@ -18,10 +18,9 @@ public class RefreshTokenMapStore implements MapStore { static final Logger logger = LoggerFactory.getLogger(RefreshTokenMapStore.class); static final DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class); - private static final String insert = "INSERT INTO refresh_token (user_id, user_type, roles, client_id, scope, refresh_token) VALUES (?, ?, ?, ?, ?, ?)"; + private static final String insert = "INSERT INTO refresh_token (user_id, user_type, roles, client_id, scope, remember, refresh_token) VALUES (?, ?, ?, ?, ?, ?, ?)"; private static final String delete = "DELETE FROM refresh_token WHERE refresh_token = ?"; private static final String select = "SELECT * FROM refresh_token WHERE refresh_token = ?"; - private static final String update = "UPDATE refresh_token SET scope=? WHERE refresh_token = ?"; private static final String loadall = "SELECT refresh_token FROM refresh_token"; @@ -46,7 +45,8 @@ public synchronized void store(String key, RefreshToken token) { stmt.setString(3, token.getRoles()); stmt.setString(4, token.getClientId()); stmt.setString(5, token.getScope()); - stmt.setString(6, token.getRefreshToken()); + stmt.setString(6, token.getRemember()); + stmt.setString(7, token.getRefreshToken()); stmt.executeUpdate(); } catch (SQLException e) { logger.error("Exception:", e); @@ -82,6 +82,7 @@ public synchronized RefreshToken load(String key) { token.setRoles(rs.getString("roles")); token.setClientId(rs.getString("client_id")); token.setScope(rs.getString("scope")); + token.setRemember(rs.getString("remember")); } } } catch (SQLException e) { diff --git a/cache/src/main/java/com/networknt/oauth/cache/model/RefreshToken.java b/cache/src/main/java/com/networknt/oauth/cache/model/RefreshToken.java index d4b86caa..6b48f282 100644 --- a/cache/src/main/java/com/networknt/oauth/cache/model/RefreshToken.java +++ b/cache/src/main/java/com/networknt/oauth/cache/model/RefreshToken.java @@ -30,6 +30,8 @@ public class RefreshToken implements IdentifiedDataSerializable { private String scope = null; + private String remember = null; + public RefreshToken refreshToken(String refreshToken) { this.refreshToken = refreshToken; return this; @@ -109,7 +111,6 @@ public RefreshToken scope(String scope) { return this; } - @JsonProperty("scope") public String getScope() { return scope; @@ -118,6 +119,19 @@ public void setScope(String scope) { this.scope = scope; } + public RefreshToken remember(String remember) { + this.remember = remember; + return this; + } + + @JsonProperty("remember") + public String getRemember() { + return remember; + } + public void setRemember(String remember) { + this.remember = remember; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -132,13 +146,14 @@ public boolean equals(Object o) { Objects.equals(userType, token.userType) && Objects.equals(roles, token.roles) && Objects.equals(clientId, token.clientId) && + Objects.equals(remember, token.remember) && Objects.equals(scope, token.scope); } @Override public int hashCode() { - return Objects.hash(refreshToken, userId, userType, roles, clientId, scope); + return Objects.hash(refreshToken, userId, userType, roles, clientId, scope, remember); } @Override @@ -152,6 +167,7 @@ public String toString() { sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n"); sb.append(" scope: ").append(toIndentedString(scope)).append("\n"); + sb.append(" remember: ").append(toIndentedString(remember)).append("\n"); sb.append("}"); return sb.toString(); } @@ -179,6 +195,7 @@ public void readData(ObjectDataInput in) throws IOException { this.roles = in.readUTF(); this.clientId = in.readUTF(); this.scope = in.readUTF(); + this.remember = in.readUTF(); } @Override @@ -189,6 +206,7 @@ public void writeData(ObjectDataOutput out) throws IOException { out.writeUTF(this.roles); out.writeUTF(this.clientId); out.writeUTF(this.scope); + out.writeUTF(this.remember); } @JsonIgnore diff --git a/cache/src/test/java/com/networknt/oauth/cache/CacheStartupHookProviderTest.java b/cache/src/test/java/com/networknt/oauth/cache/CacheStartupHookProviderTest.java index 02088105..91b01f1e 100644 --- a/cache/src/test/java/com/networknt/oauth/cache/CacheStartupHookProviderTest.java +++ b/cache/src/test/java/com/networknt/oauth/cache/CacheStartupHookProviderTest.java @@ -193,6 +193,7 @@ public void testRefreshTokenCache() { token.setClientId("59f347a0-c92d-11e6-9d9d-cec0c932ce01"); token.setScope("todo.r"); + token.setRemember("N"); token.setRefreshToken("token1"); diff --git a/cache/src/test/resources/create_h2.sql b/cache/src/test/resources/create_h2.sql index 2f05616d..0f91efcd 100644 --- a/cache/src/test/resources/create_h2.sql +++ b/cache/src/test/resources/create_h2.sql @@ -66,6 +66,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/client/src/test/resources/create_h2.sql b/client/src/test/resources/create_h2.sql index 2bf1604c..f017019e 100644 --- a/client/src/test/resources/create_h2.sql +++ b/client/src/test/resources/create_h2.sql @@ -66,6 +66,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/code/src/test/resources/create_h2.sql b/code/src/test/resources/create_h2.sql index 6fa0ef2b..ff604ea7 100644 --- a/code/src/test/resources/create_h2.sql +++ b/code/src/test/resources/create_h2.sql @@ -46,6 +46,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/db/mariadb/create_mysql.sql b/db/mariadb/create_mysql.sql index b1c45fb6..8ed2b49c 100644 --- a/db/mariadb/create_mysql.sql +++ b/db/mariadb/create_mysql.sql @@ -89,6 +89,7 @@ CREATE TABLE refresh_token ( roles VARCHAR(2048), client_id VARCHAR(36) NOT NULL, scope VARCHAR(64) NOT NULL, + remember VARCHAR(1) NOT NULL, refresh_token VARCHAR(256) NOT NULL, PRIMARY KEY (client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/db/mysql/create_mysql.sql b/db/mysql/create_mysql.sql index b1c45fb6..8ed2b49c 100644 --- a/db/mysql/create_mysql.sql +++ b/db/mysql/create_mysql.sql @@ -89,6 +89,7 @@ CREATE TABLE refresh_token ( roles VARCHAR(2048), client_id VARCHAR(36) NOT NULL, scope VARCHAR(64) NOT NULL, + remember VARCHAR(1) NOT NULL, refresh_token VARCHAR(256) NOT NULL, PRIMARY KEY (client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/db/oracle/create_oracle.sql b/db/oracle/create_oracle.sql index b4f65a36..b09ce968 100644 --- a/db/oracle/create_oracle.sql +++ b/db/oracle/create_oracle.sql @@ -76,6 +76,7 @@ CREATE TABLE refresh_token ( roles VARCHAR2(2048), client_id VARCHAR2(36) NOT NULL, scope VARCHAR2(64) NOT NULL, + remember VARCHAR2(1) NOT NULL, refresh_token VARCHAR2(256) NOT NULL, CONSTRAINT refresh_token_pk PRIMARY KEY (client_id, refresh_token), CONSTRAINT refresh_token_client_fk FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/db/postgres/create_postgres.sql b/db/postgres/create_postgres.sql index 2b2e0d3d..f8d9fe80 100644 --- a/db/postgres/create_postgres.sql +++ b/db/postgres/create_postgres.sql @@ -73,6 +73,7 @@ CREATE TABLE refresh_token ( roles VARCHAR(2048), client_id VARCHAR(36) NOT NULL, scope VARCHAR(64) NOT NULL, + remember VARCHAR(1) NOT NULL, refresh_token VARCHAR(256) NOT NULL, PRIMARY KEY (client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/db/sqlserver/create_sqlserver.sql b/db/sqlserver/create_sqlserver.sql index 15b0ce04..635d23d2 100644 --- a/db/sqlserver/create_sqlserver.sql +++ b/db/sqlserver/create_sqlserver.sql @@ -81,6 +81,7 @@ CREATE TABLE refresh_token ( roles VARCHAR(2048), client_id VARCHAR(36) NOT NULL, scope VARCHAR(64) NOT NULL, + remember VARCHAR(1) NOT NULL, refresh_token VARCHAR(256) NOT NULL, PRIMARY KEY (client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/key/src/test/resources/create_h2.sql b/key/src/test/resources/create_h2.sql index 53ac7859..d01a3e77 100644 --- a/key/src/test/resources/create_h2.sql +++ b/key/src/test/resources/create_h2.sql @@ -49,6 +49,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/provider/src/test/resources/create_h2.sql b/provider/src/test/resources/create_h2.sql index c71fd133..528d01fb 100644 --- a/provider/src/test/resources/create_h2.sql +++ b/provider/src/test/resources/create_h2.sql @@ -46,6 +46,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenGetHandlerTest.java b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenGetHandlerTest.java index 891c390b..e7450b5d 100644 --- a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenGetHandlerTest.java +++ b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenGetHandlerTest.java @@ -77,6 +77,7 @@ public void testOauth2RefreshTokenGetHandler() throws ClientException, ApiExcept token.setUserId("admin"); token.setClientId("6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); IMap tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); diff --git a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenDeleteHandlerTest.java b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenDeleteHandlerTest.java index 573845b7..4bff9d55 100644 --- a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenDeleteHandlerTest.java +++ b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenDeleteHandlerTest.java @@ -75,6 +75,7 @@ public void testOauth2RefreshTokenDeleteHandler() throws ClientException, ApiExc token.setUserId("admin"); token.setClientId("6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); IMap tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); diff --git a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenGetHandlerTest.java b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenGetHandlerTest.java index d3839151..40782bb7 100644 --- a/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenGetHandlerTest.java +++ b/refresh-token/src/test/java/com/networknt/oauth/token/handler/Oauth2RefreshTokenRefreshTokenGetHandlerTest.java @@ -75,6 +75,7 @@ public void testOauth2RefreshTokenGetHandler() throws ClientException, ApiExcept token.setUserId("admin"); token.setClientId("6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); IMap tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); diff --git a/refresh-token/src/test/resources/create_h2.sql b/refresh-token/src/test/resources/create_h2.sql index fdba487e..79f41c3f 100644 --- a/refresh-token/src/test/resources/create_h2.sql +++ b/refresh-token/src/test/resources/create_h2.sql @@ -45,6 +45,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/service/src/test/resources/create_h2.sql b/service/src/test/resources/create_h2.sql index 6e6c9b93..06d5fae6 100644 --- a/service/src/test/resources/create_h2.sql +++ b/service/src/test/resources/create_h2.sql @@ -66,6 +66,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id) diff --git a/token/src/main/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandler.java b/token/src/main/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandler.java index 23a468e4..7aeba202 100644 --- a/token/src/main/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandler.java +++ b/token/src/main/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandler.java @@ -274,6 +274,7 @@ private Map handleAuthorizationCode(HttpServerExchange exchange, token.setRoles(roles); token.setClientId(client.getClientId()); token.setScope(scope); + token.setRemember(remember != null && remember.equals("Y") ? "Y" : "N"); IMap tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.set(refreshToken, token); // if the client type is external, save the jwt to reference map and send the reference @@ -354,6 +355,7 @@ private Map handlePassword(HttpServerExchange exchange, Map tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.set(refreshToken, token); @@ -399,6 +401,7 @@ private Map handleRefreshToken(HttpServerExchange exchange, Map< String roles = token.getRoles(); String clientId = token.getClientId(); String oldScope = token.getScope(); + String remember = token.getRemember(); if(client.getClientId().equals(clientId)) { if(scope == null) { @@ -430,6 +433,7 @@ private Map handleRefreshToken(HttpServerExchange exchange, Map< newToken.setRoles(roles); newToken.setClientId(client.getClientId()); newToken.setScope(scope); + newToken.setRemember(remember); tokens.put(newRefreshToken, newToken); // if the client type is external, save the jwt to reference map and send the reference if(Client.ClientTypeEnum.EXTERNAL == client.getClientType()) { @@ -440,7 +444,7 @@ private Map handleRefreshToken(HttpServerExchange exchange, Map< resMap.put("token_type", "bearer"); resMap.put("expires_in", config.getExpiredInMinutes()*60); resMap.put("refresh_token", newRefreshToken); - resMap.put("remember", "Y"); // when refresh token is used, the remember is always true. + resMap.put("remember", remember); return resMap; } else { @@ -511,6 +515,7 @@ private Map handleClientAuthenticatedUser(HttpServerExchange exc token.setRoles(roles); token.setClientId(client.getClientId()); token.setScope(scope); + token.setRemember("N"); // default to N IMap tokens = CacheStartupHookProvider.hz.getMap("tokens"); tokens.set(refreshToken, token); diff --git a/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java b/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java index 2a2d901e..c8930540 100644 --- a/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java +++ b/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java @@ -895,6 +895,7 @@ public void testRefreshToken() throws Exception { token.setUserType("employee"); token.setClientId("6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); CacheStartupHookProvider.hz.getMap("tokens").put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); Map params = new HashMap<>(); @@ -957,6 +958,7 @@ public void testRefreshTokenExternalClient() throws Exception { token.setUserType("employee"); token.setClientId("78cd9a2e-7690-11e8-adc0-fa7ae01bbebc"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); CacheStartupHookProvider.hz.getMap("tokens").put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); Map params = new HashMap<>(); @@ -1025,6 +1027,7 @@ public void testRefreshTokenWithRoles() throws Exception { token.setRoles("user admin"); token.setClientId("6e9d1db3-2feb-4c1f-a5ad-9e93ae8ca59d"); token.setScope("petstore.r petstore.w"); + token.setRemember("N"); CacheStartupHookProvider.hz.getMap("tokens").put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token); Map params = new HashMap<>(); diff --git a/token/src/test/resources/create_h2.sql b/token/src/test/resources/create_h2.sql index 34b3ad93..6073901e 100644 --- a/token/src/test/resources/create_h2.sql +++ b/token/src/test/resources/create_h2.sql @@ -47,6 +47,7 @@ CREATE TABLE refresh_token ( roles VARCHAR, client_id VARCHAR NOT NULL, scope VARCHAR NOT NULL, + remember VARCHAR NOT NULL, refresh_token VARCHAR NOT NULL, PRIMARY KEY (user_id, client_id, refresh_token), FOREIGN KEY (client_id) REFERENCES client(client_id)