Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(idp): support Oracle database for JDBC IdP #2654

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@
<name>Gravitee IO - Access Management - Identity Provider - JDBC</name>

<properties>
<r2dbc-pool.version>0.8.6.RELEASE</r2dbc-pool.version>
<r2dbc-postgresql.version>0.8.11.RELEASE</r2dbc-postgresql.version>
<r2dbc-mssql.version>0.8.7.RELEASE</r2dbc-mssql.version>
<r2dbc-mysql.version>0.8.2.RELEASE</r2dbc-mysql.version>
<r2dbc-mariadb.version>1.0.0</r2dbc-mariadb.version>
<r2dbc-spi.version>0.8.4.RELEASE</r2dbc-spi.version>
<r2dbc-releasetrain.version>Borca-SR2</r2dbc-releasetrain.version>
<r2dbc-mysql.version>0.9.3</r2dbc-mysql.version>
<spring-data-r2dbc.version>1.4.1</spring-data-r2dbc.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-bom</artifactId>
<version>${r2dbc-releasetrain.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Gravitee.io -->
<dependency>
Expand Down Expand Up @@ -86,64 +94,30 @@

<!-- R2DBC -->
<dependency>
<groupId>io.r2dbc</groupId>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>${r2dbc-postgresql.version}</version>
<exclusions>
<exclusion>
<artifactId>r2dbc-spi</artifactId>
<groupId>io.r2dbc</groupId>
</exclusion>
<exclusion>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-mssql</artifactId>
<version>${r2dbc-mssql.version}</version>
<exclusions>
<exclusion>
<artifactId>r2dbc-spi</artifactId>
<groupId>io.r2dbc</groupId>
</exclusion>
<exclusion>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<groupId>io.asyncer</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>${r2dbc-mysql.version}</version>
<exclusions>
<exclusion>
<artifactId>r2dbc-spi</artifactId>
<groupId>io.r2dbc</groupId>
</exclusion>
<exclusion>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>${r2dbc-mariadb.version}</version>
<exclusions>
<exclusion>
<artifactId>r2dbc-spi</artifactId>
<groupId>io.r2dbc</groupId>
</exclusion>
<exclusion>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.database.r2dbc</groupId>
<artifactId>oracle-r2dbc</artifactId>
<scope>provided</scope>
</dependency>

<!-- Spring -->
Expand Down Expand Up @@ -214,6 +188,18 @@
<version>${test-container.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-xe</artifactId>
<version>1.18.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>21.7.0.0</version>
<scope>test</scope>
</dependency>

<dependency>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class JdbcIdentityProviderConfiguration implements IdentityProviderConfig
private String selectUserByEmailQuery;
private String identifierAttribute = FIELD_ID;
private String emailAttribute = FIELD_EMAIL;
private String metadataAttribute = FIELD_METADATA;
private String usernameAttribute = FIELD_USERNAME;
private String passwordAttribute = FIELD_PASSWORD;
private String passwordEncoder = PasswordEncoder.BCRYPT;
Expand Down Expand Up @@ -227,7 +228,11 @@ public void setEmailAttribute(String emailAttribute) {
}

public String getMetadataAttribute() {
return FIELD_METADATA;
return metadataAttribute;
}

public void setMetadataAttribute(String metadataAttribute) {
this.metadataAttribute = metadataAttribute;
}

public boolean getAutoProvisioning() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ public Single<UserProvider> asyncStart() {
}

private String tableExists(String protocol, String table) {
if ("sqlserver".equalsIgnoreCase(protocol)) {
return "SELECT 1 FROM sysobjects WHERE name = '" + table + "' AND xtype = 'U'";
} else {
return "SELECT 1 FROM information_schema.tables WHERE table_name = '" + table + "'";
switch (protocol) {
case "sqlserver" :
return "SELECT 1 FROM sysobjects WHERE name = '" + table + "' AND xtype = 'U'";
case "oracle":
return "SELECT 1 from user_tables where table_name = '" + table + "'";
default:
return "SELECT 1 FROM information_schema.tables WHERE table_name = '" + table + "'";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
public final class ColumnMapRowMapper {

public static Map<String, Object> mapRow(Row row, RowMetadata rowMetadata) {
Map<String, Object> claims = new HashMap<>(rowMetadata.getColumnNames()
return new HashMap<>(rowMetadata.getColumnMetadatas()
.stream()
.filter(c -> row.get(c) != null)
.collect(Collectors.toMap(c -> c, c -> row.get(c))));
return claims;
.filter(c -> row.get(c.getName()) != null)
.collect(Collectors.toMap(c -> c.getName(), c -> row.get(c.getName()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package io.gravitee.am.identityprovider.jdbc.utils;

import io.r2dbc.spi.Statement;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
Expand All @@ -32,6 +30,8 @@ public static String getIndexParameter(String database, int index, String field)
return "$" + index;
case "sqlserver":
return "@" + field;
case "oracle":
return ":" + field;
default:
return "" + index;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--
-- Script to create Oracle schema
-- Table & index names are suffixed by 3 underscores to define a
-- pattern to replace with the domain name
--
CREATE TABLE idp_users___ (id NVARCHAR2(64) NOT NULL, username NVARCHAR2(320) NOT NULL, password NVARCHAR2(255) NULL, email NVARCHAR2(320) NULL, metadata CLOB NULL, PRIMARY KEY (id))
CREATE INDEX idp_users____username_idx ON users(username)
Comment on lines +6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: username must be unique

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"protocol" : {
"type": "string",
"enum": ["postgresql", "mysql", "sqlserver", "mariadb"],
"enum": ["postgresql", "mysql", "sqlserver", "mariadb", "oracle"],
"title": "Database driver identifier",
"description": "Type of your relational database (RDBMS). PostgreSQL, MySQL, SQL Server, MariaDB, ..."
"description": "Type of your relational database (RDBMS). PostgreSQL, MySQL, SQL Server, MariaDB, Oracle"
},
"database" : {
"type" : "string",
Expand Down Expand Up @@ -79,6 +79,12 @@
"title": "User email attribute",
"description": "Email field of your users"
},
"metadataAttribute" : {
"type" : "string",
"default": "metadata",
"title": "User metadata attribute",
"description": "Additional information field of your users"
},
"passwordAttribute" : {
"type" : "string",
"default": "password",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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.gravitee.am.identityprovider.jdbc.authentication;

import io.gravitee.am.identityprovider.jdbc.authentication.spring.JdbcAuthenticationProviderConfiguration;
import io.gravitee.am.identityprovider.jdbc.configuration.JdbcAuthenticationProviderConfigurationTest_Oracle;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
*/
@ContextConfiguration(classes = { JdbcAuthenticationProviderConfigurationTest_Oracle.class, JdbcAuthenticationProviderConfiguration.class }, loader = AnnotationConfigContextLoader.class)
public class JdbcAuthenticationProvider_OracleTest extends JdbcAuthenticationProviderTest { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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.gravitee.am.identityprovider.jdbc.configuration;

import org.springframework.context.annotation.Configuration;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
*/
@Configuration
public class JdbcAuthenticationProviderConfigurationTest_Oracle extends JdbcAuthenticationProviderConfigurationTest {

public String url() {
return "r2dbc:tc:oracle:///db?TC_IMAGE_TAG=21-slim-faststart";
}

@Override
public String protocol() {
return "oracle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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.gravitee.am.identityprovider.jdbc.user;

import io.gravitee.am.identityprovider.jdbc.configuration.JdbcAuthenticationProviderConfigurationTest_Oracle;
import io.gravitee.am.identityprovider.jdbc.user.spring.JdbcUserProviderConfiguration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

/**
* @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
* @author GraviteeSource Team
*/
@ContextConfiguration(classes = { JdbcAuthenticationProviderConfigurationTest_Oracle.class, JdbcUserProviderConfiguration.class }, loader = AnnotationConfigContextLoader.class)
public class JdbcUserProvider_OracleTest extends JdbcUserProvider_Test { }
8 changes: 5 additions & 3 deletions gravitee-am-reporter/gravitee-am-reporter-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<name>Gravitee IO - Access Management - Reporter JDBC</name>

<properties>
<r2dbc-releasetrain.version>Arabba-SR11</r2dbc-releasetrain.version>
<r2dbc-releasetrain.version>Borca-SR2</r2dbc-releasetrain.version>
<r2dbc-mysql.version>0.9.3</r2dbc-mysql.version>

<jdbc-mssql.version>7.4.1.jre8</jdbc-mssql.version>
<jdbc-mysql.version>8.0.29</jdbc-mysql.version>
Expand Down Expand Up @@ -110,7 +111,7 @@
</dependency>

<dependency>
<groupId>io.r2dbc</groupId>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>provided</scope>
</dependency>
Expand All @@ -120,8 +121,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<groupId>io.asyncer</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>${r2dbc-mysql.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class JdbcReporterConfiguration implements ReporterConfiguration {
private Integer maxSize = 10;
private Integer maxIdleTime = 30000;
private Integer maxLifeTime = 30000;
private Integer maxAcquireTime = 0 ;
private Integer maxCreateConnectionTime = 0;
private Integer maxAcquireTime = -1;
private Integer maxCreateConnectionTime = -1;
private String validationQuery = "SELECT 1";
private String tableSuffix;
private Integer bulkActions = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ConnectionFactory connectionFactory() {
options = ConnectionFactoryOptions.builder()
.from(options)
.option(DRIVER, "pool")
.option(PROTOCOL, options.getValue(DRIVER))
.option(PROTOCOL, options.getValue(DRIVER).toString())
.build();
this.connectionFactory = ConnectionFactories.get(options);
}
Expand All @@ -81,13 +81,12 @@ public ConnectionFactory connectionFactory() {
public JdbcReporterConfiguration reporterConfiguration(R2dbcDatabaseContainer dbContainer) {
ConnectionFactoryOptions options = dbContainer.getOptions();
JdbcReporterConfiguration config = new JdbcReporterConfiguration();
config.setDriver(options.getValue(DRIVER));
config.setDatabase(options.getValue(DATABASE));
config.setHost(options.getValue(HOST));
config.setPort(options.getValue(PORT));
config.setUsername(options.getValue(USER));
CharSequence value = options.getValue(PASSWORD);
config.setPassword(String.join("", value));
config.setDriver(options.getValue(DRIVER).toString());
config.setDatabase(options.getValue(DATABASE).toString());
config.setHost(options.getValue(HOST).toString());
config.setPort(Integer.valueOf(options.getValue(PORT).toString()));
config.setUsername(options.getValue(USER).toString());
config.setPassword(options.getValue(PASSWORD).toString());

config.setTableSuffix("junit");
config.setFlushInterval(1);
Expand Down
Loading