It deploys! Finished adding persistence annotations to the model setup we have so far. Added IdToken.java, which extends JWT and uses an IdTokenClaims as its JWT.claims object.

pull/59/head
Amanda Anganes 2012-01-12 12:49:21 -05:00
parent 6cce82f484
commit b47d22e0fd
8 changed files with 202 additions and 160 deletions

View File

@ -270,6 +270,11 @@ public class ClientDetailsEntity implements ClientDetails {
/**
* @return the resourceIds
*/
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name="resource_ids",
joinColumns=@JoinColumn(name="owner_id")
)
public Set<String> getResourceIds() {
return resourceIds;
}
@ -277,11 +282,6 @@ public class ClientDetailsEntity implements ClientDetails {
/**
* @param resourceIds the resourceIds to set
*/
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name="resource_ids",
joinColumns=@JoinColumn(name="owner_id")
)
public void setResourceIds(Set<String> resourceIds) {
this.resourceIds = resourceIds;
}

View File

@ -9,26 +9,13 @@ import javax.persistence.Id;
@Entity
public class Address {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Basic
private String formatted;
@Basic
private String street_address;
@Basic
private String streetAddress;
private String locality;
@Basic
private String region;
@Basic
private String postal_code;
@Basic
private String postalCode;
private String country;
/**
@ -41,6 +28,7 @@ public class Address {
/**
* @return the formatted address string
*/
@Basic
public String getFormatted() {
return formatted;
}
@ -51,20 +39,22 @@ public class Address {
this.formatted = formatted;
}
/**
* @return the street_address
* @return the streetAddress
*/
public String getStreet_address() {
return street_address;
@Basic
public String getStreetAddress() {
return streetAddress;
}
/**
* @param street_address the street_address to set
* @param streetAddress the streetAddress to set
*/
public void setStreet_address(String street_address) {
this.street_address = street_address;
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @return the locality
*/
@Basic
public String getLocality() {
return locality;
}
@ -77,6 +67,7 @@ public class Address {
/**
* @return the region
*/
@Basic
public String getRegion() {
return region;
}
@ -87,20 +78,22 @@ public class Address {
this.region = region;
}
/**
* @return the postal_code
* @return the postalCode
*/
public String getPostal_code() {
return postal_code;
@Basic
public String getPostalCode() {
return postalCode;
}
/**
* @param postal_code the postal_code to set
* @param postalCode the postalCode to set
*/
public void setPostal_code(String postal_code) {
this.postal_code = postal_code;
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
/**
* @return the country
*/
@Basic
public String getCountry() {
return country;
}

View File

@ -1,57 +1,55 @@
package org.mitre.openid.connect.model;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.mitre.oauth2.model.ClientDetailsEntity;
@Entity
@Table(name="approvedsite")
@NamedQueries({
@NamedQuery(name = "ApprovedSite.getAll", query = "select a from ApprovedSite a"),
@NamedQuery(name = "ApprovedSite.getByUserInfo", query = "select a from ApprovedSite a if a.userInfo = :approvedSiteUserInfo"),
@NamedQuery(name = "ApprovedSite.getByClientDetails", query = "select a from approvedSite if a.clientDetails = :approvedSiteClientDetails")
})
public class ApprovedSite {
// unique id
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
// which user made the approval
@ManyToOne
@JoinColumn(name="userinfo_id")
private UserInfo userInfo;
// which OAuth2 client is this tied to
@ManyToOne
@JoinColumn(name="clientdetails_id")
private ClientDetails clientDetails;
private ClientDetailsEntity clientDetails;
// when was this first approved?
@Temporal(TemporalType.DATE)
private Date creationDate;
// when was this last accessed?
@Temporal(TemporalType.DATE)
private Date accessDate;
// if this is a time-limited access, when does it run out?
@Temporal(TemporalType.DATE)
private Date timeoutDate;
// what scopes have been allowed
// this should include all information for what data to access
@OneToMany(mappedBy = "approvedsite")
private Collection<String> allowedScopes;
private Set<String> allowedScopes;
// TODO: should we store the OAuth2 tokens and IdTokens here?
@ -82,6 +80,7 @@ public class ApprovedSite {
* @return the userInfo
*/
@ManyToOne
@JoinColumn(name="userinfo_id")
public UserInfo getUserInfo() {
return userInfo;
}
@ -96,14 +95,16 @@ public class ApprovedSite {
/**
* @return the clientDetails
*/
public ClientDetails getClientDetails() {
@ManyToOne
@JoinColumn(name="clientdetails_id")
public ClientDetailsEntity getClientDetails() {
return clientDetails;
}
/**
* @param clientDetails the clientDetails to set
*/
public void setClientDetails(ClientDetails clientDetails) {
public void setClientDetails(ClientDetailsEntity clientDetails) {
this.clientDetails = clientDetails;
}
@ -142,15 +143,15 @@ public class ApprovedSite {
/**
* @return the allowedScopes
*/
@OneToMany
public Collection<String> getAllowedScopes() {
@ElementCollection(fetch = FetchType.EAGER)
public Set<String> getAllowedScopes() {
return allowedScopes;
}
/**
* @param allowedScopes the allowedScopes to set
*/
public void setAllowedScopes(Collection<String> allowedScopes) {
public void setAllowedScopes(Set<String> allowedScopes) {
this.allowedScopes = allowedScopes;
}

View File

@ -7,6 +7,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
/**
@ -17,6 +18,7 @@ import javax.persistence.Temporal;
*/
@Entity
@Table(name="event")
public class Event {
public static enum EventType { LOGIN, AUTHORIZATION, ACCESS }

View File

@ -0,0 +1,56 @@
package org.mitre.openid.connect.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.mitre.jwt.model.Jwt;
@Entity
@Table(name="idtoken")
@NamedQueries({
@NamedQuery(name = "IdToken.getAll", query = "select i from IdToken i")
})
public class IdToken extends Jwt {
private Long id;
/**
* @return the id
*/
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the tokenClaims
*/
@Transient
public IdTokenClaims getTokenClaims() {
return (IdTokenClaims) super.getClaims();
}
/**
* @param tokenClaims the tokenClaims to set
*/
public void setTokenClaims(IdTokenClaims tokenClaims) {
super.setClaims(tokenClaims);
}
}

View File

@ -6,14 +6,14 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.mitre.jwt.model.Jwt;
import org.mitre.jwt.model.JwtClaims;
/*
* TODO: This class needs to be encoded as a JWT
*/
@Entity
@Table(name="idtokenclaims")
public class IdTokenClaims extends JwtClaims {
public static final String USER_ID = "user_id";
@ -38,7 +38,7 @@ public class IdTokenClaims extends JwtClaims {
this.id = id;
}
@Transient
public String getUserId() {
return getClaimAsString(USER_ID);
}
@ -47,7 +47,7 @@ public class IdTokenClaims extends JwtClaims {
setClaim(USER_ID, user_id);
}
@Transient
public String getAuthContext() {
return getClaimAsString(AUTHENTICATION_CONTEXT_CLASS_REFERENCE);
}
@ -56,7 +56,7 @@ public class IdTokenClaims extends JwtClaims {
setClaim(AUTHENTICATION_CONTEXT_CLASS_REFERENCE, acr);
}
@Transient
public String getNonce() {
return getClaimAsString(NONCE);
}
@ -65,7 +65,7 @@ public class IdTokenClaims extends JwtClaims {
setClaim(NONCE, nonce);
}
@Transient
public Date getAuthTime() {
return getClaimAsDate(AUTH_TIME);
}

View File

@ -2,86 +2,55 @@ package org.mitre.openid.connect.model;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="userinfo")
@NamedQueries({
@NamedQuery(name="UserInfo.getAll", query = "select u from UserInfo u")
})
public class UserInfo {
// unique object id for persistence
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
// TODO: underbars are awkward in java, should we switch all this to camel case and put in underbars in the serialization view?
@Basic
private String user_id;
@Basic
private String userId;
private String name;
@Basic
private String given_name;
@Basic
private String family_name;
@Basic
private String middle_name;
@Basic
private String givenName;
private String familyName;
private String middleName;
private String nickname;
@Basic
private String profile;
@Basic
private String picture;
@Basic
private String website;
@Basic
private String email;
@Basic
private Boolean verified;
@Basic
private String gender;
@Basic
private String zoneinfo;
@Basic
private String locale;
@Basic
private String phone_number;
@OneToOne
private String phoneNumber;
private Address address;
@Basic
private String updated_time;
private String updatedTime;
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the user_id
* @return the userId
*/
@Id
public String getUser_id() {
return user_id;
public String getUserId() {
return userId;
}
/**
* @param user_id the user_id to set
* @param userId the userId to set
*/
public void setUser_id(String user_id) {
this.user_id = user_id;
public void setUserId(String userId) {
this.userId = userId;
}
/**
* @return the name
*/
@Basic
public String getName() {
return name;
}
@ -92,44 +61,48 @@ public class UserInfo {
this.name = name;
}
/**
* @return the given_name
* @return the givenName
*/
public String getGiven_name() {
return given_name;
@Basic
public String getGivenName() {
return givenName;
}
/**
* @param given_name the given_name to set
* @param givenName the givenName to set
*/
public void setGiven_name(String given_name) {
this.given_name = given_name;
public void setGivenName(String givenName) {
this.givenName = givenName;
}
/**
* @return the family_name
* @return the familyName
*/
public String getFamily_name() {
return family_name;
@Basic
public String getFamilyName() {
return familyName;
}
/**
* @param family_name the family_name to set
* @param familyName the familyName to set
*/
public void setFamily_name(String family_name) {
this.family_name = family_name;
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
/**
* @return the middle_name
* @return the middleName
*/
public String getMiddle_name() {
return middle_name;
@Basic
public String getMiddleName() {
return middleName;
}
/**
* @param middle_name the middle_name to set
* @param middleName the middleName to set
*/
public void setMiddle_name(String middle_name) {
this.middle_name = middle_name;
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
/**
* @return the nickname
*/
@Basic
public String getNickname() {
return nickname;
}
@ -142,6 +115,7 @@ public class UserInfo {
/**
* @return the profile
*/
@Basic
public String getProfile() {
return profile;
}
@ -154,6 +128,7 @@ public class UserInfo {
/**
* @return the picture
*/
@Basic
public String getPicture() {
return picture;
}
@ -166,6 +141,7 @@ public class UserInfo {
/**
* @return the website
*/
@Basic
public String getWebsite() {
return website;
}
@ -178,6 +154,7 @@ public class UserInfo {
/**
* @return the email
*/
@Basic
public String getEmail() {
return email;
}
@ -190,6 +167,7 @@ public class UserInfo {
/**
* @return the verified
*/
@Basic
public Boolean getVerified() {
return verified;
}
@ -202,6 +180,7 @@ public class UserInfo {
/**
* @return the gender
*/
@Basic
public String getGender() {
return gender;
}
@ -214,6 +193,7 @@ public class UserInfo {
/**
* @return the zoneinfo
*/
@Basic
public String getZoneinfo() {
return zoneinfo;
}
@ -226,6 +206,7 @@ public class UserInfo {
/**
* @return the locale
*/
@Basic
public String getLocale() {
return locale;
}
@ -236,20 +217,22 @@ public class UserInfo {
this.locale = locale;
}
/**
* @return the phone_number
* @return the phoneNumber
*/
public String getPhone_number() {
return phone_number;
@Basic
public String getPhoneNumber() {
return phoneNumber;
}
/**
* @param phone_number the phone_number to set
* @param phoneNumber the phoneNumber to set
*/
public void setPhone_number(String phone_number) {
this.phone_number = phone_number;
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* @return the address
*/
@OneToOne
public Address getAddress() {
return address;
}
@ -260,16 +243,17 @@ public class UserInfo {
this.address = address;
}
/**
* @return the updated_time
* @return the updatedTime
*/
public String getUpdated_time() {
return updated_time;
@Basic
public String getUpdatedTime() {
return updatedTime;
}
/**
* @param updated_time the updated_time to set
* @param updatedTime the updatedTime to set
*/
public void setUpdated_time(String updated_time) {
this.updated_time = updated_time;
public void setUpdatedTime(String updatedTime) {
this.updatedTime = updatedTime;
}
}

View File

@ -1,17 +1,20 @@
package org.mitre.openid.connect.model;
import java.util.Collection;
import java.util.Set;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.mitre.oauth2.model.ClientDetailsEntity;
/**
* Indicator that login to a site should be automatically granted
@ -21,27 +24,23 @@ import org.springframework.security.oauth2.provider.ClientDetails;
*/
@Entity
@Table(name="whitelistedsite")
@NamedQueries({
@NamedQuery(name = "WhitelistedSite.getAll", query = "select w from WhitelistedSite w")
})
public class WhitelistedSite {
// unique id
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// who added this site to the whitelist (should be an admin)
@ManyToOne
@JoinColumn(name="userinfo_id")
private UserInfo userInfo;
// which OAuth2 client is this tied to
@ManyToOne
@JoinColumn(name="clientdetails_id")
private ClientDetails clientDetails;
private ClientDetailsEntity clientDetails;
// what scopes be allowed by default
// this should include all information for what data to access
@OneToMany(mappedBy="whitelistedsite")
private Collection<String> allowedScopes;
private Set<String> allowedScopes;
/**
* Empty constructor
@ -53,6 +52,8 @@ public class WhitelistedSite {
/**
* @return the id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
@ -67,6 +68,8 @@ public class WhitelistedSite {
/**
* @return the userInfo
*/
@ManyToOne
@JoinColumn(name="userinfo_id")
public UserInfo getUserInfo() {
return userInfo;
}
@ -81,28 +84,31 @@ public class WhitelistedSite {
/**
* @return the clientDetails
*/
public ClientDetails getClientDetails() {
@ManyToOne
@JoinColumn(name="clientdetails_id")
public ClientDetailsEntity getClientDetails() {
return clientDetails;
}
/**
* @param clientDetails the clientDetails to set
*/
public void setClientDetails(ClientDetails clientDetails) {
public void setClientDetails(ClientDetailsEntity clientDetails) {
this.clientDetails = clientDetails;
}
/**
* @return the allowedScopes
*/
public Collection<String> getAllowedScopes() {
@ElementCollection(fetch = FetchType.EAGER)
public Set<String> getAllowedScopes() {
return allowedScopes;
}
/**
* @param allowedScopes the allowedScopes to set
*/
public void setAllowedScopes(Collection<String> allowedScopes) {
public void setAllowedScopes(Set<String> allowedScopes) {
this.allowedScopes = allowedScopes;
}
}