refactoring submodule common - part 4

pull/1580/head
Dominik František Bučík 2020-03-31 09:07:50 +02:00 committed by Dominik Frantisek Bucik
parent 273106f76b
commit c8ddea070e
No known key found for this signature in database
GPG Key ID: 25014C8DB2E7E62D
29 changed files with 79 additions and 423 deletions

View File

@ -37,7 +37,6 @@ import com.google.gson.JsonElement;
/** /**
* @author jricher * @author jricher
*
*/ */
@Entity @Entity
@Table(name = "claim") @Table(name = "claim")
@ -51,129 +50,86 @@ public class Claim {
private Set<String> claimTokenFormat; private Set<String> claimTokenFormat;
private Set<String> issuer; private Set<String> issuer;
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
public Long getId() { public Long getId() {
return id; return id;
} }
/**
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the name
*/
@Basic @Basic
@Column(name = "name") @Column(name = "name")
public String getName() { public String getName() {
return name; return name;
} }
/**
* @param name the name to set
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* @return the friendlyName
*/
@Basic @Basic
@Column(name = "friendly_name") @Column(name = "friendly_name")
public String getFriendlyName() { public String getFriendlyName() {
return friendlyName; return friendlyName;
} }
/**
* @param friendlyName the friendlyName to set
*/
public void setFriendlyName(String friendlyName) { public void setFriendlyName(String friendlyName) {
this.friendlyName = friendlyName; this.friendlyName = friendlyName;
} }
/**
* @return the claimType
*/
@Basic @Basic
@Column(name = "claim_type") @Column(name = "claim_type")
public String getClaimType() { public String getClaimType() {
return claimType; return claimType;
} }
/**
* @param claimType the claimType to set
*/
public void setClaimType(String claimType) { public void setClaimType(String claimType) {
this.claimType = claimType; this.claimType = claimType;
} }
/**
* @return the claimTokenFormat
*/
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@Column(name = "claim_token_format") @Column(name = "claim_token_format")
@CollectionTable( @CollectionTable(name = "claim_token_format", joinColumns = @JoinColumn(name = "owner_id"))
name = "claim_token_format",
joinColumns = @JoinColumn(name = "owner_id")
)
public Set<String> getClaimTokenFormat() { public Set<String> getClaimTokenFormat() {
return claimTokenFormat; return claimTokenFormat;
} }
/**
* @param claimTokenFormat the claimTokenFormat to set
*/
public void setClaimTokenFormat(Set<String> claimTokenFormat) { public void setClaimTokenFormat(Set<String> claimTokenFormat) {
this.claimTokenFormat = claimTokenFormat; this.claimTokenFormat = claimTokenFormat;
} }
/**
* @return the issuer
*/
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@Column(name = "issuer") @Column(name = "issuer")
@CollectionTable( @CollectionTable(name = "claim_issuer", joinColumns = @JoinColumn(name = "owner_id"))
name = "claim_issuer",
joinColumns = @JoinColumn(name = "owner_id")
)
public Set<String> getIssuer() { public Set<String> getIssuer() {
return issuer; return issuer;
} }
/**
* @param issuer the issuer to set
*/
public void setIssuer(Set<String> issuer) { public void setIssuer(Set<String> issuer) {
this.issuer = issuer; this.issuer = issuer;
} }
/**
* @return the value
*/
@Basic @Basic
@Column(name = "claim_value") @Column(name = "claim_value")
@Convert(converter = JsonElementStringConverter.class) @Convert(converter = JsonElementStringConverter.class)
public JsonElement getValue() { public JsonElement getValue() {
return value; return value;
} }
/**
* @param value the value to set
*/
public void setValue(JsonElement value) { public void setValue(JsonElement value) {
this.value = value; this.value = value;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
return "Claim [id=" + id + ", name=" + name + ", friendlyName=" + friendlyName + ", claimType=" + claimType + ", value=" + value + ", claimTokenFormat=" + claimTokenFormat + ", issuer=" + issuer + "]"; return "Claim [id=" + id + ", name=" + name + ", friendlyName=" + friendlyName + ", claimType=" + claimType + ", value=" + value + ", claimTokenFormat=" + claimTokenFormat + ", issuer=" + issuer + "]";
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -187,9 +143,7 @@ public class Claim {
result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((value == null) ? 0 : value.hashCode());
return result; return result;
} }
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
@ -253,4 +207,5 @@ public class Claim {
} }
return true; return true;
} }
} }

View File

