001/* 002 * #%L 003 * Netarchivesuite - harvester 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023 024package dk.netarkivet.harvester.datamodel; 025 026import dk.netarkivet.common.exceptions.ArgumentNotValid; 027import dk.netarkivet.common.utils.Named; 028 029/** 030 * Immutable password class. Represents a http credentials password. See RFC 2617: HTTP Authentication: Basic and Digest 031 * Access Authentication 032 */ 033 034public final class Password implements Named { 035 036 /** The name of the Password. Used for sorting. */ 037 private final String name; 038 /** Any comments given to the Password. */ 039 private final String comments; 040 /** The domain where this Password is used. */ 041 private final String passwordDomain; 042 /** 043 * The realm for this Password. Defines a specific protection space on a webserver. See RFC 2617, section 1.2 044 */ 045 private final String realm; 046 /** The username. */ 047 private final String username; 048 /** The password. */ 049 private final String password; 050 051 /** ID autogenerated by DB, ignored otherwise. */ 052 private Long id; 053 054 /** 055 * Create a new password object with the given information. 056 * 057 * @param name The name of the Password 058 * @param comments Any comments 059 * @param passwordDomain the domain where this Password is used 060 * @param realm the realm of the Password 061 * @param username the username 062 * @param password the password 063 */ 064 public Password(String name, String comments, String passwordDomain, String realm, String username, String password) { 065 ArgumentNotValid.checkNotNullOrEmpty(name, "name"); 066 ArgumentNotValid.checkNotNull(comments, "comments"); 067 ArgumentNotValid.checkNotNullOrEmpty(passwordDomain, "passwordDomain"); 068 ArgumentNotValid.checkNotNullOrEmpty(realm, "realm"); 069 ArgumentNotValid.checkNotNullOrEmpty(username, "username"); 070 ArgumentNotValid.checkNotNullOrEmpty(password, "password"); 071 072 this.name = name; 073 this.comments = comments; 074 this.passwordDomain = passwordDomain; 075 this.realm = realm; 076 this.username = username; 077 this.password = password; 078 } 079 080 /** 081 * @return the name of the Password 082 */ 083 public String getName() { 084 return name; 085 } 086 087 /** 088 * @return the comments for the Password 089 */ 090 public String getComments() { 091 return comments; 092 } 093 094 /** 095 * @return the domain for the Password 096 */ 097 public String getPasswordDomain() { 098 return passwordDomain; 099 } 100 101 /** 102 * @return the Realm for the Password 103 */ 104 public String getRealm() { 105 return realm; 106 } 107 108 /** 109 * @return the username. 110 */ 111 public String getUsername() { 112 return username; 113 } 114 115 /** 116 * @return the password. 117 */ 118 119 public String getPassword() { 120 return password; 121 } 122 123 /** 124 * Get the ID of this password. Only for use by DBDAO 125 * 126 * @return the ID of this password 127 */ 128 long getID() { 129 return id; 130 } 131 132 /** 133 * Set the ID of this password. Only for use by DBDAO. 134 * 135 * @param newid the new ID of this password 136 */ 137 void setID(long newid) { 138 this.id = newid; 139 } 140 141 /** 142 * Check if this password has an ID set yet (doesn't happen until the DBDAO persists it). 143 * 144 * @return true if this password has an ID set yet 145 */ 146 boolean hasID() { 147 return id != null; 148 } 149 150 /** 151 * equals method overriding Object#equals. Autogenerated code. 152 * 153 * @param o The object to compare with 154 * @return Whether they are equal 155 */ 156 public boolean equals(Object o) { 157 if (this == o) { 158 return true; 159 } 160 if (!(o instanceof Password)) { 161 return false; 162 } 163 164 final Password password1 = (Password) o; 165 166 if (comments != null ? !comments.equals(password1.comments) : password1.comments != null) { 167 return false; 168 } 169 if (name != null ? !name.equals(password1.name) : password1.name != null) { 170 return false; 171 } 172 if (password != null ? !password.equals(password1.password) : password1.password != null) { 173 return false; 174 } 175 if (passwordDomain != null ? !passwordDomain.equals(password1.passwordDomain) 176 : password1.passwordDomain != null) { 177 return false; 178 } 179 if (realm != null ? !realm.equals(password1.realm) : password1.realm != null) { 180 return false; 181 } 182 if (username != null ? !username.equals(password1.username) : password1.username != null) { 183 return false; 184 } 185 186 return true; 187 } 188 189 /** 190 * hashCode method overriding Object#hashCode. Autogenerated code. 191 * 192 * @return hashcode 193 */ 194 public int hashCode() { 195 int result; 196 result = (name != null ? name.hashCode() : 0); 197 result = 29 * result + (comments != null ? comments.hashCode() : 0); 198 result = 29 * result + (passwordDomain != null ? passwordDomain.hashCode() : 0); 199 result = 29 * result + (realm != null ? realm.hashCode() : 0); 200 result = 29 * result + (username != null ? username.hashCode() : 0); 201 result = 29 * result + (password != null ? password.hashCode() : 0); 202 return result; 203 } 204 205}