Skip to content
Open
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
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.pingidentity.developer</groupId>
<artifactId>pingid-api-playground</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<version>1.0.1</version>
<name>pingid-api-playground</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand All @@ -20,6 +20,16 @@
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
66 changes: 46 additions & 20 deletions src/main/java/com/pingidentity/developer/pingid/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

Expand All @@ -16,14 +18,17 @@
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.keys.HmacKey;
import org.jose4j.lang.JoseException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import com.pingidentity.developer.pingid.User;


public class Operation {


private static final String ENDPOINT_BASE = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/";

private String name;
private String endpoint;
private String requestToken;
Expand All @@ -47,7 +52,7 @@ public class Operation {
private String clientData;
private User user;

private final String apiVersion = "4.6";
private final String apiVersion = "4.9";

public Operation() {
}
Expand Down Expand Up @@ -86,7 +91,7 @@ public Operation(String orgAlias, String token, String useBase64Key) {
public void AddUser(Boolean activateUser) {

this.name = "AddUser";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/adduser/do";
this.endpoint = ENDPOINT_BASE + "adduser/do";

JSONObject reqBody = new JSONObject();
reqBody.put("activateUser", activateUser);
Expand All @@ -111,7 +116,7 @@ public void AddUser(Boolean activateUser) {
public void EditUser(Boolean activateUser) {

this.name = "EditUser";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/edituser/do";
this.endpoint = ENDPOINT_BASE + "edituser/do";

JSONObject reqBody = new JSONObject();
reqBody.put("activateUser", activateUser);
Expand All @@ -136,7 +141,7 @@ public void EditUser(Boolean activateUser) {
public void GetUserDetails() {

this.name = "GetUserDetails";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/getuserdetails/do";
this.endpoint = ENDPOINT_BASE + "getuserdetails/do";

JSONObject reqBody = new JSONObject();
reqBody.put("getSameDeviceUsers", false);
Expand All @@ -152,15 +157,26 @@ public void GetUserDetails() {
JSONObject userDetails = (JSONObject)response.get("userDetails");
this.user = new User(userDetails);

DeviceDetails deviceDetails = new DeviceDetails((JSONObject)userDetails.get("deviceDetails"));
DeviceDetails deviceDetails = new DeviceDetails();
List<DeviceDetails> devices = new ArrayList<DeviceDetails>();
if(userDetails != null) {
JSONArray devicesArray = (JSONArray)userDetails.get("devicesDetails");
if(devicesArray != null) {
for(int i = 0; i < devicesArray.size(); i++) {
devices.add(new DeviceDetails((JSONObject)devicesArray.get(i)));
}
}
deviceDetails = new DeviceDetails((JSONObject)userDetails.get("deviceDetails"));
}
this.user.setDeviceDetails(deviceDetails);
this.user.setDevices(devices);
}

@SuppressWarnings("unchecked")
public void DeleteUser() {

this.name = "DeleteUser";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/deleteuser/do";
this.endpoint = ENDPOINT_BASE + "deleteuser/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
Expand All @@ -177,7 +193,7 @@ public void DeleteUser() {
public void SuspendUser() {

this.name = "SuspendUser";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/suspenduser/do";
this.endpoint = ENDPOINT_BASE + "suspenduser/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
Expand All @@ -194,7 +210,7 @@ public void SuspendUser() {
public void ActivateUser() {

this.name = "ActivateUser";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/activateuser/do";
this.endpoint = ENDPOINT_BASE + "activateuser/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
Expand All @@ -211,7 +227,7 @@ public void ActivateUser() {
public void ToggleUserBypass(long until) {

this.name = "ToggleUserBypass";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/userbypass/do";
this.endpoint = ENDPOINT_BASE + "userbypass/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
Expand All @@ -226,15 +242,18 @@ public void ToggleUserBypass(long until) {
}

@SuppressWarnings("unchecked")
public void UnpairDevice() {
public void UnpairDevice(long deviceId) {

this.name = "UnpairDevice";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/unpairdevice/do";
this.endpoint = ENDPOINT_BASE + "unpairdevice/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
reqBody.put("clientData", this.clientData);

if(deviceId > 0)
reqBody.put("deviceId", deviceId);

this.requestToken = buildRequestToken(reqBody);

sendRequest();
Expand All @@ -246,7 +265,7 @@ public void UnpairDevice() {
public void GetPairingStatus(String activationCode) {

this.name = "GetPairingStatus";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/pairingstatus/do";
this.endpoint = ENDPOINT_BASE + "pairingstatus/do";

JSONObject reqBody = new JSONObject();
reqBody.put("activationCode", activationCode);
Expand All @@ -264,7 +283,7 @@ public void GetPairingStatus(String activationCode) {
public void PairYubiKey(String otp) {

this.name = "PairYubiKey";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/pairyubikey/do";
this.endpoint = ENDPOINT_BASE + "pairyubikey/do";

JSONObject reqBody = new JSONObject();
reqBody.put("otp", otp);
Expand All @@ -282,7 +301,7 @@ public void PairYubiKey(String otp) {
public void StartOfflinePairing(OfflinePairingMethod pairingMethod) {

this.name = "StartOfflinePairing";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/startofflinepairing/do";
this.endpoint = ENDPOINT_BASE + "startofflinepairing/do";

JSONObject reqBody = new JSONObject();

Expand Down Expand Up @@ -311,7 +330,7 @@ public void StartOfflinePairing(OfflinePairingMethod pairingMethod) {
public void FinalizeOfflinePairing(String sessionId, String otp) {

this.name = "FinalizeOfflinePairing";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/finalizeofflinepairing/do";
this.endpoint = ENDPOINT_BASE + "finalizeofflinepairing/do";

JSONObject reqBody = new JSONObject();
reqBody.put("otp", otp);
Expand All @@ -329,7 +348,7 @@ public void FinalizeOfflinePairing(String sessionId, String otp) {
public void GetActivationCode() {

this.name = "GetActivationCode";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/getactivationcode/do";
this.endpoint = ENDPOINT_BASE + "getactivationcode/do";

JSONObject reqBody = new JSONObject();
reqBody.put("userName", this.user.getUserName());
Expand All @@ -342,19 +361,26 @@ public void GetActivationCode() {
values.clear();
this.lastActivationCode = (String)response.get("activationCode");
}

public void AuthenticateOnline(Application application, String authType) {
AuthenticateOnline(application, authType, 0);
}

@SuppressWarnings("unchecked")
public void AuthenticateOnline(Application application, String authType) {
public void AuthenticateOnline(Application application, String authType, long deviceId) {

this.name = "AuthenticateOnline";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/authonline/do";
this.endpoint = ENDPOINT_BASE + "authonline/do";

JSONObject reqBody = new JSONObject();
reqBody.put("authType", authType);
reqBody.put("spAlias", application.getSpAlias());
reqBody.put("userName", this.user.getUserName());
reqBody.put("clientData", this.clientData);

if(deviceId > 0)
reqBody.put("deviceId", deviceId);

JSONObject formParameters = new JSONObject();
formParameters.put("sp_name", application.getName());
if (application.getLogoUrl() != null || !application.getLogoUrl().isEmpty()) {
Expand All @@ -378,7 +404,7 @@ public void AuthenticateOnline(Application application, String authType) {
public void AuthenticateOffline(String sessionId, String otp) {

this.name = "AuthenticateOffline";
this.endpoint = "https://idpxnyl3m.pingidentity.com/pingid/rest/4/authoffline/do";
this.endpoint = ENDPOINT_BASE + "authoffline/do";

JSONObject reqBody = new JSONObject();
reqBody.put("spAlias", "web");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/pingidentity/developer/pingid/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

Expand All @@ -20,6 +21,7 @@ public class User {

private String phoneNumber;
private DeviceDetails deviceDetails;
private List<DeviceDetails> devices;

private Date lastAuthentication;
private Boolean enabled;
Expand Down Expand Up @@ -106,6 +108,7 @@ public User(JSONObject userDetailsJSON) {
public UserStatus getStatus() { return this.status; }
public Date getBypassedUntil(String spAlias) { return this.bypassInfo.get(spAlias); }
public Date getLastAuthentication() { return this.lastAuthentication; }
public List<DeviceDetails> getDevices() { return devices; }

public void setUserName(String userName) { this.userName = userName; }
public void setFirstName(String firstName) { this.fName = firstName; }
Expand All @@ -114,6 +117,7 @@ public User(JSONObject userDetailsJSON) {
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
public void setRole(UserRole role) { this.role = role; }
public void setDeviceDetails(DeviceDetails deviceDetails) { this.deviceDetails = deviceDetails; }
public void setDevices(List<DeviceDetails> devices) { this.devices = devices; }

@SuppressWarnings("unused")
private Date parseDate(String dateToParse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import com.cedarsoftware.util.io.JsonWriter;
import com.pingidentity.developer.pingid.Application;
import com.pingidentity.developer.pingid.OfflinePairingMethod;
import com.pingidentity.developer.pingid.User;
import com.pingidentity.developer.pingid.Operation;
import com.pingidentity.developer.pingid.User;

public class APIHandlerServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String requestedOperation = request.getParameter("operation");
Expand All @@ -28,13 +30,17 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
Operation operation = new Operation((String)session.getAttribute("pingid_org_alias"), (String)session.getAttribute("pingid_token"), (String)session.getAttribute("pingid_use_base64_key"));;
operation.setTargetUser(targetUsername);

String deviceIdObject = (String)request.getParameter("deviceId");
long deviceId = deviceIdObject != null && !deviceIdObject.isEmpty() ? Long.parseLong(deviceIdObject) : 0;

switch (requestedOperation) {

case "AuthenticateOnline":
Application app = new Application(request.getParameter("applicationName"));
app.setLogoUrl(request.getParameter("applicationIconUrl"));
app.setSpAlias("web");
operation.AuthenticateOnline(app, request.getParameter("authType"));

operation.AuthenticateOnline(app, request.getParameter("authType"), deviceId);
request.setAttribute("lastSessionId", operation.getLastSessionId());
break;

Expand Down Expand Up @@ -139,7 +145,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
break;

case "UnpairDevice":
operation.UnpairDevice();
operation.UnpairDevice(deviceId);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.RequestDispatcher;
Expand All @@ -16,12 +15,12 @@
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;
import org.apache.commons.io.IOUtils;


public class PropertiesFileUploadServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

if (ServletFileUpload.isMultipartContent(request)) {
Expand All @@ -32,7 +31,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)

while(fii.hasNext()) {
FileItemStream item = fii.next();
String name = item.getFieldName();
InputStream is = item.openStream();

if (item.isFormField()) {
Expand Down
Loading