Skip to content

Commit

Permalink
--wip--
Browse files Browse the repository at this point in the history
  • Loading branch information
Titouan Compiegne committed May 30, 2023
1 parent 1e920ec commit f470b1d
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
<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-pool.version>0.9.2.RELEASE</r2dbc-pool.version>
<r2dbc-postgresql.version>0.9.2.RELEASE</r2dbc-postgresql.version>
<r2dbc-mssql.version>0.9.0.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-mariadb.version>1.1.2</r2dbc-mariadb.version>
<r2dbc-oracle.version>0.4.0</r2dbc-oracle.version>
<r2dbc-spi.version>0.9.1.RELEASE</r2dbc-spi.version>
<spring-data-r2dbc.version>1.4.1</spring-data-r2dbc.version>
</properties>

Expand Down Expand Up @@ -86,7 +87,7 @@

<!-- R2DBC -->
<dependency>
<groupId>io.r2dbc</groupId>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>${r2dbc-postgresql.version}</version>
<exclusions>
Expand Down Expand Up @@ -145,6 +146,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.oracle.database.r2dbc</groupId>
<artifactId>oracle-r2dbc</artifactId>
<version>${r2dbc-oracle.version}</version>
<exclusions>
<exclusion>
<artifactId>r2dbc-spi</artifactId>
<groupId>io.r2dbc</groupId>
</exclusion>
<exclusion>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
</exclusion>
</exclusions>
</dependency>

<!-- Spring -->
<dependency>
Expand Down Expand Up @@ -214,6 +230,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)
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 { }
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 @@ -30,7 +30,7 @@
<name>Gravitee IO - Access Management - Repository JDBC API</name>

<properties>
<r2dbc-releasetrain.version>Arabba-SR13</r2dbc-releasetrain.version>
<r2dbc-releasetrain.version>Borca-SR2</r2dbc-releasetrain.version>
<reactor-adapter.version>3.4.9</reactor-adapter.version>
<reactor-core.version>3.4.13</reactor-core.version>
<spring-data-r2dbc.version>1.4.1</spring-data-r2dbc.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.r2dbc.pool.ConnectionPool;
import io.r2dbc.pool.ConnectionPoolConfiguration;
import io.r2dbc.pool.PoolingConnectionFactoryProvider;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
Expand Down Expand Up @@ -91,8 +92,8 @@ public static ConnectionFactory createClient(R2DBCConnectionConfiguration config
.option(PoolingConnectionFactoryProvider.MAX_SIZE, 10)
.option(PoolingConnectionFactoryProvider.MAX_IDLE_TIME, Duration.of(30000l, ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_LIFE_TIME, Duration.of(30000l, ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_ACQUIRE_TIME, Duration.of(0, ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_CREATE_CONNECTION_TIME, Duration.of(0, ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_ACQUIRE_TIME, ConnectionPoolConfiguration.NO_TIMEOUT)
.option(PoolingConnectionFactoryProvider.MAX_CREATE_CONNECTION_TIME, ConnectionPoolConfiguration.NO_TIMEOUT)
.option(PoolingConnectionFactoryProvider.VALIDATION_DEPTH, ValidationDepth.LOCAL);

List<Map<String, String>> options = configuration.getOptions();
Expand All @@ -104,7 +105,16 @@ public static ConnectionFactory createClient(R2DBCConnectionConfiguration config
});
}

ConnectionPool connectionPool = (ConnectionPool) ConnectionFactories.get(builder.build());
ConnectionPool connectionPool;
// TCCL has been introduced to support Oracle driver loading
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader goldenLoader = ConnectionFactories.class.getClassLoader();
Thread.currentThread().setContextClassLoader(goldenLoader);
connectionPool = (ConnectionPool) ConnectionFactories.get(builder.build());
} finally {
Thread.currentThread().setContextClassLoader(origLoader);
}
LOGGER.info("Connection pool created for database server {} on host {}", configuration.getProtocol(), configuration.getHost());

final Tags tags = Tags.of(
Expand Down Expand Up @@ -149,8 +159,8 @@ public ConnectionFactory factory() {
.option(PoolingConnectionFactoryProvider.MAX_SIZE, Integer.parseInt(environment.getProperty(prefix+"maxSize", "10")))
.option(PoolingConnectionFactoryProvider.MAX_IDLE_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxIdleTime", "30000")), ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_LIFE_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxLifeTime", "30000")), ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_ACQUIRE_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxAcquireTime", "0")), ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_CREATE_CONNECTION_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxCreateConnectionTime", "0")), ChronoUnit.MILLIS));
.option(PoolingConnectionFactoryProvider.MAX_ACQUIRE_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxAcquireTime", "-1")), ChronoUnit.MILLIS))
.option(PoolingConnectionFactoryProvider.MAX_CREATE_CONNECTION_TIME, Duration.of(Long.parseLong(environment.getProperty(prefix+"maxCreateConnectionTime", "-1")), ChronoUnit.MILLIS));

if (port != null) {
builder.option(PORT, Integer.parseInt(port));
Expand Down
Loading

0 comments on commit f470b1d

Please sign in to comment.