Change Address model to be an interface. Will allow consuming projects

to override this funcitonality more easily.
pull/908/merge
Tony Fendall 2015-08-28 11:03:01 +12:00 committed by Justin Richer
parent c4726b09f0
commit f43c94314c
3 changed files with 262 additions and 179 deletions

View File

@ -18,219 +18,66 @@ package org.mitre.openid.connect.model;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="address")
public class Address implements Serializable {
private static final long serialVersionUID = -1304880008685206811L;
private Long id;
private String formatted;
private String streetAddress;
private String locality;
private String region;
private String postalCode;
private String country;
public interface Address extends Serializable {
/**
* Empty constructor
* @return the formatted address
*/
public Address() {
}
/**
* @return the formatted address string
*/
@Basic
@Column(name = "formatted")
public String getFormatted() {
return formatted;
}
public String getFormatted();
/**
* @param formatted the formatted address to set
*/
public void setFormatted(String formatted) {
this.formatted = formatted;
}
public void setFormatted(String formatted);
/**
* @return the streetAddress
*/
@Basic
@Column(name="street_address")
public String getStreetAddress() {
return streetAddress;
}
public String getStreetAddress();
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public void setStreetAddress(String streetAddress);
/**
* @return the locality
*/
@Basic
@Column(name = "locality")
public String getLocality() {
return locality;
}
public String getLocality();
/**
* @param locality the locality to set
*/
public void setLocality(String locality) {
this.locality = locality;
}
public void setLocality(String locality);
/**
* @return the region
*/
@Basic
@Column(name = "region")
public String getRegion() {
return region;
}
public String getRegion();
/**
* @param region the region to set
*/
public void setRegion(String region) {
this.region = region;
}
public void setRegion(String region);
/**
* @return the postalCode
*/
@Basic
@Column(name="postal_code")
public String getPostalCode() {
return postalCode;
}
public String getPostalCode();
/**
* @param postalCode the postalCode to set
*/
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public void setPostalCode(String postalCode);
/**
* @return the country
*/
@Basic
@Column(name = "country")
public String getCountry() {
return country;
}
public String getCountry();
/**
* @param country the country to set
*/
public void setCountry(String country) {
this.country = country;
}
/**
* @return the id
*/
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((formatted == null) ? 0 : formatted.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((locality == null) ? 0 : locality.hashCode());
result = prime * result + ((postalCode == null) ? 0 : postalCode.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode());
result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Address)) {
return false;
}
Address other = (Address) obj;
if (country == null) {
if (other.country != null) {
return false;
}
} else if (!country.equals(other.country)) {
return false;
}
if (formatted == null) {
if (other.formatted != null) {
return false;
}
} else if (!formatted.equals(other.formatted)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (locality == null) {
if (other.locality != null) {
return false;
}
} else if (!locality.equals(other.locality)) {
return false;
}
if (postalCode == null) {
if (other.postalCode != null) {
return false;
}
} else if (!postalCode.equals(other.postalCode)) {
return false;
}
if (region == null) {
if (other.region != null) {
return false;
}
} else if (!region.equals(other.region)) {
return false;
}
if (streetAddress == null) {
if (other.streetAddress != null) {
return false;
}
} else if (!streetAddress.equals(other.streetAddress)) {
return false;
}
return true;
}
public void setCountry(String country);
}

View File

@ -0,0 +1,236 @@
/*******************************************************************************
* Copyright 2015 The MITRE Corporation
* and the MIT Kerberos and Internet Trust Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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 org.mitre.openid.connect.model;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="address")
public class DefaultAddress implements Address {
private static final long serialVersionUID = -1304880008685206811L;
private Long id;
private String formatted;
private String streetAddress;
private String locality;
private String region;
private String postalCode;
private String country;
/**
* Empty constructor
*/
public DefaultAddress() {
}
/**
* @return the formatted address string
*/
@Basic
@Column(name = "formatted")
public String getFormatted() {
return formatted;
}
/**
* @param formatted the formatted address to set
*/
public void setFormatted(String formatted) {
this.formatted = formatted;
}
/**
* @return the streetAddress
*/
@Basic
@Column(name="street_address")
public String getStreetAddress() {
return streetAddress;
}
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @return the locality
*/
@Basic
@Column(name = "locality")
public String getLocality() {
return locality;
}
/**
* @param locality the locality to set
*/
public void setLocality(String locality) {
this.locality = locality;
}
/**
* @return the region
*/
@Basic
@Column(name = "region")
public String getRegion() {
return region;
}
/**
* @param region the region to set
*/
public void setRegion(String region) {
this.region = region;
}
/**
* @return the postalCode
*/
@Basic
@Column(name="postal_code")
public String getPostalCode() {
return postalCode;
}
/**
* @param postalCode the postalCode to set
*/
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
/**
* @return the country
*/
@Basic
@Column(name = "country")
public String getCountry() {
return country;
}
/**
* @param country the country to set
*/
public void setCountry(String country) {
this.country = country;
}
/**
* @return the id
*/
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((formatted == null) ? 0 : formatted.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((locality == null) ? 0 : locality.hashCode());
result = prime * result + ((postalCode == null) ? 0 : postalCode.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode());
result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DefaultAddress)) {
return false;
}
DefaultAddress other = (DefaultAddress) obj;
if (country == null) {
if (other.country != null) {
return false;
}
} else if (!country.equals(other.country)) {
return false;
}
if (formatted == null) {
if (other.formatted != null) {
return false;
}
} else if (!formatted.equals(other.formatted)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (locality == null) {
if (other.locality != null) {
return false;
}
} else if (!locality.equals(other.locality)) {
return false;
}
if (postalCode == null) {
if (other.postalCode != null) {
return false;
}
} else if (!postalCode.equals(other.postalCode)) {
return false;
}
if (region == null) {
if (other.region != null) {
return false;
}
} else if (!region.equals(other.region)) {
return false;
}
if (streetAddress == null) {
if (other.streetAddress != null) {
return false;
}
} else if (!streetAddress.equals(other.streetAddress)) {
return false;
}
return true;
}
}

View File

@ -495,7 +495,7 @@ public class DefaultUserInfo implements UserInfo {
if (obj.has("address") && obj.get("address").isJsonObject()) {
JsonObject addr = obj.get("address").getAsJsonObject();
ui.setAddress(new Address());
ui.setAddress(new DefaultAddress());
ui.getAddress().setFormatted(nullSafeGetString(addr, "formatted"));
ui.getAddress().setStreetAddress(nullSafeGetString(addr, "street_address"));