Skip to content

Commit

Permalink
Merged in SHIBUI-468 (pull request #72)
Browse files Browse the repository at this point in the history
SHIBUI-468

* [SHIBUI-440]

    Unit test additions WIP

* [SHIBUI-440]

    Added simple tests to ensure that file creation and deletion happens as expected.

* [SHIBUI-440]

    Heavily refactored JPAEntityServiceImpl.getAttributeListFromEntityRepresentation.
    Added more tests in an attempt to increase coverage.
    Removed a couple default constructors.
    Added a helper util for counting attributes from a RelyingPartyOverridesRepresentation. This could maybe use a better name.

* [SHIBUI-440]

    Added a unit test to check for the exception that we always throw here.

* [SHIBUI-440]

    Added a WIP unit test. There are a few that still need to be added to this class.

* [SHIBUI-468]

    Added tests for XML-related POSTs/GETs of EntityDescriptors,

* [SHIBUI-468]

    Added simple auth test.
  • Loading branch information
Bill Smith authored and Jonathan Johnson committed May 17, 2018
1 parent fcb0b88 commit 072c3c3
Show file tree
Hide file tree
Showing 10 changed files with 712 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
public interface EntityService {
List<Attribute> getAttributeListFromEntityRepresentation(EntityDescriptorRepresentation entityDescriptorRepresentation);
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute getAttributeFromAttributeReleaseList(List<String> attributeReleaseList);
List<Attribute> getAttributeListFromAttributeReleaseList(List<String> attributeReleaseList);
List<Attribute> getAttributeListFromRelyingPartyOverridesRepresentation(RelyingPartyOverridesRepresentation relyingPartyOverridesRepresentation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public class JPAEntityDescriptorServiceImpl implements EntityDescriptorService {
@Autowired
private EntityService entityService;

public JPAEntityDescriptorServiceImpl() {
}

public JPAEntityDescriptorServiceImpl(OpenSamlObjects openSamlObjects, EntityService entityService) {
this.openSamlObjects = openSamlObjects;
this.entityService = entityService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class JPAEntityServiceImpl implements EntityService {
@Autowired
private AttributeUtility attributeUtility;

public JPAEntityServiceImpl() {}

public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects) {
this.openSamlObjects = openSamlObjects;
}
Expand All @@ -32,55 +30,40 @@ public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects) {
public List<Attribute> getAttributeListFromEntityRepresentation(EntityDescriptorRepresentation entityDescriptorRepresentation) {
List<edu.internet2.tier.shibboleth.admin.ui.domain.Attribute> list = new ArrayList<>();
if (entityDescriptorRepresentation.getRelyingPartyOverrides() != null) {
// Let's do the overrides
RelyingPartyOverridesRepresentation overridesRepresentation = entityDescriptorRepresentation.getRelyingPartyOverrides();
if (overridesRepresentation.isSignAssertion()) {
list.add(attributeUtility.createAttributeWithBooleanValue(MDDCConstants.SIGN_ASSERTIONS, MDDCConstants.SIGN_ASSERTIONS_FN, true));
}
if (overridesRepresentation.isDontSignResponse()) {
list.add(attributeUtility.createAttributeWithBooleanValue(MDDCConstants.SIGN_RESPONSES, MDDCConstants.SIGN_RESPONSES_FN, false));
}
if (overridesRepresentation.isTurnOffEncryption()) {
list.add(attributeUtility.createAttributeWithBooleanValue(MDDCConstants.ENCRYPT_ASSERTIONS, MDDCConstants.ENCRYPT_ASSERTIONS_FN, false));
}
if (overridesRepresentation.isUseSha()) {
list.add(attributeUtility.createAttributeWithArbitraryValues(MDDCConstants.SECURITY_CONFIGURATION, MDDCConstants.SECURITY_CONFIGURATION_FN, "shibboleth.SecurityConfiguration.SHA1"));
}
if (overridesRepresentation.isIgnoreAuthenticationMethod()) {
// this is actually going to be wrong, but it will work for the time being. this should be a bitmask value that we calculate
// TODO: fix
list.add(attributeUtility.createAttributeWithArbitraryValues(MDDCConstants.DISALLOWED_FEATURES, MDDCConstants.DISALLOWED_FEATURES_FN, "0x1"));
}
if (overridesRepresentation.isOmitNotBefore()) {
list.add(attributeUtility.createAttributeWithBooleanValue(MDDCConstants.INCLUDE_CONDITIONS_NOT_BEFORE, MDDCConstants.INCLUDE_CONDITIONS_NOT_BEFORE_FN, false));
}
if (overridesRepresentation.getResponderId() != null && !"".equals(overridesRepresentation.getResponderId())) {
list.add(attributeUtility.createAttributeWithArbitraryValues(MDDCConstants.RESPONDER_ID, MDDCConstants.RESPONDER_ID_FN, overridesRepresentation.getResponderId()));
}
if (overridesRepresentation.getNameIdFormats() != null && overridesRepresentation.getNameIdFormats().size() > 0) {
list.add(attributeUtility.createAttributeWithArbitraryValues(MDDCConstants.NAME_ID_FORMAT_PRECEDENCE, MDDCConstants.NAME_ID_FORMAT_PRECEDENCE_FN, overridesRepresentation.getNameIdFormats()));
}
if (overridesRepresentation.getAuthenticationMethods() != null && overridesRepresentation.getAuthenticationMethods().size() > 0) {
list.add(attributeUtility.createAttributeWithArbitraryValues(MDDCConstants.DEFAULT_AUTHENTICATION_METHODS, MDDCConstants.DEFAULT_AUTHENTICATION_METHODS_FN, overridesRepresentation.getAuthenticationMethods()));
}
getAttributeListFromRelyingPartyOverridesRepresentation(entityDescriptorRepresentation.getRelyingPartyOverrides()).forEach(attribute ->
list.add((edu.internet2.tier.shibboleth.admin.ui.domain.Attribute) attribute)
);
}

// let's map the attribute release
if (entityDescriptorRepresentation.getAttributeRelease() != null && entityDescriptorRepresentation.getAttributeRelease().size() > 0) {
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = ((AttributeBuilder) openSamlObjects.getBuilderFactory().getBuilder(edu.internet2.tier.shibboleth.admin.ui.domain.Attribute.DEFAULT_ELEMENT_NAME)).buildObject();
list.add(attribute);

attribute.setName(MDDCConstants.RELEASE_ATTRIBUTES);

for (String attributeRelease : entityDescriptorRepresentation.getAttributeRelease()) {
XSString xsString = (XSString) openSamlObjects.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
xsString.setValue(attributeRelease);
attribute.getAttributeValues().add(xsString);
}
list.add(getAttributeFromAttributeReleaseList(entityDescriptorRepresentation.getAttributeRelease()));
}

return (List<Attribute>)(List<? extends Attribute>)list;
}

@Override
public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute getAttributeFromAttributeReleaseList(List<String> attributeReleaseList) {
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = ((AttributeBuilder) openSamlObjects
.getBuilderFactory()
.getBuilder(edu.internet2.tier.shibboleth.admin.ui.domain.Attribute.DEFAULT_ELEMENT_NAME))
.buildObject();

attribute.setName(MDDCConstants.RELEASE_ATTRIBUTES);

attributeReleaseList.forEach(attributeRelease -> {
XSString xsString = (XSString) openSamlObjects
.getBuilderFactory()
.getBuilder(XSString.TYPE_NAME)
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
xsString.setValue(attributeRelease);
attribute.getAttributeValues().add(xsString);
});

return attribute;
}

@Override
public List<Attribute> getAttributeListFromAttributeReleaseList(List<String> attributeReleaseList) {
List<edu.internet2.tier.shibboleth.admin.ui.domain.Attribute> attributeList = new ArrayList<>();
Expand Down Expand Up @@ -130,7 +113,4 @@ public List<Attribute> getAttributeListFromRelyingPartyOverridesRepresentation(R

return (List<Attribute>)(List<? extends Attribute>)list;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.util.DefaultUriBuilderFactory
import spock.lang.Specification

/**
* @author Bill Smith (wsmith@unicon.net)
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
class DefaultAuthenticationIntegrationTests extends Specification {

@Autowired
private WebTestClient webClient

def setup() {
this.webClient.webClient.uriBuilderFactory.encodingMode = DefaultUriBuilderFactory.EncodingMode.NONE
}

def "When auth is enabled and an unauth'd request is made, a 302 is returned which points at login"() {
when:
def result = this.webClient
.get()
.uri("/api/entities/http%3A%2F%2Ftest.scaldingspoon.org%2Ftest1")
.exchange()

then:
result
.expectStatus().isEqualTo(302)
.expectHeader().valueMatches("Location", "http://localhost:\\d*/login")
}
}
Loading

0 comments on commit 072c3c3

Please sign in to comment.