mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-13 07:47:05 +08:00
CB-2507 custom security manager configuration
This commit is contained in:
+11
-6
@@ -68,9 +68,6 @@ public class CBEmbeddedSecurityController implements SMAdminController, SMAuthen
|
||||
|
||||
private static final Log log = Log.getLog(CBEmbeddedSecurityController.class);
|
||||
|
||||
private static final int ACCESS_TOKEN_TTL_IN_MINUTES = 20;
|
||||
private static final int REFRESH_TOKEN_TTL_IN_HOURS = 24;
|
||||
|
||||
protected static final String CHAR_BOOL_TRUE = "Y";
|
||||
protected static final String CHAR_BOOL_FALSE = "N";
|
||||
|
||||
@@ -84,10 +81,18 @@ public class CBEmbeddedSecurityController implements SMAdminController, SMAuthen
|
||||
protected final CBDatabase database;
|
||||
protected final SMCredentialsProvider credentialsProvider;
|
||||
|
||||
public CBEmbeddedSecurityController(WebApplication application, CBDatabase database, SMCredentialsProvider credentialsProvider) {
|
||||
private final SMControllerConfiguration smConfig;
|
||||
|
||||
public CBEmbeddedSecurityController(
|
||||
WebApplication application,
|
||||
CBDatabase database,
|
||||
SMCredentialsProvider credentialsProvider,
|
||||
SMControllerConfiguration smConfig
|
||||
) {
|
||||
this.application = application;
|
||||
this.database = database;
|
||||
this.credentialsProvider = credentialsProvider;
|
||||
this.smConfig = smConfig;
|
||||
}
|
||||
|
||||
private boolean isSubjectExists(String subjectId) throws DBCException {
|
||||
@@ -1406,12 +1411,12 @@ public class CBEmbeddedSecurityController implements SMAdminController, SMAuthen
|
||||
} else {
|
||||
dbStat.setString(3, userId);
|
||||
}
|
||||
var accessTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusMinutes(ACCESS_TOKEN_TTL_IN_MINUTES));
|
||||
var accessTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusMinutes(smConfig.getAccessTokenTtl()));
|
||||
dbStat.setTimestamp(4, accessTokenExpirationTime);
|
||||
|
||||
String smRefreshToken = SecurityUtils.generatePassword(32);
|
||||
dbStat.setString(5, smRefreshToken);
|
||||
var refreshTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusHours(REFRESH_TOKEN_TTL_IN_HOURS));
|
||||
var refreshTokenExpirationTime = Timestamp.valueOf(LocalDateTime.now().plusMinutes(smConfig.getRefreshTokenTtl()));
|
||||
dbStat.setTimestamp(6, refreshTokenExpirationTime);
|
||||
|
||||
dbStat.execute();
|
||||
|
||||
+20
-4
@@ -33,13 +33,26 @@ import java.util.Map;
|
||||
public class EmbeddedSecurityControllerFactory {
|
||||
private static volatile CBDatabase DB_INSTANCE;
|
||||
|
||||
|
||||
/**
|
||||
* Create new security controller instance
|
||||
* Create new security controller instance with default configuration
|
||||
*/
|
||||
public CBEmbeddedSecurityController createSecurityService(
|
||||
WebApplication application,
|
||||
Map<String, Object> databaseConfig,
|
||||
SMCredentialsProvider credentialsProvider
|
||||
) throws DBException {
|
||||
return createSecurityService(application, databaseConfig, credentialsProvider, new SMControllerConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new security controller instance with custom configuration
|
||||
*/
|
||||
public CBEmbeddedSecurityController createSecurityService(
|
||||
WebApplication application,
|
||||
Map<String, Object> databaseConfig,
|
||||
SMCredentialsProvider credentialsProvider,
|
||||
SMControllerConfiguration smConfig
|
||||
) throws DBException {
|
||||
boolean initDb = false;
|
||||
if (DB_INSTANCE == null) {
|
||||
@@ -50,7 +63,9 @@ public class EmbeddedSecurityControllerFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
var securityController = createEmbeddedSecurityController(application, DB_INSTANCE, credentialsProvider);
|
||||
var securityController = createEmbeddedSecurityController(
|
||||
application, DB_INSTANCE, credentialsProvider, smConfig
|
||||
);
|
||||
if (initDb) {
|
||||
//FIXME circular dependency
|
||||
DB_INSTANCE.setAdminSecurityController(securityController);
|
||||
@@ -76,8 +91,9 @@ public class EmbeddedSecurityControllerFactory {
|
||||
protected CBEmbeddedSecurityController createEmbeddedSecurityController(
|
||||
WebApplication application,
|
||||
CBDatabase database,
|
||||
SMCredentialsProvider credentialsProvider
|
||||
SMCredentialsProvider credentialsProvider,
|
||||
SMControllerConfiguration smConfig
|
||||
) {
|
||||
return new CBEmbeddedSecurityController(application, database, credentialsProvider);
|
||||
return new CBEmbeddedSecurityController(application, database, credentialsProvider, smConfig);
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* DBeaver - Universal Database Manager
|
||||
* Copyright (C) 2010-2022 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.cloudbeaver.service.security;
|
||||
|
||||
public class SMControllerConfiguration {
|
||||
//in minutes
|
||||
public static final int DEFAULT_ACCESS_TOKEN_TTL = 20;
|
||||
public static final int DEFAULT_REFRESH_TOKEN_TTL = 4320; //72h
|
||||
|
||||
private int accessTokenTtl = DEFAULT_ACCESS_TOKEN_TTL;
|
||||
private int refreshTokenTtl = DEFAULT_REFRESH_TOKEN_TTL;
|
||||
|
||||
public int getAccessTokenTtl() {
|
||||
return accessTokenTtl;
|
||||
}
|
||||
|
||||
public void setAccessTokenTtl(int accessTokenTtl) {
|
||||
this.accessTokenTtl = accessTokenTtl;
|
||||
}
|
||||
|
||||
public int getRefreshTokenTtl() {
|
||||
return refreshTokenTtl;
|
||||
}
|
||||
|
||||
public void setRefreshTokenTtl(int refreshTokenTtl) {
|
||||
this.refreshTokenTtl = refreshTokenTtl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user