Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions authorize/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
public class RefreshTokenMapStore implements MapStore<String, RefreshToken> {
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";


Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +111,6 @@ public RefreshToken scope(String scope) {
return this;
}


@JsonProperty("scope")
public String getScope() {
return scope;
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public void testRefreshTokenCache() {
token.setClientId("59f347a0-c92d-11e6-9d9d-cec0c932ce01");

token.setScope("todo.r");
token.setRemember("N");
token.setRefreshToken("token1");


Expand Down
1 change: 1 addition & 0 deletions cache/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions client/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions code/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions db/mariadb/create_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions db/mysql/create_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions db/oracle/create_oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions db/postgres/create_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions db/sqlserver/create_sqlserver.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions key/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions provider/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.put("86c0a39f-0789-4b71-9fed-d99fe6dc9281", token);

Expand Down
1 change: 1 addition & 0 deletions refresh-token/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions service/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private Map<String, Object> handleAuthorizationCode(HttpServerExchange exchange,
token.setRoles(roles);
token.setClientId(client.getClientId());
token.setScope(scope);
token.setRemember(remember != null && remember.equals("Y") ? "Y" : "N");
IMap<String, RefreshToken> 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
Expand Down Expand Up @@ -354,6 +355,7 @@ private Map<String, Object> handlePassword(HttpServerExchange exchange, Map<Stri
token.setUserId(userId);
token.setClientId(client.getClientId());
token.setScope(scope);
token.setRemember("N"); // set this to N by default for password
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.set(refreshToken, token);

Expand Down Expand Up @@ -399,6 +401,7 @@ private Map<String, Object> 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) {
Expand Down Expand Up @@ -430,6 +433,7 @@ private Map<String, Object> 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()) {
Expand All @@ -440,7 +444,7 @@ private Map<String, Object> 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 {
Expand Down Expand Up @@ -511,6 +515,7 @@ private Map<String, Object> handleClientAuthenticatedUser(HttpServerExchange exc
token.setRoles(roles);
token.setClientId(client.getClientId());
token.setScope(scope);
token.setRemember("N"); // default to N
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.set(refreshToken, token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> params = new HashMap<>();
Expand Down Expand Up @@ -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<String, String> params = new HashMap<>();
Expand Down Expand Up @@ -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<String, String> params = new HashMap<>();
Expand Down
1 change: 1 addition & 0 deletions token/src/test/resources/create_h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down