Skip to content

Commit

Permalink
Fixed authentication issue
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaellondner-okta committed Nov 1, 2016
1 parent 6c76cf2 commit a5fdcae
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/main/java/com/okta/tools/awscli.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ private static String oktaAuthntication() throws ClientProtocolException, JSONEx
oktaPassword = new String(console.readPassword("Password: "));
} else { // hack to be able to debug in an IDE
System.out.print("Password: ");
oktaUsername = "john";

oktaPassword = scanner.next();
oktaPassword = "ctkQesDGLULiVyFPVFxuCfLzWX(7";
}

responseAuthenticate = authnticateCredentials(oktaUsername, oktaPassword);
Expand Down Expand Up @@ -413,9 +411,7 @@ private static AssumeRoleWithSAMLResult assumeAWSRole(String resultSAML) {

//use user credentials to assume AWS role
AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(awsCreds);




AssumeRoleWithSAMLRequest assumeRequest = new AssumeRoleWithSAMLRequest()
.withPrincipalArn(principalArn)
.withRoleArn(roleArn)
Expand Down Expand Up @@ -452,6 +448,12 @@ private static void GetRoleToAssume(String roleName) {
}
if (managedPolicies.size() >= 1) //we prioritize managed policies over inline policies
{
List<String> lstManagedPolicies = new ArrayList<String>();

for (AttachedPolicy managedPolicy: managedPolicies) {
lstManagedPolicies.add(managedPolicy.getPolicyName());
}

logger.debug("Managed Policies: " + managedPolicies.toString());
//TODO: handle more than 1 policy (ask the user to choose it?)
AttachedPolicy attachedPolicy = managedPolicies.get(0);
Expand Down Expand Up @@ -488,6 +490,26 @@ else if (inlinePolicies.size() >= 1) //if we only have one policy, then use it b
}


private static String SelectPolicy(List<String> lstPolicies) {
String strSelectedPolicy = null;

System.out.println("\nPlease select a policy: ");

//Gather list of policies for the selected role
int i = 1;
for (String strPolicyName: lstPolicies)
{
System.out.println("[ " + i + " ]: " + strPolicyName);
i++;
}


//Prompt user for policy selection
int selection = numSelection(lstPolicies.size());

return strSelectedPolicy;
}

private static String ProcessPolicyDocument(String policyDoc) {

String strRoleToAssume = null;
Expand Down

0 comments on commit a5fdcae

Please sign in to comment.