Skip to content

Commit

Permalink
SHIBUI-1262 [1307,1308 WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jun 3, 2019
1 parent 7c4aced commit 3610ed1
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 1 deletion.
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.AttributeExtensibleXMLObject;
import org.opensaml.core.xml.util.AttributeMap;

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

@MappedSuperclass
@EqualsAndHashCode(callSuper = true, exclude={"unknownAttributes"})
@Audited
public abstract class AbstractAttributeExtensibleXMLObject extends AbstractXMLObject implements AttributeExtensibleXMLObject {

private transient final AttributeMap unknownAttributes;
Expand All @@ -24,4 +26,4 @@ public abstract class AbstractAttributeExtensibleXMLObject extends AbstractXMLOb
public AttributeMap getUnknownAttributes() {
return this.unknownAttributes;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.envers.Audited;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
Expand All @@ -22,6 +23,7 @@
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode
@Audited
public abstract class AbstractAuditable implements Auditable {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Attribute extends AbstractAttributeExtensibleXMLObject implements o

@OneToMany(cascade = CascadeType.ALL)
@OrderColumn
@Audited
private List<AbstractXMLObject> attributeValues = new ArrayList<>();

@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.saml.saml2.core.Assertion;

Expand All @@ -16,6 +17,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class EntityAttributes extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.ext.saml2mdattr.EntityAttributes {

@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.util.AttributeMap;

import javax.annotation.Nonnull;
Expand All @@ -10,6 +11,7 @@

@Entity
@EqualsAndHashCode(callSuper = true, exclude = {"unknownAttributes"})
@Audited
public class XSAny extends AbstractElementExtensibleXMLObject implements org.opensaml.core.xml.schema.XSAny {

private String textContext;
Expand Down
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 XSBase64Binary extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSBase64Binary {
private String b64value;

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.schema.XSBooleanValue;

import javax.annotation.Nullable;
Expand All @@ -9,6 +10,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class XSBoolean extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSBoolean {
private String storedValue;

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.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
import org.joda.time.format.DateTimeFormatter;
Expand All @@ -13,6 +14,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class XSDateTime extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSDateTime {

private DateTime dateTime;
Expand Down
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 XSInteger extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSInteger {
private int intValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.EqualsAndHashCode;
import net.shibboleth.utilities.java.support.xml.QNameSupport;
import org.hibernate.envers.Audited;

import javax.annotation.Nullable;
import javax.persistence.Entity;
Expand All @@ -10,6 +11,7 @@

@Entity
@EqualsAndHashCode(callSuper = true)
@Audited
public class XSQName extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSQName {
@Nullable
@Override
Expand Down
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 XSString extends AbstractXMLObject implements org.opensaml.core.xml.schema.XSString {
private String xsStringvalue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import edu.internet2.tier.shibboleth.admin.ui.configuration.Internationalization
import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration
import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration
import edu.internet2.tier.shibboleth.admin.ui.domain.AssertionConsumerService
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityAttributes
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.KeyDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.SPSSODescriptor
Expand Down Expand Up @@ -518,4 +519,59 @@ class EntityDescriptorEnversVersioningTests extends Specification {
slo.location == 'http://logout'
slo.binding == 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
}

@DirtiesContext
def "test versioning relying party overrides"() {
when:
EntityDescriptor ed = new EntityDescriptor()
def representation = new EntityDescriptorRepresentation().with {
it.relyingPartyOverrides = [signAssertion: true]
it.attributeRelease = ['attr1']
it
}

def entityDescriptorHistory = updateAndGetRevisionHistoryOfEntityDescriptor(ed, representation, entityDescriptorService,
entityDescriptorRepository,
txMgr,
entityManager)

EntityAttributes attrs = entityDescriptorService.getEntityAttributes(getTargetEntityForRevisionIndex(entityDescriptorHistory, 0))

then:
entityDescriptorHistory.size() == 1
attrs.attributes[0].attributeValues[0].storedValue == 'true'
attrs.attributes[1].attributeValues[0].xsStringvalue == 'attr1'

when:
representation = new EntityDescriptorRepresentation().with {
it.relyingPartyOverrides = [signAssertion: false]
it.attributeRelease = ['attr1', 'attr2']
it
}

//Currently this is the ONLY way to let envers recognize update revision type for EntityDescriptor type
//when modifying attributes. This date "touch" would need to be encapsulated
//perhaps in JPAEntityDescriptorServiceImpl#buildDescriptorFromRepresentation
ed.modifiedDate = LocalDateTime.now()

entityDescriptorHistory = updateAndGetRevisionHistoryOfEntityDescriptor(ed, representation, entityDescriptorService,
entityDescriptorRepository,
txMgr,
entityManager)

EntityAttributes attrs2 = entityDescriptorService.getEntityAttributes(getTargetEntityForRevisionIndex(entityDescriptorHistory, 1))

//Initial revision
attrs = entityDescriptorService.getEntityAttributes(getTargetEntityForRevisionIndex(entityDescriptorHistory, 0))

then:
entityDescriptorHistory.size() == 2
attrs2.attributes[0].attributeValues[0].xsStringvalue == 'attr1'
attrs2.attributes[0].attributeValues[1].xsStringvalue == 'attr2'

//Check the initial revision is intact
attrs.attributes[0].attributeValues[0].storedValue == 'true'
attrs.attributes[1].attributeValues[0].xsStringvalue == 'attr1'
attrs.attributes[1].attributeValues[1] == null
}
}

0 comments on commit 3610ed1

Please sign in to comment.