001package com.identityworksllc.iiq.common.task.export;
002
003import lombok.Getter;
004import lombok.Setter;
005
006import java.io.Serializable;
007import java.util.Objects;
008import java.util.Properties;
009
010/**
011 * A record / vo class used to pass connection info to the export partition. Your driver
012 * should already have been registered here.
013 */
014@Getter
015@Setter
016public final class ExportConnectionInfo implements Serializable {
017    /**
018     * The driver class (currently not used)
019     */
020    private String driver;
021    /**
022     * The encrypted password - will fail if not encrypted
023     */
024    private String encryptedPassword;
025    /**
026     * JDBC network timeout
027     */
028    private long networkTimeout;
029    /**
030     * Any additional driver options, unique per driver
031     */
032    private Properties options;
033
034    /**
035     * The JDBC URL string
036     */
037    private String url;
038
039    /**
040     * The username to connect
041     */
042    private String username;
043
044    /**
045     * Construct an empty connection info
046     */
047    public ExportConnectionInfo() {
048        this.options = new Properties();
049    }
050
051    /**
052     * Construct a connection info with the given URL, username, and password
053     * @param url The URL
054     * @param username The username
055     * @param encryptedPassword The encrypted password
056     */
057    public ExportConnectionInfo(String url, String username, String encryptedPassword) {
058        this();
059
060        if (!Objects.requireNonNull(encryptedPassword, "encryptedPassword").contains(":ACP:")) {
061            throw new IllegalArgumentException("The password must in IIQ encrypted format");
062        }
063
064        this.url = Objects.requireNonNull(url, "url");
065        this.username = Objects.requireNonNull(username, "username");
066        this.encryptedPassword = encryptedPassword;
067    }
068
069    /**
070     * Construct a connection info with the given URL, username, and password
071     * @param url The URL
072     * @param username The username
073     * @param encryptedPassword The encrypted password
074     * @param options The driver-specific connection options
075     */
076    public ExportConnectionInfo(String url, String username, String encryptedPassword, Properties options) {
077        this();
078
079        if (!Objects.requireNonNull(encryptedPassword, "encryptedPassword").contains(":ACP:")) {
080            throw new IllegalArgumentException("The password must in IIQ encrypted format");
081        }
082
083        this.url = Objects.requireNonNull(url, "url");
084        this.username = Objects.requireNonNull(username, "username");
085        this.encryptedPassword = encryptedPassword;
086        this.options = options;
087    }
088
089    @Override
090    public boolean equals(Object o) {
091        if (this == o) return true;
092        if (o == null || getClass() != o.getClass()) return false;
093        ExportConnectionInfo that = (ExportConnectionInfo) o;
094        return Objects.equals(driver, that.driver) && Objects.equals(encryptedPassword, that.encryptedPassword) && Objects.equals(options, that.options) && Objects.equals(url, that.url) && Objects.equals(username, that.username);
095    }
096
097    @Override
098    public int hashCode() {
099        return Objects.hash(driver, encryptedPassword, options, url, username);
100    }
101
102}