Skip to content

Commit

Permalink
Added support for dynamic credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Woy [email protected]

[resolves r2dbc#273]

Signed-off-by: calebcodesgud <[email protected]>
  • Loading branch information
calebcodesgud committed Sep 7, 2022
1 parent 55a6e10 commit de9c40a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.r2dbc.spi;

import org.reactivestreams.Publisher;

import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -106,6 +108,11 @@ public final class ConnectionFactoryOptions {
*/
public static final Option<Duration> STATEMENT_TIMEOUT = Option.valueOf("statementTimeout");

/**
* A Credential publisher, which supports dynamic credential usage.
*/
public static final Option<Publisher<? extends Credential>> CREDENTIAL_PUBLISHER = Option.valueOf("credentialPublisher");

/**
* User for authentication.
*/
Expand Down
11 changes: 11 additions & 0 deletions r2dbc-spi/src/main/java/io/r2dbc/spi/Credential.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.r2dbc.spi;

/**
* Credentials used to authenticate with a database. Credential objects are
* mutable. Mutability allows any security sensitive values retained by a
* {@code Credential} to be cleared from memory. Drivers MUST NOT retain a
* reference to a {@code Credential} object after consuming it for database
* authentication.
*/
interface Credential {
}
16 changes: 16 additions & 0 deletions r2dbc-spi/src/main/java/io/r2dbc/spi/CredentialFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.r2dbc.spi;

/** Factory for creating {@link Credential} objects */
public class CredentialFactory {

/**
* Returns a new {@link UserPasswordCredential}
* @param user Username. Not null.
* @param password Password. Not null.
*/
public static UserPasswordCredential createUserPasswordCredential(
String user, CharSequence password) {
return new UserPasswordCredentialImpl(user, password);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.r2dbc.spi;

/**
* UserPasswordCredentials used to authenticate with a database.
*/
public interface UserPasswordCredential extends Credential {
String user();
CharSequence password();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.r2dbc.spi;

public class UserPasswordCredentialImpl implements UserPasswordCredential {

private String user;

private CharSequence password;

UserPasswordCredentialImpl(String user, CharSequence password) {
this.user = user;
this.password = password;
}

@Override
public String user() {
return this.user;
}

@Override
public CharSequence password() {
return this.password;
}
}

0 comments on commit de9c40a

Please sign in to comment.