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

🐛 Session not invalidated on org switch #251

Merged
Merged
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
4 changes: 4 additions & 0 deletions src/main/java/com/okta/tools/helpers/SessionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class SessionHelper {

private static final String OKTA_AWS_CLI_EXPIRY_PROPERTY = "OKTA_AWS_CLI_EXPIRY";
private static final String OKTA_AWS_CLI_PROFILE_PROPERTY = "OKTA_AWS_CLI_PROFILE";
private static final String OKTA_ORG_PROPERTY = "OKTA_ORG";

private final OktaAwsCliEnvironment environment;
private final CookieHelper cookieHelper;
Expand All @@ -39,6 +40,8 @@ public Optional<Session> getCurrentSession() throws IOException {
try (FileReader fileReader = new FileReader(getSessionPath().toFile())) {
Properties properties = new Properties();
properties.load(fileReader);
String oktaOrg = properties.getProperty(OKTA_ORG_PROPERTY);
if (oktaOrg != null && !oktaOrg.equals(environment.oktaOrg)) return Optional.empty();
String expiry = properties.getProperty(OKTA_AWS_CLI_EXPIRY_PROPERTY);
String profileName = properties.getProperty(OKTA_AWS_CLI_PROFILE_PROPERTY);
Instant expiryInstant = Instant.parse(expiry);
Expand Down Expand Up @@ -84,6 +87,7 @@ private void logoutMultipleAccounts(String profileName) throws IOException {

public void updateCurrentSession(Instant expiryInstant, String profileName) throws IOException {
Properties properties = new Properties();
properties.setProperty(OKTA_ORG_PROPERTY, environment.oktaOrg);
properties.setProperty(OKTA_AWS_CLI_PROFILE_PROPERTY, profileName);
properties.setProperty(OKTA_AWS_CLI_EXPIRY_PROPERTY, expiryInstant.toString());
properties.store(new FileWriter(getSessionPath().toString()), "Saved at: " + Instant.now().toString());
Expand Down