@ -22,7 +22,6 @@ import java.util.Collection;
* Data shuttle to return results of the claims processing service. * Data shuttle to return results of the claims processing service.
* *
* @author jricher * @author jricher
*
*/ */
public class ClaimProcessingResult { public class ClaimProcessingResult {
@ -30,64 +29,38 @@ public class ClaimProcessingResult {
private Collection<Claim> unmatched; private Collection<Claim> unmatched;
private Policy matched; private Policy matched;
/**
* Create an unmatched result. isSatisfied is false.
* @param unmatched
*/
public ClaimProcessingResult(Collection<Claim> unmatched) { public ClaimProcessingResult(Collection<Claim> unmatched) {
this.satisfied = false; this.satisfied = false;
this.unmatched = unmatched; this.unmatched = unmatched;
this.matched = null; this.matched = null;
} }
/**
* Create a matched result. isSatisfied is true.
* @param matched
*/
public ClaimProcessingResult(Policy matched) { public ClaimProcessingResult(Policy matched) {
this.satisfied = true; this.satisfied = true;
this.matched = matched; this.matched = matched;
this.unmatched = null; this.unmatched = null;
} }
/**
* @return the satisfied
*/
public boolean isSatisfied() { public boolean isSatisfied() {
return satisfied; return satisfied;
} }
/**
* @param satisfied the satisfied to set
*/
public void setSatisfied(boolean satisfied) { public void setSatisfied(boolean satisfied) {
this.satisfied = satisfied; this.satisfied = satisfied;
} }
/**
* @return the unmatched
*/
public Collection<Claim> getUnmatched() { public Collection<Claim> getUnmatched() {
return unmatched; return unmatched;
} }
/**
* @param unmatched the unmatched to set
*/
public void setUnmatched(Collection<Claim> unmatched) { public void setUnmatched(Collection<Claim> unmatched) {
this.unmatched = unmatched; this.unmatched = unmatched;
} }
/**
* @return the matched
*/
public Policy getMatched() { public Policy getMatched() {
return matched; return matched;
} }
/**
* @param matched the matched to set
*/
public void setMatched(Policy matched) { public void setMatched(Policy matched) {
this.matched = matched; this.matched = matched;
} }

View File

@ -41,9 +41,6 @@ public class Permission {
private ResourceSet resourceSet; private ResourceSet resourceSet;
private Set<String> scopes; private Set<String> scopes;
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -51,46 +48,29 @@ public class Permission {
return id; return id;
} }
/**
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the resourceSet
*/
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "resource_set_id") @JoinColumn(name = "resource_set_id")
public ResourceSet getResourceSet() { public ResourceSet getResourceSet() {
return resourceSet; return resourceSet;
} }
/**
* @param resourceSet the resourceSet to set
*/
public void setResourceSet(ResourceSet resourceSet) { public void setResourceSet(ResourceSet resourceSet) {
this.resourceSet = resourceSet; this.resourceSet = resourceSet;
} }
/**
* @return the scopes
*/
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@Column(name = "scope") @Column(name = "scope")
@CollectionTable( @CollectionTable(name = "permission_scope", joinColumns = @JoinColumn(name = "owner_id"))
name = "permission_scope",
joinColumns = @JoinColumn(name = "owner_id")
)
public Set<String> getScopes() { public Set<String> getScopes() {
return scopes; return scopes;
} }
/**
* @param scopes the scopes to set
*/
public void setScopes(Set<String> scopes) { public void setScopes(Set<String> scopes) {
this.scopes = scopes; this.scopes = scopes;
} }
}
}

View File

@ -66,9 +66,6 @@ public class PermissionTicket {
private Date expiration; private Date expiration;
private Collection<Claim> claimsSupplied; private Collection<Claim> claimsSupplied;
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -76,48 +73,30 @@ public class PermissionTicket {
return id; return id;
} }
/**
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the permission
*/
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "permission_id") @JoinColumn(name = "permission_id")
public Permission getPermission() { public Permission getPermission() {
return permission; return permission;
} }
/**
* @param permission the permission to set
*/
public void setPermission(Permission permission) { public void setPermission(Permission permission) {
this.permission = permission; this.permission = permission;
} }
/**
* @return the ticket
*/
@Basic @Basic
@Column(name = "ticket") @Column(name = "ticket")
public String getTicket() { public String getTicket() {
return ticket; return ticket;
} }
/**
* @param ticket the ticket to set
*/
public void setTicket(String ticket) { public void setTicket(String ticket) {
this.ticket = ticket; this.ticket = ticket;
} }
/**
* @return the expiration
*/
@Basic @Basic
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
@Column(name = "expiration") @Column(name = "expiration")
@ -125,32 +104,19 @@ public class PermissionTicket {
return expiration; return expiration;
} }
/**
* @param expiration the expiration to set
*/
public void setExpiration(Date expiration) { public void setExpiration(Date expiration) {
this.expiration = expiration; this.expiration = expiration;
} }
/**
* @return the claimsSupplied
*/
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable( @JoinTable(name = "claim_to_permission_ticket", joinColumns = @JoinColumn(name = "permission_ticket_id"),
name = "claim_to_permission_ticket", inverseJoinColumns = @JoinColumn(name = "claim_id"))
joinColumns = @JoinColumn(name = "permission_ticket_id"),
inverseJoinColumns = @JoinColumn(name = "claim_id")
)
public Collection<Claim> getClaimsSupplied() { public Collection<Claim> getClaimsSupplied() {
return claimsSupplied; return claimsSupplied;
} }
/**
* @param claimsSupplied the claimsSupplied to set
*/
public void setClaimsSupplied(Collection<Claim> claimsSupplied) { public void setClaimsSupplied(Collection<Claim> claimsSupplied) {
this.claimsSupplied = claimsSupplied; this.claimsSupplied = claimsSupplied;
} }
} }

