-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FederatedAuthConnectionPlugin (#741)
- Loading branch information
1 parent
a6b1e17
commit 5fcf8f0
Showing
21 changed files
with
1,976 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
examples/AWSDriverExample/src/main/java/software/amazon/FederatedAuthPluginExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* 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 software.amazon; | ||
|
||
import software.amazon.jdbc.PropertyDefinition; | ||
import software.amazon.jdbc.plugin.federatedauth.FederatedAuthPlugin; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.Properties; | ||
|
||
public class FederatedAuthPluginExample { | ||
|
||
private static final String CONNECTION_STRING = "jdbc:aws-wrapper:postgresql://db-identifier.XYZ.us-east-2.rds.amazonaws.com:5432/employees"; | ||
|
||
public static void main(String[] args) throws SQLException { | ||
// Set the AWS Federated Authentication Connection Plugin parameters and the JDBC Wrapper parameters. | ||
final Properties properties = new Properties(); | ||
|
||
// Enable the AWS Federated Authentication Connection Plugin. | ||
properties.setProperty(PropertyDefinition.PLUGINS.name, "federatedAuth"); | ||
properties.setProperty(FederatedAuthPlugin.IDP_NAME.name, "adfs"); | ||
properties.setProperty(FederatedAuthPlugin.IDP_ENDPOINT.name, "ec2amaz-ab3cdef.example.com"); | ||
properties.setProperty(FederatedAuthPlugin.IAM_ROLE_ARN.name, "arn:aws:iam::123456789012:role/adfs_example_iam_role"); | ||
properties.setProperty(FederatedAuthPlugin.IAM_IDP_ARN.name, "arn:aws:iam::123456789012:saml-provider/adfs_example"); | ||
properties.setProperty(FederatedAuthPlugin.IAM_REGION.name, "us-east-2"); | ||
properties.setProperty(FederatedAuthPlugin.IDP_USERNAME.name, "[email protected]"); | ||
properties.setProperty(FederatedAuthPlugin.IDP_PASSWORD.name, "somePassword"); | ||
properties.setProperty(PropertyDefinition.USER.name, "someIamUser"); | ||
|
||
// Try and make a connection: | ||
try (final Connection conn = DriverManager.getConnection(CONNECTION_STRING, properties); | ||
final Statement statement = conn.createStatement(); | ||
final ResultSet rs = statement.executeQuery("SELECT 1")) { | ||
System.out.println(Util.getResult(rs)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
wrapper/src/main/java/software/amazon/jdbc/plugin/TokenInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* 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 software.amazon.jdbc.plugin; | ||
|
||
import java.time.Instant; | ||
|
||
public class TokenInfo { | ||
private final String token; | ||
private final Instant expiration; | ||
|
||
public TokenInfo(final String token, final Instant expiration) { | ||
this.token = token; | ||
this.expiration = expiration; | ||
} | ||
|
||
public String getToken() { | ||
return this.token; | ||
} | ||
|
||
public Instant getExpiration() { | ||
return this.expiration; | ||
} | ||
|
||
public boolean isExpired() { | ||
return Instant.now().isAfter(this.expiration); | ||
} | ||
} |
Oops, something went wrong.