From d01d4ac48b0583a5655c0d76a1148e4c6bd20a66 Mon Sep 17 00:00:00 2001 From: vzikratyi Date: Thu, 18 Jun 2020 18:49:57 +0300 Subject: [PATCH] Created oauth2 client_registration and mapper_config (as separate entities) --- .../main/data/upgrade/3.1.0/schema_update.sql | 56 ++++++++++ .../server/common/data/oauth2/MapperType.java | 5 + .../data/oauth2/OAuth2BasicMapperConfig.java | 21 ++++ .../data/oauth2/OAuth2ClientRegistration.java | 57 ++++++++++ .../data/oauth2/OAuth2CustomMapperConfig.java | 16 +++ .../data/oauth2/OAuth2MapperConfig.java | 34 ++++++ .../server/dao/model/ModelConstants.java | 40 +++++++ .../sql/OAuth2ClientRegistrationEntity.java | 99 +++++++++++++++++ .../model/sql/OAuth2MapperConfigEntity.java | 101 ++++++++++++++++++ .../resources/sql/schema-entities-hsql.sql | 36 +++++++ .../main/resources/sql/schema-entities.sql | 38 +++++++ 11 files changed, 503 insertions(+) create mode 100644 application/src/main/data/upgrade/3.1.0/schema_update.sql create mode 100644 common/data/src/main/java/org/thingsboard/server/common/data/oauth2/MapperType.java create mode 100644 common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2BasicMapperConfig.java create mode 100644 common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientRegistration.java create mode 100644 common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2CustomMapperConfig.java create mode 100644 common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2MapperConfig.java create mode 100644 dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2ClientRegistrationEntity.java create mode 100644 dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2MapperConfigEntity.java diff --git a/application/src/main/data/upgrade/3.1.0/schema_update.sql b/application/src/main/data/upgrade/3.1.0/schema_update.sql new file mode 100644 index 0000000000..3ee67b03a4 --- /dev/null +++ b/application/src/main/data/upgrade/3.1.0/schema_update.sql @@ -0,0 +1,56 @@ +-- +-- Copyright © 2016-2020 The Thingsboard Authors +-- +-- 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. +-- + +DROP TABLE IF EXISTS oauth2_client_registration; + +CREATE TABLE IF NOT EXISTS oauth2_client_registration ( + registration_id varchar(255) NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, + mapper_config_id varchar(31), + client_id varchar(255), + client_secret varchar(255), + authorization_uri varchar(255), + token_uri varchar(255), + redirect_uri_template varchar(255), + scope varchar(255), + authorization_grant_type varchar(255), + user_info_uri varchar(255), + user_name_attribute varchar(255), + jwk_set_uri varchar(255), + client_authentication_method varchar(255), + client_name varchar(255), + login_button_label varchar(255), + login_button_icon varchar(255) +); + +DROP TABLE IF EXISTS oauth2_mapper_config; + +CREATE TABLE IF NOT EXISTS oauth2_mapper_config ( + id varchar(31) NOT NULL CONSTRAINT oauth2_mapper_config_pkey PRIMARY KEY, + allow_user_creation boolean, + activate_user boolean, + type varchar(31), + basic_email_attribute_key varchar(31), + basic_first_name_attribute_key varchar(31), + basic_last_name_attribute_key varchar(31), + basic_tenant_name_strategy varchar(31), + basic_tenant_name_pattern varchar(255), + basic_customer_name_pattern varchar(255), + basic_default_dashboard_name varchar(255), + basic_always_full_screen boolean, + custom_url varchar(255), + custom_username varchar(255), + custom_password varchar(255) +); \ No newline at end of file diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/MapperType.java b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/MapperType.java new file mode 100644 index 0000000000..d33563b668 --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/MapperType.java @@ -0,0 +1,5 @@ +package org.thingsboard.server.common.data.oauth2; + +public enum MapperType { + BASIC, CUSTOM; +} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2BasicMapperConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2BasicMapperConfig.java new file mode 100644 index 0000000000..e91daf75e7 --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2BasicMapperConfig.java @@ -0,0 +1,21 @@ +package org.thingsboard.server.common.data.oauth2; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +@Builder(toBuilder = true) +@EqualsAndHashCode +@Getter +@ToString +public class OAuth2BasicMapperConfig { + private final String emailAttributeKey; + private final String firstNameAttributeKey; + private final String lastNameAttributeKey; + private final String tenantNameStrategy; + private final String tenantNamePattern; + private final String customerNamePattern; + private final String defaultDashboardName; + private final boolean alwaysFullScreen; +} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientRegistration.java b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientRegistration.java new file mode 100644 index 0000000000..d5bd3b076e --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2ClientRegistration.java @@ -0,0 +1,57 @@ +package org.thingsboard.server.common.data.oauth2; + +import lombok.*; +import org.thingsboard.server.common.data.BaseData; +import org.thingsboard.server.common.data.id.OAuth2IntegrationId; + +@EqualsAndHashCode(callSuper = true) +@Data +@ToString(exclude = {"clientSecret"}) +public class OAuth2ClientRegistration extends BaseData { + + private String registrationId; + private OAuth2IntegrationId mapperConfigId; + private String clientId; + private String clientSecret; + private String authorizationUri; + private String tokenUri; + private String redirectUriTemplate; + private String scope; + private String authorizationGrantType; + private String userInfoUri; + private String userNameAttribute; + private String jwkSetUri; + private String clientAuthenticationMethod; + private String clientName; + private String loginButtonLabel; + private String loginButtonIcon; + + public OAuth2ClientRegistration() { + super(); + } + + public OAuth2ClientRegistration(OAuth2IntegrationId id) { + super(id); + } + + @Builder(toBuilder = true) + public OAuth2ClientRegistration(OAuth2IntegrationId id, String registrationId, String clientId, String clientSecret, String authorizationUri, String tokenUri, String redirectUriTemplate, String scope, String authorizationGrantType, String userInfoUri, String userNameAttribute, String jwkSetUri, String clientAuthenticationMethod, String clientName, String loginButtonLabel, String loginButtonIcon, OAuth2IntegrationId mapperConfigId) { + super(id); + this.registrationId = registrationId; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.authorizationUri = authorizationUri; + this.tokenUri = tokenUri; + this.redirectUriTemplate = redirectUriTemplate; + this.scope = scope; + this.authorizationGrantType = authorizationGrantType; + this.userInfoUri = userInfoUri; + this.userNameAttribute = userNameAttribute; + this.jwkSetUri = jwkSetUri; + this.clientAuthenticationMethod = clientAuthenticationMethod; + this.clientName = clientName; + this.loginButtonLabel = loginButtonLabel; + this.loginButtonIcon = loginButtonIcon; + this.mapperConfigId = mapperConfigId; + } +} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2CustomMapperConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2CustomMapperConfig.java new file mode 100644 index 0000000000..ea9c963721 --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2CustomMapperConfig.java @@ -0,0 +1,16 @@ +package org.thingsboard.server.common.data.oauth2; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +@Builder(toBuilder = true) +@EqualsAndHashCode +@Getter +@ToString(exclude = {"password"}) +public class OAuth2CustomMapperConfig { + private final String url; + private final String username; + private final String password; +} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2MapperConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2MapperConfig.java new file mode 100644 index 0000000000..95c1fdf4a8 --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2MapperConfig.java @@ -0,0 +1,34 @@ +package org.thingsboard.server.common.data.oauth2; + +import lombok.*; +import org.thingsboard.server.common.data.BaseData; +import org.thingsboard.server.common.data.id.OAuth2IntegrationId; + +@EqualsAndHashCode(callSuper = true) +@Data +@ToString +public class OAuth2MapperConfig extends BaseData { + private boolean allowUserCreation; + private boolean activateUser; + private MapperType type; + private OAuth2BasicMapperConfig basicConfig; + private OAuth2CustomMapperConfig customConfig; + + public OAuth2MapperConfig() { + super(); + } + + public OAuth2MapperConfig(OAuth2IntegrationId id) { + super(id); + } + + @Builder(toBuilder = true) + public OAuth2MapperConfig(OAuth2IntegrationId id, boolean allowUserCreation, boolean activateUser, MapperType type, OAuth2BasicMapperConfig basicConfig, OAuth2CustomMapperConfig customConfig) { + super(id); + this.allowUserCreation = allowUserCreation; + this.activateUser = activateUser; + this.type = type; + this.basicConfig = basicConfig; + this.customConfig = customConfig; + } +} diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java index f52e450d8b..c551114aa5 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java @@ -354,6 +354,46 @@ public class ModelConstants { public static final String RULE_NODE_NAME_PROPERTY = "name"; public static final String RULE_NODE_CONFIGURATION_PROPERTY = "configuration"; + /** + * Cassandra OAuth2 client registration constants. + */ + public static final String OAUTH2_CLIENT_REGISTRATION_COLUMN_FAMILY_NAME = "oauth2_client_registration"; + public static final String OAUTH2_CLIENT_REGISTRATION_ID_PROPERTY = "registration_id"; + public static final String OAUTH2_CLIENT_REGISTRATION_MAPPER_CONFIG_ID_PROPERTY = "mapper_config_id"; + public static final String OAUTH2_CLIENT_ID_PROPERTY = "client_id"; + public static final String OAUTH2_CLIENT_SECRET_PROPERTY = "client_secret"; + public static final String OAUTH2_AUTHORIZATION_URI_PROPERTY = "authorization_uri"; + public static final String OAUTH2_TOKEN_URI_PROPERTY = "token_uri"; + public static final String OAUTH2_REDIRECT_URI_TEMPLATE_PROPERTY = "redirect_uri_template"; + public static final String OAUTH2_SCOPE_PROPERTY = "scope"; + public static final String OAUTH2_AUTHORIZATION_GRANT_TYPE_PROPERTY = "authorization_grant_type"; + public static final String OAUTH2_USER_INFO_URI_PROPERTY = "user_info_uri"; + public static final String OAUTH2_USER_NAME_ATTRIBUTE_PROPERTY = "user_name_attribute"; + public static final String OAUTH2_JWK_SET_URI_PROPERTY = "jwk_set_uri"; + public static final String OAUTH2_CLIENT_AUTHENTICATION_METHOD_PROPERTY = "client_authentication_method"; + public static final String OAUTH2_CLIENT_NAME_PROPERTY = "client_name"; + public static final String OAUTH2_LOGIN_BUTTON_LABEL_PROPERTY = "login_button_label"; + public static final String OAUTH2_LOGIN_BUTTON_ICON_PROPERTY = "login_button_icon"; + + /** + * Cassandra OAuth2 mapper config constants. + */ + public static final String OAUTH2_MAPPER_CONFIG_COLUMN_FAMILY_NAME = "oauth2_mapper_config"; + public static final String OAUTH2_ALLOW_USER_CREATION_PROPERTY = "allow_user_creation"; + public static final String OAUTH2_ACTIVATE_USER_PROPERTY = "activate_user"; + public static final String OAUTH2_MAPPER_TYPE_PROPERTY = "type"; + public static final String OAUTH2_EMAIL_ATTRIBUTE_KEY_PROPERTY = "basic_email_attribute_key"; + public static final String OAUTH2_FIRST_NAME_ATTRIBUTE_KEY_PROPERTY = "basic_first_name_attribute_key"; + public static final String OAUTH2_LAST_NAME_ATTRIBUTE_KEY_PROPERTY = "basic_last_name_attribute_key"; + public static final String OAUTH2_TENANT_NAME_STRATEGY_PROPERTY = "basic_tenant_name_strategy"; + public static final String OAUTH2_TENANT_NAME_PATTERN_PROPERTY = "basic_tenant_name_pattern"; + public static final String OAUTH2_CUSTOMER_NAME_PATTERN_PROPERTY = "basic_customer_name_pattern"; + public static final String OAUTH2_DEFAULT_DASHBOARD_NAME_PROPERTY = "basic_default_dashboard_name"; + public static final String OAUTH2_ALWAYS_FULL_SCREEN_PROPERTY = "basic_always_full_screen"; + public static final String OAUTH2_MAPPER_URL_PROPERTY = "custom_url"; + public static final String OAUTH2_MAPPER_USERNAME_PROPERTY = "custom_username"; + public static final String OAUTH2_MAPPER_PASSWORD_PROPERTY = "custom_password"; + /** * Cassandra attributes and timeseries constants. */ diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2ClientRegistrationEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2ClientRegistrationEntity.java new file mode 100644 index 0000000000..bc402a7d7d --- /dev/null +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2ClientRegistrationEntity.java @@ -0,0 +1,99 @@ +/** + * Copyright © 2016-2020 The Thingsboard Authors + * + * 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 org.thingsboard.server.dao.model.sql; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.TypeDef; +import org.thingsboard.server.common.data.EntityView; +import org.thingsboard.server.common.data.id.OAuth2IntegrationId; +import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistration; +import org.thingsboard.server.dao.model.BaseSqlEntity; +import org.thingsboard.server.dao.model.ModelConstants; +import org.thingsboard.server.dao.util.mapping.JsonStringType; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Table(name = ModelConstants.OAUTH2_CLIENT_REGISTRATION_COLUMN_FAMILY_NAME) +public class OAuth2ClientRegistrationEntity extends BaseSqlEntity { + + @Column(name = ModelConstants.OAUTH2_CLIENT_REGISTRATION_ID_PROPERTY) + private String registrationId; + @Column(name = ModelConstants.OAUTH2_CLIENT_REGISTRATION_MAPPER_CONFIG_ID_PROPERTY) + private String mapperConfigId; + @Column(name = ModelConstants.OAUTH2_CLIENT_ID_PROPERTY) + private String clientId; + @Column(name = ModelConstants.OAUTH2_CLIENT_SECRET_PROPERTY) + private String clientSecret; + @Column(name = ModelConstants.OAUTH2_AUTHORIZATION_URI_PROPERTY) + private String authorizationUri; + @Column(name = ModelConstants.OAUTH2_TOKEN_URI_PROPERTY) + private String tokenUri; + @Column(name = ModelConstants.OAUTH2_REDIRECT_URI_TEMPLATE_PROPERTY) + private String redirectUriTemplate; + @Column(name = ModelConstants.OAUTH2_SCOPE_PROPERTY) + private String scope; + @Column(name = ModelConstants.OAUTH2_AUTHORIZATION_GRANT_TYPE_PROPERTY) + private String authorizationGrantType; + @Column(name = ModelConstants.OAUTH2_USER_INFO_URI_PROPERTY) + private String userInfoUri; + @Column(name = ModelConstants.OAUTH2_USER_NAME_ATTRIBUTE_PROPERTY) + private String userNameAttribute; + @Column(name = ModelConstants.OAUTH2_JWK_SET_URI_PROPERTY) + private String jwkSetUri; + @Column(name = ModelConstants.OAUTH2_CLIENT_AUTHENTICATION_METHOD_PROPERTY) + private String clientAuthenticationMethod; + @Column(name = ModelConstants.OAUTH2_CLIENT_NAME_PROPERTY) + private String clientName; + @Column(name = ModelConstants.OAUTH2_LOGIN_BUTTON_LABEL_PROPERTY) + private String loginButtonLabel; + @Column(name = ModelConstants.OAUTH2_LOGIN_BUTTON_ICON_PROPERTY) + private String loginButtonIcon; + + public OAuth2ClientRegistrationEntity() { + super(); + } + + @Override + public OAuth2ClientRegistration toData() { + return OAuth2ClientRegistration.builder() + .id(new OAuth2IntegrationId(toUUID(id))) + .registrationId(registrationId) + .mapperConfigId(new OAuth2IntegrationId(toUUID(mapperConfigId))) + .clientId(clientId) + .clientSecret(clientSecret) + .authorizationUri(authorizationUri) + .tokenUri(tokenUri) + .redirectUriTemplate(redirectUriTemplate) + .scope(scope) + .authorizationGrantType(authorizationGrantType) + .userInfoUri(userInfoUri) + .userNameAttribute(userNameAttribute) + .jwkSetUri(jwkSetUri) + .clientAuthenticationMethod(clientAuthenticationMethod) + .clientName(clientName) + .loginButtonLabel(loginButtonLabel) + .loginButtonIcon(loginButtonIcon) + .build(); + } +} diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2MapperConfigEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2MapperConfigEntity.java new file mode 100644 index 0000000000..de75c052e4 --- /dev/null +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/OAuth2MapperConfigEntity.java @@ -0,0 +1,101 @@ +/** + * Copyright © 2016-2020 The Thingsboard Authors + *

+ * 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 org.thingsboard.server.dao.model.sql; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.TypeDef; +import org.thingsboard.server.common.data.id.OAuth2IntegrationId; +import org.thingsboard.server.common.data.oauth2.MapperType; +import org.thingsboard.server.common.data.oauth2.OAuth2BasicMapperConfig; +import org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig; +import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig; +import org.thingsboard.server.dao.model.BaseSqlEntity; +import org.thingsboard.server.dao.model.ModelConstants; +import org.thingsboard.server.dao.util.mapping.JsonStringType; + +import javax.persistence.*; + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Table(name = ModelConstants.OAUTH2_MAPPER_CONFIG_COLUMN_FAMILY_NAME) +public class OAuth2MapperConfigEntity extends BaseSqlEntity { + + @Column(name = ModelConstants.OAUTH2_ALLOW_USER_CREATION_PROPERTY) + private Boolean allowUserCreation; + @Column(name = ModelConstants.OAUTH2_ACTIVATE_USER_PROPERTY) + private Boolean activateUser; + @Enumerated(EnumType.STRING) + @Column(name = ModelConstants.OAUTH2_MAPPER_TYPE_PROPERTY) + private MapperType type; + @Column(name = ModelConstants.OAUTH2_EMAIL_ATTRIBUTE_KEY_PROPERTY) + private String emailAttributeKey; + @Column(name = ModelConstants.OAUTH2_FIRST_NAME_ATTRIBUTE_KEY_PROPERTY) + private String firstNameAttributeKey; + @Column(name = ModelConstants.OAUTH2_LAST_NAME_ATTRIBUTE_KEY_PROPERTY) + private String lastNameAttributeKey; + @Column(name = ModelConstants.OAUTH2_TENANT_NAME_STRATEGY_PROPERTY) + private String tenantNameStrategy; + @Column(name = ModelConstants.OAUTH2_TENANT_NAME_PATTERN_PROPERTY) + private String tenantNamePattern; + @Column(name = ModelConstants.OAUTH2_CUSTOMER_NAME_PATTERN_PROPERTY) + private String customerNamePattern; + @Column(name = ModelConstants.OAUTH2_DEFAULT_DASHBOARD_NAME_PROPERTY) + private String defaultDashboardName; + @Column(name = ModelConstants.OAUTH2_ALWAYS_FULL_SCREEN_PROPERTY) + private Boolean alwaysFullScreen; + @Column(name = ModelConstants.OAUTH2_MAPPER_URL_PROPERTY) + private String url; + @Column(name = ModelConstants.OAUTH2_MAPPER_USERNAME_PROPERTY) + private String username; + @Column(name = ModelConstants.OAUTH2_MAPPER_PASSWORD_PROPERTY) + private String password; + + public OAuth2MapperConfigEntity() { + super(); + } + + @Override + public OAuth2MapperConfig toData() { + return OAuth2MapperConfig.builder() + .id(new OAuth2IntegrationId(toUUID(id))) + .allowUserCreation(allowUserCreation) + .activateUser(activateUser) + .type(type) + .basicConfig( + OAuth2BasicMapperConfig.builder() + .emailAttributeKey(emailAttributeKey) + .firstNameAttributeKey(firstNameAttributeKey) + .lastNameAttributeKey(lastNameAttributeKey) + .tenantNameStrategy(tenantNameStrategy) + .tenantNamePattern(tenantNamePattern) + .customerNamePattern(customerNamePattern) + .defaultDashboardName(defaultDashboardName) + .alwaysFullScreen(alwaysFullScreen) + .build() + ) + .customConfig( + OAuth2CustomMapperConfig.builder() + .url(url) + .username(username) + .password(password) + .build() + ) + .build(); + } +} diff --git a/dao/src/main/resources/sql/schema-entities-hsql.sql b/dao/src/main/resources/sql/schema-entities-hsql.sql index 697e34930a..d9dba652b1 100644 --- a/dao/src/main/resources/sql/schema-entities-hsql.sql +++ b/dao/src/main/resources/sql/schema-entities-hsql.sql @@ -253,3 +253,39 @@ CREATE TABLE IF NOT EXISTS entity_view ( additional_info varchar ); +CREATE TABLE IF NOT EXISTS oauth2_client_registration ( + registration_id varchar(255) NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, + mapper_config_id varchar(31), + client_id varchar(255), + client_secret varchar(255), + authorization_uri varchar(255), + token_uri varchar(255), + redirect_uri_template varchar(255), + scope varchar(255), + authorization_grant_type varchar(255), + user_info_uri varchar(255), + user_name_attribute varchar(255), + jwk_set_uri varchar(255), + client_authentication_method varchar(255), + client_name varchar(255), + login_button_label varchar(255), + login_button_icon varchar(255) +); + +CREATE TABLE IF NOT EXISTS oauth2_mapper_config ( + id varchar(31) NOT NULL CONSTRAINT oauth2_mapper_config_pkey PRIMARY KEY, + allow_user_creation boolean, + activate_user boolean, + type varchar(31), + basic_email_attribute_key varchar(31), + basic_first_name_attribute_key varchar(31), + basic_last_name_attribute_key varchar(31), + basic_tenant_name_strategy varchar(31), + basic_tenant_name_pattern varchar(255), + basic_customer_name_pattern varchar(255), + basic_default_dashboard_name varchar(255), + basic_always_full_screen boolean, + custom_url varchar(255), + custom_username varchar(255), + custom_password varchar(255) +); diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 931856e1df..820a7775c5 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -253,6 +253,44 @@ CREATE TABLE IF NOT EXISTS entity_view ( additional_info varchar ); +CREATE TABLE IF NOT EXISTS oauth2_client_registration ( + id varchar(31) NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, + registration_id varchar(255) UNIQUE, + mapper_config_id varchar(31), + client_id varchar(255), + client_secret varchar(255), + authorization_uri varchar(255), + token_uri varchar(255), + redirect_uri_template varchar(255), + scope varchar(255), + authorization_grant_type varchar(255), + user_info_uri varchar(255), + user_name_attribute varchar(255), + jwk_set_uri varchar(255), + client_authentication_method varchar(255), + client_name varchar(255), + login_button_label varchar(255), + login_button_icon varchar(255) +); + +CREATE TABLE IF NOT EXISTS oauth2_mapper_config ( + id varchar(31) NOT NULL CONSTRAINT oauth2_mapper_config_pkey PRIMARY KEY, + allow_user_creation boolean, + activate_user boolean, + type varchar(31), + basic_email_attribute_key varchar(31), + basic_first_name_attribute_key varchar(31), + basic_last_name_attribute_key varchar(31), + basic_tenant_name_strategy varchar(31), + basic_tenant_name_pattern varchar(255), + basic_customer_name_pattern varchar(255), + basic_default_dashboard_name varchar(255), + basic_always_full_screen boolean, + custom_url varchar(255), + custom_username varchar(255), + custom_password varchar(255) +); + CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint) LANGUAGE plpgsql AS $$