View File

@ -38,7 +38,6 @@ import javax.persistence.Table;
* A set of claims required to fulfill a given permission. * A set of claims required to fulfill a given permission.
* *
* @author jricher * @author jricher
*
*/ */
@Entity @Entity
@Table(name = "policy") @Table(name = "policy")
@ -49,9 +48,6 @@ public class Policy {
private Collection<Claim> claimsRequired; private Collection<Claim> claimsRequired;
private Set<String> scopes; private Set<String> scopes;
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -59,80 +55,47 @@ public class Policy {
return id; return id;
} }
/**
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the name
*/
@Basic @Basic
@Column(name = "name") @Column(name = "name")
public String getName() { public String getName() {
return name; return name;
} }
/**
* @param name the name to set
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* @return the claimsRequired
*/
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable( @JoinTable(name = "claim_to_policy", joinColumns = @JoinColumn(name = "policy_id"),
name = "claim_to_policy", inverseJoinColumns = @JoinColumn(name = "claim_id"))
joinColumns = @JoinColumn(name = "policy_id"),
inverseJoinColumns = @JoinColumn(name = "claim_id")
)
public Collection<Claim> getClaimsRequired() { public Collection<Claim> getClaimsRequired() {
return claimsRequired; return claimsRequired;
} }
/**
* @param claimsRequired the claimsRequired to set
*/
public void setClaimsRequired(Collection<Claim> claimsRequired) { public void setClaimsRequired(Collection<Claim> claimsRequired) {
this.claimsRequired = claimsRequired; this.claimsRequired = claimsRequired;
} }
/**
* @return the scopes
*/
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@Column(name = "scope") @Column(name = "scope")
@CollectionTable( @CollectionTable(name = "policy_scope", joinColumns = @JoinColumn(name = "owner_id"))
name = "policy_scope",
joinColumns = @JoinColumn(name = "owner_id")
)
public Set<String> getScopes() { public Set<String> getScopes() {
return scopes; return scopes;
} }
/**
* @param scopes the scopes to set
*/
public void setScopes(Set<String> scopes) { public void setScopes(Set<String> scopes) {
this.scopes = scopes; this.scopes = scopes;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
return "Policy [id=" + id + ", name=" + name + ", claimsRequired=" + claimsRequired + ", scopes=" + scopes + "]"; return "Policy [id=" + id + ", name=" + name + ", claimsRequired=" + claimsRequired + ", scopes=" + scopes + "]";
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -144,9 +107,6 @@ public class Policy {
return result; return result;
} }
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {

View File

@ -59,15 +59,11 @@ public class ResourceSet {
private String type; private String type;
private Set<String> scopes = new HashSet<>(); private Set<String> scopes = new HashSet<>();
private String iconUri; private String iconUri;
private String owner; // username of the person responsible for the registration (either directly or via OAuth token) private String owner; // username of the person responsible for the registration (either directly or via OAuth token)
private String clientId; // client id of the protected resource that registered this resource set via OAuth token private String clientId; // client id of the protected resource that registered this resource set via OAuth token
private Collection<Policy> policies = new HashSet<>(); private Collection<Policy> policies = new HashSet<>();
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -75,156 +71,96 @@ public class ResourceSet {
return id; return id;
} }
/**
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the name
*/
@Basic @Basic
@Column(name = "name") @Column(name = "name")
public String getName() { public String getName() {
return name; return name;
} }
/**
* @param name the name to set
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* @return the uri
*/
@Basic @Basic
@Column(name = "uri") @Column(name = "uri")
public String getUri() { public String getUri() {
return uri; return uri;
} }
/**
* @param uri the uri to set
*/
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
/**
* @return the type
*/
@Basic @Basic
@Column(name = "rs_type") @Column(name = "rs_type")
public String getType() { public String getType() {
return type; return type;
} }
/**
* @param type the type to set
*/
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
/**
* @return the scopes
*/
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@Column(name = "scope") @Column(name = "scope")
@CollectionTable( @CollectionTable(name = "resource_set_scope", joinColumns = @JoinColumn(name = "owner_id"))
name = "resource_set_scope",
joinColumns = @JoinColumn(name = "owner_id")
)
public Set<String> getScopes() { public Set<String> getScopes() {
return scopes; return scopes;
} }
/**
* @param scopes the scopes to set
*/
public void setScopes(Set<String> scopes) { public void setScopes(Set<String> scopes) {
this.scopes = scopes; this.scopes = scopes;
} }
/**
* @return the iconUri
*/
@Basic @Basic
@Column(name = "icon_uri") @Column(name = "icon_uri")
public String getIconUri() { public String getIconUri() {
return iconUri; return iconUri;
} }
/**
* @param iconUri the iconUri to set
*/
public void setIconUri(String iconUri) { public void setIconUri(String iconUri) {
this.iconUri = iconUri; this.iconUri = iconUri;
} }
/**
* @return the owner
*/
@Basic @Basic
@Column(name = "owner") @Column(name = "owner")
public String getOwner() { public String getOwner() {
return owner; return owner;
} }
/**
* @param owner the owner to set
*/
public void setOwner(String owner) { public void setOwner(String owner) {
this.owner = owner; this.owner = owner;
} }
/**
* @return the clientId
*/
@Basic @Basic
@Column(name = "client_id") @Column(name = "client_id")
public String getClientId() { public String getClientId() {
return clientId; return clientId;
} }
/**
* @param clientId the clientId to set
*/
public void setClientId(String clientId) { public void setClientId(String clientId) {
this.clientId = clientId; this.clientId = clientId;
} }
/**
* @return the claimsRequired
*/
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "resource_set_id") @JoinColumn(name = "resource_set_id")
public Collection<Policy> getPolicies() { public Collection<Policy> getPolicies() {
return policies; return policies;
} }
/**
* @param policies the claimsRequired to set
*/
public void setPolicies(Collection<Policy> policies) { public void setPolicies(Collection<Policy> policies) {
this.policies = policies; this.policies = policies;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
return "ResourceSet [id=" + id + ", name=" + name + ", uri=" + uri + ", type=" + type + ", scopes=" + scopes + ", iconUri=" + iconUri + ", owner=" + owner + ", clientId=" + clientId + ", policies=" + policies + "]"; return "ResourceSet [id=" + id + ", name=" + name + ", uri=" + uri + ", type=" + type + ", scopes=" + scopes + ", iconUri=" + iconUri + ", owner=" + owner + ", clientId=" + clientId + ", policies=" + policies + "]";
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -322,8 +258,4 @@ public class ResourceSet {
return true; return true;
} }
} }

