All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.launchkey.sdk.transport.v1.domain.PingResponse Maven / Gradle / Ivy

Go to download

SDK for interacting with the LaunchKey distributed authentication and authorization platform

There is a newer version: 4.0.0
Show newest version
/**
 * Copyright 2015 LaunchKey, Inc.  All rights reserved.
 *
 * Licensed under the MIT License.
 * You may not use this file except in compliance with the License.
 * A copy of the License is located in the "LICENSE.txt" file accompanying
 * this file. This file 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 com.launchkey.sdk.transport.v1.domain;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.text.ParseException;
import java.util.Date;

/**
 * Response data from a "ping" call
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class PingResponse {

    /**
     * When the public key was generated. Returned only if a key is returned.
     */
    private final Date dateStamp;

    /**
     * When the Ping response was generated by LaunchKey Engine.
     */
    private final Date apiTime;

    /**
     * RSA Public key string returned by the Ping call.
     */
    private final String publicKey;

    /**
     * Finger print of the public key in the response.
     */
    private String fingerprint;

    /**
     * @return When the public key was generated. Returned only if a key is returned.
     */
    @Deprecated
    public final Date getDateStamp() {
        return dateStamp;
    }

    /**
     * @return When the Ping response was generated by from Platform API.
     * @deprecated Use {@link #getApiTime()} instead
     */
    @Deprecated
    public final Date getLaunchKeyTime() {
        return apiTime;
    }

    /**
     * @return When the Ping response was generated by from Platform API.
     */
    public Date getApiTime() {
        return apiTime;
    }

    /**
     * Get the finger print of the public key in the response. Returned only if a key is returned.
     * @return
     */
    public String getFingerprint() {
        return fingerprint;
    }

    /**
     * @return RSA Public key string returned bye the Ping call.
     */
    public final String getPublicKey() {
        return publicKey;
    }

    /**
     * @param dateStamp When the public key was generated. Returned only if a key is returned.
     * @param launchKeyTime When the Ping response was generated by LaunchKey Engine.
     * @param publicKey RSA Public key string returned by the Ping call.
     * @throws ParseException when the dateStamp or apiTime are not valid LaunchKey Date/Times
     */
    public PingResponse(String dateStamp, String launchKeyTime, String publicKey) throws ParseException {
        this.dateStamp = PlatformDateFormat.getInstance().parseObject(dateStamp);
        this.apiTime = PlatformDateFormat.getInstance().parseObject(launchKeyTime);
        this.publicKey = publicKey;
    }

    /**
     * @param fingerprint Fingerprint of the Public Key
     * @param publicKey RSA Public key string returned by the Ping call.
     * @throws ParseException when the dateStamp or apiTime are not valid LaunchKey Date/Times
     */
    @JsonCreator
    public PingResponse(
            @JsonProperty("fingerprint") String fingerprint,
            @JsonProperty("api_time") Date apiTime,
            @JsonProperty("key") String publicKey
    ) throws ParseException {
        this.dateStamp = null;
        this.fingerprint = fingerprint;
        this.apiTime = apiTime;
        this.publicKey = publicKey;
    }

    @Override
    public String toString() {
        return "PingResponse{" +
                "fingerprint=" + fingerprint +
                ", apiTime=" + apiTime +
                ", publicKey='" + publicKey + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PingResponse)) return false;

        PingResponse that = (PingResponse) o;

        if (fingerprint != null ? !fingerprint.equals(that.fingerprint) : that.fingerprint != null) return false;
        if (apiTime != null ? !apiTime.equals(that.apiTime) : that.apiTime != null) return false;
        return !(publicKey != null ? !publicKey.equals(that.publicKey) : that.publicKey != null);

    }

    @Override
    public int hashCode() {
        int result = fingerprint != null ? fingerprint.hashCode() : 0;
        result = 31 * result + (apiTime != null ? apiTime.hashCode() : 0);
        result = 31 * result + (publicKey != null ? publicKey.hashCode() : 0);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy