Skip to content

Commit

Permalink
SHIBUI-1262 [1307 WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed May 29, 2019
1 parent dcf2ec2 commit a8e82ba
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.ElementExtensibleXMLObject;
import org.opensaml.core.xml.XMLObject;

Expand All @@ -20,6 +21,7 @@
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EqualsAndHashCode(callSuper = true)
@Audited
public abstract class AbstractElementExtensibleXMLObject extends AbstractXMLObject implements ElementExtensibleXMLObject {
@OneToMany(cascade = CascadeType.ALL)
@OrderColumn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.xmlsec.encryption.KeySize;
import org.opensaml.xmlsec.encryption.OAEPparams;

Expand All @@ -10,6 +11,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class EncryptionMethod extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.saml2.metadata.EncryptionMethod {

private String algorithm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;

import javax.annotation.Nonnull;
Expand All @@ -14,6 +15,7 @@
*/
@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class Endpoint extends AbstractAttributeExtensibleXMLObject implements org.opensaml.saml.saml2.metadata.Endpoint {

private String binding;
Expand Down Expand Up @@ -72,4 +74,4 @@ public List<XMLObject> getUnknownXMLObjects() {
public List<XMLObject> getUnknownXMLObjects(@Nonnull QName qName) {
return null; //TODO
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@

import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
import org.opensaml.core.xml.io.MarshallingException;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import javax.annotation.Nullable;

import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderColumn;
import javax.persistence.Transient;

import javax.xml.namespace.QName;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -49,7 +40,6 @@ public class EntityDescriptor extends AbstractDescriptor implements org.opensaml
private String resourceId;

@OneToOne(cascade = CascadeType.ALL)
@NotAudited
private Organization organization;

@OneToMany(cascade = CascadeType.ALL)
Expand All @@ -58,7 +48,6 @@ public class EntityDescriptor extends AbstractDescriptor implements org.opensaml

@OneToMany(cascade = CascadeType.ALL)
@OrderColumn
@NotAudited
private List<RoleDescriptor> roleDescriptors;

@OneToMany(cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;

import javax.annotation.Nullable;
Expand All @@ -13,6 +14,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class Extensions extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.saml2.metadata.Extensions {
@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.security.credential.UsageType;
import org.opensaml.xmlsec.signature.KeyInfo;
Expand All @@ -12,6 +13,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class KeyDescriptor extends AbstractXMLObject implements org.opensaml.saml.saml2.metadata.KeyDescriptor {

@Column(name = "keyDescriptorName")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.xmlsec.encryption.AgreementMethod;
import org.opensaml.xmlsec.encryption.EncryptedKey;
Expand Down Expand Up @@ -29,6 +30,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class KeyInfo extends AbstractXMLObject implements org.opensaml.xmlsec.signature.KeyInfo {

@OneToMany(cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import org.hibernate.envers.Audited;

import javax.annotation.Nullable;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
@Audited
public class LocalizedName extends AbstractXMLObject implements org.opensaml.saml.saml2.metadata.LocalizedName {

private String xMLLang;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;

import javax.annotation.Nullable;
Expand All @@ -11,6 +12,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class Organization extends AbstractAttributeExtensibleXMLObject implements org.opensaml.saml.saml2.metadata.Organization {

@OneToOne(cascade = CascadeType.ALL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;

import javax.persistence.Entity;

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class OrganizationDisplayName extends LocalizedName implements org.opensaml.saml.saml2.metadata.OrganizationDisplayName {

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;

import javax.persistence.Entity;

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class OrganizationName extends LocalizedName implements org.opensaml.saml.saml2.metadata.OrganizationName {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;

import javax.annotation.Nullable;
import javax.persistence.Entity;

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class OrganizationURL extends AbstractXMLObject implements org.opensaml.saml.saml2.metadata.OrganizationURL {

private String xMLLang;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.util.AttributeMap;

Expand All @@ -25,6 +26,7 @@

@Entity
@EqualsAndHashCode(callSuper = true, exclude={"unknownAttributes"})
@Audited
public class RoleDescriptor extends AbstractDescriptor implements org.opensaml.saml.saml2.metadata.RoleDescriptor {

@ElementCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.ContactRepresentation
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.OrganizationRepresentation
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService
Expand All @@ -16,7 +17,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.test.context.ContextConfiguration
import org.springframework.transaction.PlatformTransactionManager
import spock.lang.Shared
import spock.lang.Specification

import javax.persistence.EntityManager
Expand Down Expand Up @@ -49,11 +49,9 @@ class EntityDescriptorEnversVersioningTests extends Specification {
@Autowired
OpenSamlObjects openSamlObjects

@Shared
EntityDescriptor ed = new EntityDescriptor()

def "test versioning with contact persons"() {
when:
def ed = new EntityDescriptor()
def representation = new EntityDescriptorRepresentation().with {
it.contacts = [new ContactRepresentation(type: 'administrative', name: 'name', emailAddress: 'test@test')]
it
Expand Down Expand Up @@ -116,4 +114,48 @@ class EntityDescriptorEnversVersioningTests extends Specification {
entityDescriptorHistory[0][1].timestamp > 0L

}

def "test versioning with organization"() {
when:
EntityDescriptor ed = new EntityDescriptor()
def representation = new EntityDescriptorRepresentation().with {
it.organization = new OrganizationRepresentation(name: 'org', displayName: 'display org', url: 'http://org.edu')
it
}
def entityDescriptorHistory = updateAndGetRevisionHistory(ed, representation, entityDescriptorService,
entityDescriptorRepository,
txMgr,
entityManager)
then:
entityDescriptorHistory.size() == 1
entityDescriptorHistory[0][0].organization.organizationNames[0].value == 'org'
entityDescriptorHistory[0][0].organization.displayNames[0].value == 'display org'
entityDescriptorHistory[0][0].organization.URLs[0].value == 'http://org.edu'
entityDescriptorHistory[0][1].principalUserName == 'anonymous'
entityDescriptorHistory[0][1].timestamp > 0L

when:
representation = new EntityDescriptorRepresentation().with {
it.organization = new OrganizationRepresentation(name: 'orgUpdated', displayName: 'display org Updated', url: 'http://org2.edu')
it
}
entityDescriptorHistory = updateAndGetRevisionHistory(ed, representation, entityDescriptorService,
entityDescriptorRepository,
txMgr,
entityManager)
then:
entityDescriptorHistory.size() == 2
entityDescriptorHistory[1][0].organization.organizationNames[0].value == 'orgUpdated'
entityDescriptorHistory[1][0].organization.displayNames[0].value == 'display org Updated'
entityDescriptorHistory[1][0].organization.URLs[0].value == 'http://org2.edu'
entityDescriptorHistory[1][1].principalUserName == 'anonymous'
entityDescriptorHistory[1][1].timestamp > 0L

//Check the original revision is intact
entityDescriptorHistory[0][0].organization.organizationNames[0].value == 'org'
entityDescriptorHistory[0][0].organization.displayNames[0].value == 'display org'
entityDescriptorHistory[0][0].organization.URLs[0].value == 'http://org.edu'
entityDescriptorHistory[0][1].principalUserName == 'anonymous'
entityDescriptorHistory[0][1].timestamp > 0L
}
}

0 comments on commit a8e82ba

Please sign in to comment.