View File

@ -30,7 +30,6 @@ import org.mitre.uma.model.convert.RegisteredClientStringConverter;
/** /**
* @author jricher * @author jricher
*
*/ */
@Entity @Entity
@Table(name = "saved_registered_client") @Table(name = "saved_registered_client")
@ -40,9 +39,6 @@ public class SavedRegisteredClient {
private String issuer; private String issuer;
private RegisteredClient registeredClient; private RegisteredClient registeredClient;
/**
* @return the id
*/
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
@ -50,33 +46,20 @@ public class SavedRegisteredClient {
return id; return id;
} }
/**
*
* @param id the id to set
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* @return the issuer
*/
@Basic @Basic
@Column(name = "issuer") @Column(name = "issuer")
public String getIssuer() { public String getIssuer() {
return issuer; return issuer;
} }
/**
* @param issuer the issuer to set
*/
public void setIssuer(String issuer) { public void setIssuer(String issuer) {
this.issuer = issuer; this.issuer = issuer;
} }
/**
* @return the registeredClient
*/
@Basic @Basic
@Column(name = "registered_client") @Column(name = "registered_client")
@Convert(converter = RegisteredClientStringConverter.class) @Convert(converter = RegisteredClientStringConverter.class)
@ -84,13 +67,8 @@ public class SavedRegisteredClient {
return registeredClient; return registeredClient;
} }
/**
* @param registeredClient the registeredClient to set
*/
public void setRegisteredClient(RegisteredClient registeredClient) { public void setRegisteredClient(RegisteredClient registeredClient) {
this.registeredClient = registeredClient; this.registeredClient = registeredClient;
} }
} }

View File

