Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public String toJson() {
return new StringBuffer("{")
.append(Utils.toJsonString("AccountId", this.AccountId, false))
.append(Utils.toJsonString("SystemId", this.AssetId, true))
.append(Utils.toJsonString("AccessRequestType", this.AccessType == null ? null : this.AccessType.name(), true))
.append(Utils.toJsonString("AccessRequestType", this.AccessType == null ? null : this.AccessType.toString(), true))
.append(Utils.toJsonString("IsEmergency", this.IsEmergency, true))
.append(Utils.toJsonString("ReasonCodeId", this.ReasonCodeId, true))
.append(Utils.toJsonString("ReasonComment", this.ReasonComment, true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ public enum BrokeredAccessRequestType
/**
* Access request is for a password.
*/
Password,
Password ("Password"),
/**
* Access request is for an SSH session.
*/
Ssh,
Ssh ("SSH"),
/**
* Access request is for a remote desktop session.
*/
Rdp
Rdp ("RemoteDesktop");

private final String name;

private BrokeredAccessRequestType(String s) {
name = s;
}

public boolean equalsName (String otherName) {
return name.equals(otherName);
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oneidentity.safeguard.safeguardjava.SafeguardForPrivilegedSessions;
import com.oneidentity.safeguard.safeguardjava.data.A2ARetrievableAccount;
import com.oneidentity.safeguard.safeguardjava.data.BrokeredAccessRequest;
import com.oneidentity.safeguard.safeguardjava.data.BrokeredAccessRequestType;
import com.oneidentity.safeguard.safeguardjava.data.FullResponse;
import com.oneidentity.safeguard.safeguardjava.data.KeyFormat;
import com.oneidentity.safeguard.safeguardjava.data.Method;
Expand Down Expand Up @@ -310,40 +311,51 @@ public void safeguardTestA2AContext(ISafeguardA2AContext a2aContext) {
return;
}

boolean passwordRelease = readLine("Password or Private Key(p/k): ", "p").equalsIgnoreCase("p");
String apiKey = readLine("API Key: ", null);

try {
if (passwordRelease) {
String password = new String(a2aContext.retrievePassword(apiKey.toCharArray()));
System.out.println(String.format("\tSuccessful password release"));
}
else {
String key = new String(a2aContext.retrievePrivateKey(apiKey.toCharArray(), KeyFormat.OpenSsh));
System.out.println(String.format("\tSuccessful private key release"));
}

List<A2ARetrievableAccount> registrations = a2aContext.getRetrievableAccounts();
System.out.println(String.format("\tRetrievable accounts:"));
for (A2ARetrievableAccount reg : registrations) {
System.out.println(String.format("\t\t%d %s %s", reg.getAccountId(), reg.getAccountName(), reg.getAccountDescription()));
if (readLine("Test Credential Retrieval(y/n): ", "y").equalsIgnoreCase("y")) {
boolean passwordRelease = readLine("Password or Private Key(p/k): ", "p").equalsIgnoreCase("p");
String apiKey = readLine("API Key: ", null);

try {
if (passwordRelease) {
String password = new String(a2aContext.retrievePassword(apiKey.toCharArray()));
System.out.println(String.format("\tSuccessful password release"));
}
else {
String key = new String(a2aContext.retrievePrivateKey(apiKey.toCharArray(), KeyFormat.OpenSsh));
System.out.println(String.format("\tSuccessful private key release"));
}

List<A2ARetrievableAccount> registrations = a2aContext.getRetrievableAccounts();
System.out.println(String.format("\tRetrievable accounts:"));
for (A2ARetrievableAccount reg : registrations) {
System.out.println(String.format("\t\t%d %s %s", reg.getAccountId(), reg.getAccountName(), reg.getAccountDescription()));
}
} catch (ArgumentException | ObjectDisposedException | SafeguardForJavaException ex) {
System.out.println("\t[ERROR]Test connection failed: " + ex.getMessage());
}
}

if (readLine("Test Access Request Broker(y/n): ", "y").equalsIgnoreCase("y")) {
String accountId = readLine("Account Id: ", null);
String assetId = readLine("Asset Id:", null);
String forUserId = readLine("For User Id:", null);
apiKey = readLine("Api Key: ", null);
String accessRequestType = readLine("Access Request Type((p)assword/(s)sh/(r)dp): ", "p");
String apiKey = readLine("Api Key: ", null);

BrokeredAccessRequest accessRequest = new BrokeredAccessRequest();
accessRequest.setAccountId(Integer.parseInt(accountId));
accessRequest.setForUserId(Integer.parseInt(forUserId));
accessRequest.setAssetId(Integer.parseInt(assetId));
a2aContext.brokerAccessRequest(apiKey.toCharArray(), accessRequest);

} catch (ObjectDisposedException | SafeguardForJavaException ex) {
System.out.println("\t[ERROR]Test connection failed: " + ex.getMessage());
} catch (Exception ex) {
System.out.println("\t[ERROR]Test connection failed: " + ex.getMessage());
try {
BrokeredAccessRequest accessRequest = new BrokeredAccessRequest();
accessRequest.setAccountId(Integer.parseInt(accountId));
accessRequest.setForUserId(Integer.parseInt(forUserId));
accessRequest.setAssetId(Integer.parseInt(assetId));
accessRequest.setAccessType(accessRequestType.toLowerCase().equals("p") ? BrokeredAccessRequestType.Password
: accessRequestType.toLowerCase().equals("s") ? BrokeredAccessRequestType.Ssh
: BrokeredAccessRequestType.Rdp);
String result = a2aContext.brokerAccessRequest(apiKey.toCharArray(), accessRequest);

System.out.println(result);
} catch (ArgumentException | ObjectDisposedException | SafeguardForJavaException | NumberFormatException ex) {
System.out.println("\t[ERROR]Test connection failed: " + ex.getMessage());
}
}
}

Expand Down