@ -21,39 +21,22 @@ import javax.persistence.Converter;
import org.mitre.oauth2.model.RegisteredClient; import org.mitre.oauth2.model.RegisteredClient;
import org.mitre.openid.connect.ClientDetailsEntityJsonProcessor; import org.mitre.openid.connect.ClientDetailsEntityJsonProcessor;
import org.springframework.util.StringUtils;
import com.google.common.base.Strings;
/** /**
* @author jricher * @author jricher
*
*/ */
@Converter @Converter
public class RegisteredClientStringConverter implements AttributeConverter<RegisteredClient, String>{ public class RegisteredClientStringConverter implements AttributeConverter<RegisteredClient, String>{
/* (non-Javadoc)
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object)
*/
@Override @Override
public String convertToDatabaseColumn(RegisteredClient attribute) { public String convertToDatabaseColumn(RegisteredClient attribute) {
if (attribute == null || attribute.getSource() == null) { return attribute == null || attribute.getSource() == null ? null : attribute.getSource().toString();
return null;
} else {
return attribute.getSource().toString();
}
} }
/* (non-Javadoc)
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object)
*/
@Override @Override
public RegisteredClient convertToEntityAttribute(String dbData) { public RegisteredClient convertToEntityAttribute(String dbData) {
if (Strings.isNullOrEmpty(dbData)) { return StringUtils.isEmpty(dbData) ? null : ClientDetailsEntityJsonProcessor.parseRegistered(dbData);
return null;
} else {
return ClientDetailsEntityJsonProcessor.parseRegistered(dbData);
}
} }
} }

View File

@ -24,63 +24,21 @@ import org.mitre.uma.model.ResourceSet;
/** /**
* @author jricher * @author jricher
*
*/ */
public interface PermissionRepository { public interface PermissionRepository {
/** PermissionTicket save(PermissionTicket p);
*
* Save a permission ticket.
*
* @param p
* @return
*/
public PermissionTicket save(PermissionTicket p);
/** PermissionTicket getByTicket(String ticket);
* Get the permission indicated by its ticket value.
*
* @param ticket
* @return
*/
public PermissionTicket getByTicket(String ticket);
/** Collection<PermissionTicket> getAll();
* Get all the tickets in the system (used by the import/export API)
*
* @return
*/
public Collection<PermissionTicket> getAll();
/** Permission saveRawPermission(Permission p);
* Save a permission object with no associated ticket (used by the import/export API)
*
* @param p
* @return
*/
public Permission saveRawPermission(Permission p);
/** Permission getById(Long permissionId);
* Get a permission object by its ID (used by the import/export API)
*
* @param permissionId
* @return
*/
public Permission getById(Long permissionId);
/** Collection<PermissionTicket> getPermissionTicketsForResourceSet(ResourceSet rs);
* Get all permission tickets issued against a resource set (called when RS is deleted)
*
* @param rs
* @return
*/
public Collection<PermissionTicket> getPermissionTicketsForResourceSet(ResourceSet rs);
/** void remove(PermissionTicket ticket);
* Remove the specified ticket.
*
* @param ticket
*/
public void remove(PermissionTicket ticket);
} }

View File

@ -22,22 +22,21 @@ import org.mitre.uma.model.ResourceSet;
/** /**
* @author jricher * @author jricher
*
*/ */
public interface ResourceSetRepository { public interface ResourceSetRepository {
public ResourceSet save(ResourceSet rs); ResourceSet save(ResourceSet rs);
public ResourceSet getById(Long id); ResourceSet getById(Long id);
public void remove(ResourceSet rs); void remove(ResourceSet rs);
public Collection<ResourceSet> getAllForOwner(String owner); Collection<ResourceSet> getAllForOwner(String owner);
public Collection<ResourceSet> getAllForOwnerAndClient(String owner, String clientId); Collection<ResourceSet> getAllForOwnerAndClient(String owner, String clientId);
public Collection<ResourceSet> getAll(); Collection<ResourceSet> getAll();
public Collection<ResourceSet> getAllForClient(String clientId); Collection<ResourceSet> getAllForClient(String clientId);
} }

View File

@ -21,11 +21,9 @@ import org.mitre.uma.model.PermissionTicket;
import org.mitre.uma.model.ResourceSet; import org.mitre.uma.model.ResourceSet;
/** /**
*
* Processes claims presented during an UMA transaction. * Processes claims presented during an UMA transaction.
* *
* @author jricher * @author jricher
*
*/ */
public interface ClaimsProcessingService { public interface ClaimsProcessingService {
@ -39,6 +37,6 @@ public interface ClaimsProcessingService {
* @param ticket the supplied claims to test * @param ticket the supplied claims to test
* @return the result of the claims processing action * @return the result of the claims processing action
*/ */
public ClaimProcessingResult claimsAreSatisfied(ResourceSet rs, PermissionTicket ticket); ClaimProcessingResult claimsAreSatisfied(ResourceSet rs, PermissionTicket ticket);
} }

View File

@ -25,7 +25,6 @@ import org.springframework.security.oauth2.common.exceptions.InsufficientScopeEx
/** /**
* @author jricher * @author jricher
*
*/ */
public interface PermissionService { public interface PermissionService {
@ -35,16 +34,15 @@ public interface PermissionService {
* @return the created (and stored) permission object, with ticket * @return the created (and stored) permission object, with ticket
* @throws InsufficientScopeException if the scopes in scopes don't match those in resourceSet.getScopes * @throws InsufficientScopeException if the scopes in scopes don't match those in resourceSet.getScopes
*/ */
public PermissionTicket createTicket(ResourceSet resourceSet, Set<String> scopes); PermissionTicket createTicket(ResourceSet resourceSet, Set<String> scopes);
/** /**
*
* Read the permission associated with the given ticket. * Read the permission associated with the given ticket.
* *
* @param the ticket value to search on * @param the ticket value to search on
* @return the permission object, or null if none is found * @return the permission object, or null if none is found
*/ */
public PermissionTicket getByTicket(String ticket); PermissionTicket getByTicket(String ticket);
/** /**
* Save the updated permission ticket to the database. Does not create a new ticket. * Save the updated permission ticket to the database. Does not create a new ticket.
@ -52,6 +50,6 @@ public interface PermissionService {
* @param ticket * @param ticket
* @return * @return
*/ */
public PermissionTicket updateTicket(PermissionTicket ticket); PermissionTicket updateTicket(PermissionTicket ticket);
} }

View File

@ -21,26 +21,24 @@ import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.uma.model.ResourceSet; import org.mitre.uma.model.ResourceSet;
/** /**
*
* Manage registered resource sets at this authorization server. * Manage registered resource sets at this authorization server.
* *
* @author jricher * @author jricher
*
*/ */
public interface ResourceSetService { public interface ResourceSetService {
public ResourceSet saveNew(ResourceSet rs); ResourceSet saveNew(ResourceSet rs);
public ResourceSet getById(Long id); ResourceSet getById(Long id);
public ResourceSet update(ResourceSet oldRs, ResourceSet newRs); ResourceSet update(ResourceSet oldRs, ResourceSet newRs);
public void remove(ResourceSet rs); void remove(ResourceSet rs);
public Collection<ResourceSet> getAllForOwner(String owner); Collection<ResourceSet> getAllForOwner(String owner);
public Collection<ResourceSet> getAllForOwnerAndClient(String owner, String authClientId); Collection<ResourceSet> getAllForOwnerAndClient(String owner, String authClientId);
public Collection<ResourceSet> getAllForClient(ClientDetailsEntity client); Collection<ResourceSet> getAllForClient(ClientDetailsEntity client);
} }

View File

@ -23,7 +23,6 @@ import org.mitre.uma.model.SavedRegisteredClient;
/** /**
* @author jricher * @author jricher
*
*/ */
public interface SavedRegisteredClientService { public interface SavedRegisteredClientService {

View File

@ -31,8 +31,7 @@ public interface UmaTokenService {
/** /**
* Create the RPT from the given authentication and ticket. * Create the RPT from the given authentication and ticket.
*
*/ */
public OAuth2AccessTokenEntity createRequestingPartyToken(OAuth2Authentication o2auth, PermissionTicket ticket, Policy policy); OAuth2AccessTokenEntity createRequestingPartyToken(OAuth2Authentication o2auth, PermissionTicket ticket, Policy policy);
} }

View File

@ -51,14 +51,10 @@ import com.nimbusds.jose.JWSAlgorithm;
* A collection of null-safe converters from common classes and JSON elements, using GSON. * A collection of null-safe converters from common classes and JSON elements, using GSON.
* *
* @author jricher * @author jricher
*
*/ */
@SuppressWarnings(value = {"rawtypes", "unchecked"}) @SuppressWarnings(value = {"rawtypes", "unchecked"})
public class JsonUtils { public class JsonUtils {
/**
* Logger for this class
*/
private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class); private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class);
private static Gson gson = new Gson(); private static Gson gson = new Gson();
@ -72,7 +68,6 @@ public class JsonUtils {
return getAsArray(value, false); return getAsArray(value, false);
} }
/** /**
* Translate a set of strings to a JSON array, optionally preserving the empty array. Otherwise (default) empty array is returned as null. * Translate a set of strings to a JSON array, optionally preserving the empty array. Otherwise (default) empty array is returned as null.
* @param value * @param value
@ -109,11 +104,7 @@ public class JsonUtils {
*/ */
public static JWEAlgorithm getAsJweAlgorithm(JsonObject o, String member) { public static JWEAlgorithm getAsJweAlgorithm(JsonObject o, String member) {
String s = getAsString(o, member); String s = getAsString(o, member);
if (s != null) { return s != null ? JWEAlgorithm.parse(s) : null;
return JWEAlgorithm.parse(s);
} else {
return null;
}
} }
/** /**
@ -121,11 +112,7 @@ public class JsonUtils {
*/ */
public static EncryptionMethod getAsJweEncryptionMethod(JsonObject o, String member) { public static EncryptionMethod getAsJweEncryptionMethod(JsonObject o, String member) {
String s = getAsString(o, member); String s = getAsString(o, member);
if (s != null) { return s != null ? EncryptionMethod.parse(s) : null;
return EncryptionMethod.parse(s);
} else {
return null;
}
} }
/** /**
@ -133,11 +120,7 @@ public class JsonUtils {
*/ */
public static JWSAlgorithm getAsJwsAlgorithm(JsonObject o, String member) { public static JWSAlgorithm getAsJwsAlgorithm(JsonObject o, String member) {
String s = getAsString(o, member); String s = getAsString(o, member);
if (s != null) { return s != null ? JWSAlgorithm.parse(s) : null;
return JWSAlgorithm.parse(s);
} else {
return null;
}
} }
/** /**
@ -148,11 +131,7 @@ public class JsonUtils {
*/ */
public static PKCEAlgorithm getAsPkceAlgorithm(JsonObject o, String member) { public static PKCEAlgorithm getAsPkceAlgorithm(JsonObject o, String member) {
String s = getAsString(o, member); String s = getAsString(o, member);
if (s != null) { return s != null ? PKCEAlgorithm.parse(s) : null;
return PKCEAlgorithm.parse(s);
} else {
return null;
}
} }
/** /**
@ -286,7 +265,7 @@ public class JsonUtils {
reader.beginObject(); reader.beginObject();
while(reader.hasNext()) { while(reader.hasNext()) {
String name = reader.nextName(); String name = reader.nextName();
Object value = null; Object value;
switch(reader.peek()) { switch(reader.peek()) {
case STRING: case STRING:
value = reader.nextString(); value = reader.nextString();
@ -309,7 +288,7 @@ public class JsonUtils {
} }
public static Set readSet(JsonReader reader) throws IOException { public static Set readSet(JsonReader reader) throws IOException {
Set arraySet = null; Set arraySet;
reader.beginArray(); reader.beginArray();
switch (reader.peek()) { switch (reader.peek()) {
case STRING: case STRING:

View File

@ -30,6 +30,7 @@ import org.mitre.data.PageCriteria;
* Time: 2:13 PM * Time: 2:13 PM
*/ */
public class JpaUtil { public class JpaUtil {
public static <T> T getSingleResult(List<T> list) { public static <T> T getSingleResult(List<T> list) {
switch(list.size()) { switch(list.size()) {
case 0: case 0:
@ -41,7 +42,6 @@ public class JpaUtil {
} }
} }
/** /**
* Get a page of results from the specified TypedQuery * Get a page of results from the specified TypedQuery
* by using the given PageCriteria to limit the query * by using the given PageCriteria to limit the query
@ -60,9 +60,10 @@ public class JpaUtil {
return query.getResultList(); return query.getResultList();
} }
public static <T, I> T saveOrUpdate(I id, EntityManager entityManager, T entity) { public static <T, I> T saveOrUpdate(EntityManager entityManager, T entity) {
T tmp = entityManager.merge(entity); T tmp = entityManager.merge(entity);
entityManager.flush(); entityManager.flush();
return tmp; return tmp;
} }
} }

View File

@ -65,7 +65,7 @@ public class JpaAuthenticationHolderRepository implements AuthenticationHolderRe
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public AuthenticationHolderEntity save(AuthenticationHolderEntity a) { public AuthenticationHolderEntity save(AuthenticationHolderEntity a) {
return JpaUtil.saveOrUpdate(a.getId(), manager, a); return JpaUtil.saveOrUpdate(manager, a);
} }
@Override @Override

View File

@ -54,7 +54,7 @@ public class JpaAuthorizationCodeRepository implements AuthorizationCodeReposito
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public AuthorizationCodeEntity save(AuthorizationCodeEntity authorizationCode) { public AuthorizationCodeEntity save(AuthorizationCodeEntity authorizationCode) {
return JpaUtil.saveOrUpdate(authorizationCode.getId(), manager, authorizationCode); return JpaUtil.saveOrUpdate(manager, authorizationCode);
} }

View File

@ -89,7 +89,7 @@ public class JpaDeviceCodeRepository implements DeviceCodeRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public DeviceCode save(DeviceCode scope) { public DeviceCode save(DeviceCode scope) {
return saveOrUpdate(scope.getId(), em, scope); return saveOrUpdate(em, scope);
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -68,7 +68,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
*/ */
@Override @Override
public ClientDetailsEntity saveClient(ClientDetailsEntity client) { public ClientDetailsEntity saveClient(ClientDetailsEntity client) {
return JpaUtil.saveOrUpdate(client.getClientId(), manager, client); return JpaUtil.saveOrUpdate(manager, client);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -89,7 +89,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
// sanity check // sanity check
client.setId(id); client.setId(id);
return JpaUtil.saveOrUpdate(id, manager, client); return JpaUtil.saveOrUpdate(manager, client);
} }
@Override @Override

View File

@ -93,7 +93,7 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token) { public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token) {
return JpaUtil.saveOrUpdate(token.getId(), manager, token); return JpaUtil.saveOrUpdate(manager, token);
} }
@Override @Override
@ -138,7 +138,7 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken) { public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
return JpaUtil.saveOrUpdate(refreshToken.getId(), manager, refreshToken); return JpaUtil.saveOrUpdate(manager, refreshToken);
} }
@Override @Override

View File

@ -96,7 +96,7 @@ public class JpaSystemScopeRepository implements SystemScopeRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public SystemScope save(SystemScope scope) { public SystemScope save(SystemScope scope) {
return saveOrUpdate(scope.getId(), em, scope); return saveOrUpdate(em, scope);
} }
} }

View File

@ -70,7 +70,7 @@ public class JpaApprovedSiteRepository implements ApprovedSiteRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public ApprovedSite save(ApprovedSite approvedSite) { public ApprovedSite save(ApprovedSite approvedSite) {
return saveOrUpdate(approvedSite.getId(), manager, approvedSite); return saveOrUpdate(manager, approvedSite);
} }
@Override @Override

View File

@ -84,7 +84,7 @@ public class JpaBlacklistedSiteRepository implements BlacklistedSiteRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public BlacklistedSite save(BlacklistedSite blacklistedSite) { public BlacklistedSite save(BlacklistedSite blacklistedSite) {
return saveOrUpdate(blacklistedSite.getId(), manager, blacklistedSite); return saveOrUpdate(manager, blacklistedSite);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -95,7 +95,7 @@ public class JpaBlacklistedSiteRepository implements BlacklistedSiteRepository {
public BlacklistedSite update(BlacklistedSite oldBlacklistedSite, BlacklistedSite blacklistedSite) { public BlacklistedSite update(BlacklistedSite oldBlacklistedSite, BlacklistedSite blacklistedSite) {
blacklistedSite.setId(oldBlacklistedSite.getId()); blacklistedSite.setId(oldBlacklistedSite.getId());
return saveOrUpdate(oldBlacklistedSite.getId(), manager, blacklistedSite); return saveOrUpdate(manager, blacklistedSite);
} }

View File

@ -60,7 +60,7 @@ public class JpaPairwiseIdentifierRepository implements PairwiseIdentifierReposi
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public void save(PairwiseIdentifier pairwise) { public void save(PairwiseIdentifier pairwise) {
saveOrUpdate(pairwise.getId(), manager, pairwise); saveOrUpdate(manager, pairwise);
} }
} }

View File

@ -71,7 +71,7 @@ public class JpaWhitelistedSiteRepository implements WhitelistedSiteRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public WhitelistedSite save(WhitelistedSite whiteListedSite) { public WhitelistedSite save(WhitelistedSite whiteListedSite) {
return saveOrUpdate(whiteListedSite.getId(), manager, whiteListedSite); return saveOrUpdate(manager, whiteListedSite);
} }
@Override @Override
@ -80,7 +80,7 @@ public class JpaWhitelistedSiteRepository implements WhitelistedSiteRepository {
// sanity check // sanity check
whitelistedSite.setId(oldWhitelistedSite.getId()); whitelistedSite.setId(oldWhitelistedSite.getId());
return saveOrUpdate(oldWhitelistedSite.getId(), manager, whitelistedSite); return saveOrUpdate(manager, whitelistedSite);
} }
@Override @Override

View File

@ -43,7 +43,7 @@ public class JpaPermissionRepository implements PermissionRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public PermissionTicket save(PermissionTicket p) { public PermissionTicket save(PermissionTicket p) {
return JpaUtil.saveOrUpdate(p.getId(), em, p); return JpaUtil.saveOrUpdate(em, p);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -71,7 +71,7 @@ public class JpaPermissionRepository implements PermissionRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public Permission saveRawPermission(Permission p) { public Permission saveRawPermission(Permission p) {
return JpaUtil.saveOrUpdate(p.getId(), em, p); return JpaUtil.saveOrUpdate(em, p);
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -44,7 +44,7 @@ public class JpaResourceSetRepository implements ResourceSetRepository {
@Override @Override
@Transactional(value="defaultTransactionManager") @Transactional(value="defaultTransactionManager")
public ResourceSet save(ResourceSet rs) { public ResourceSet save(ResourceSet rs) {
return JpaUtil.saveOrUpdate(rs.getId(), em, rs); return JpaUtil.saveOrUpdate(em, rs);
} }
@Override @Override