Skip to content

Commit

Permalink
Merged in feature/SHIBUI-1058 (pull request #296)
Browse files Browse the repository at this point in the history
Feature/SHIBUI-1058
  • Loading branch information
Jonathan Johnson committed Feb 14, 2019
2 parents 4f71da0 + 22d3f57 commit 6c7f34a
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 129 deletions.
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ dependencies {

// CSV file support
compile 'com.opencsv:opencsv:4.4'

testCompile 'org.skyscreamer:jsonassert:1.5.0'
}

def generatedSrcDir = new File(buildDir, 'generated/src/main/java')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,10 @@ public ResponseEntity<?> update(@RequestBody EntityDescriptorRepresentation edRe
return new ResponseEntity<Void>(HttpStatus.CONFLICT);
}

EntityDescriptor updatedEd =
EntityDescriptor.class.cast(entityDescriptorService.createDescriptorFromRepresentation(edRepresentation));
entityDescriptorService.updateDescriptorFromRepresentation(existingEd, edRepresentation);
existingEd = entityDescriptorRepository.save(existingEd);

updatedEd.setAudId(existingEd.getAudId());
updatedEd.setResourceId(existingEd.getResourceId());
updatedEd.setCreatedDate(existingEd.getCreatedDate());

updatedEd = entityDescriptorRepository.save(updatedEd);

return ResponseEntity.ok().body(entityDescriptorService.createRepresentationFromDescriptor(updatedEd));
return ResponseEntity.ok().body(entityDescriptorService.createRepresentationFromDescriptor(existingEd));
} else {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(HttpStatus.FORBIDDEN,
"You are not authorized to perform the requested operation."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -171,6 +172,16 @@ public SPSSODescriptor getSPSSODescriptor(String s) {
.orElse(null);
}

@Transient
public Optional<SPSSODescriptor> getOptionalSPSSODescriptor(String s) {
return Optional.ofNullable(this.getSPSSODescriptor(s));
}

@Transient
public Optional<SPSSODescriptor> getOptionalSPSSODescriptor() {
return this.getOptionalSPSSODescriptor("");
}

@Override
public AuthnAuthorityDescriptor getAuthnAuthorityDescriptor(String s) {
return authnAuthorityDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.Collections;
import java.util.List;
import java.util.Optional;


@Entity
Expand All @@ -17,4 +19,14 @@ public class Extensions extends AbstractElementExtensibleXMLObject implements or
public List<XMLObject> getOrderedChildren() {
return Collections.unmodifiableList(this.getUnknownXMLObjects());
}

@Transient
public Optional<UIInfo> getOptionalUIInfo() {
List uiinfos = this.getUnknownXMLObjects(UIInfo.DEFAULT_ELEMENT_NAME);
if (uiinfos.size() == 0) {
return Optional.empty();
} else {
return Optional.of((UIInfo) uiinfos.get(0));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Entity
@EqualsAndHashCode(callSuper = true)
Expand Down Expand Up @@ -116,4 +117,9 @@ public List<XMLObject> getOrderedChildren() {

return Collections.unmodifiableList(children);
}

@Transient
public Optional<Extensions> getOptionalExtensions() {
return Optional.ofNullable(this.getExtensions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;

Expand All @@ -21,5 +22,6 @@ public RegexScheme() {
}

@NotNull
@Column(name = "match_regex")
private String match;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService
import edu.internet2.tier.shibboleth.admin.ui.util.RandomGenerator
import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator
import edu.internet2.tier.shibboleth.admin.util.AttributeUtility
import groovy.json.JsonOutput
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.json.JacksonTester
Expand All @@ -34,6 +36,7 @@ import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.DefaultNodeMatcher
import org.xmlunit.diff.ElementSelectors
import spock.lang.Ignore
import spock.lang.Specification

@ContextConfiguration(classes=[CoreShibUiConfiguration, CustomPropertiesConfiguration])
Expand All @@ -55,6 +58,8 @@ class JPAEntityDescriptorServiceImplTests extends Specification {

JacksonTester<EntityDescriptorRepresentation> jacksonTester

ObjectMapper mapper

RandomGenerator generator

@Autowired
Expand All @@ -66,7 +71,8 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
def setup() {
service = new JPAEntityDescriptorServiceImpl(openSamlObjects,
new JPAEntityServiceImpl(openSamlObjects, new AttributeUtility(openSamlObjects), customPropertiesConfiguration), new UserService(roleRepository, userRepository))
JacksonTester.initFields(this, new ObjectMapper())
mapper = new ObjectMapper()
JacksonTester.initFields(this, mapper)
generator = new RandomGenerator()
testObjectGenerator = new TestObjectGenerator()
}
Expand Down Expand Up @@ -764,16 +770,25 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
testRunIndex << (1..5)
}

def "updateDescriptorFromRepresentation throws expected exception"() {
def "updateDescriptorFromRepresentation updates descriptor properly"() {
given:
def randomEntityDescriptor = generateRandomEntityDescriptor()
def entityDescriptorRepresentation = service.createRepresentationFromDescriptor(randomEntityDescriptor)
def updatedEntityDescriptor = generateRandomEntityDescriptor()

//copy values we don't care about asserting (id, entity id, ...)
updatedEntityDescriptor.entityID = randomEntityDescriptor.entityID
updatedEntityDescriptor.resourceId = randomEntityDescriptor.resourceId
updatedEntityDescriptor.elementLocalName = randomEntityDescriptor.elementLocalName

def updatedEntityDescriptorRepresentation = service.createRepresentationFromDescriptor(updatedEntityDescriptor)

when:
service.updateDescriptorFromRepresentation(randomEntityDescriptor, entityDescriptorRepresentation)
service.updateDescriptorFromRepresentation(randomEntityDescriptor, updatedEntityDescriptorRepresentation)

then:
thrown UnsupportedOperationException
def expectedJson = mapper.writeValueAsString(updatedEntityDescriptorRepresentation)
def actualJson = mapper.writeValueAsString(service.createRepresentationFromDescriptor(randomEntityDescriptor))
JSONAssert.assertEquals(expectedJson, actualJson, false)
}

def "createRepresentationFromDescriptor creates a representation containing a version that is a hash of the original object"() {
Expand Down Expand Up @@ -849,6 +864,9 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
ed.setServiceProviderName(generator.randomString(10))
ed.setServiceEnabled(generator.randomBoolean())
ed.setResourceId(generator.randomId())
ed.setElementLocalName(generator.randomString(10))

//TODO: Finish fleshing out this thing

return ed
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.unicon.shibui.pac4j;

import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Optional;

public class Pac4jAuditorAware implements AuditorAware<String> {
@Override
public Optional<String> getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return Optional.empty();
}
return Optional.of(authentication.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
Expand Down Expand Up @@ -93,4 +94,9 @@ public void configure(org.springframework.security.config.annotation.web.builder
web.httpFirewall(firewall);
}
}

@Bean
public AuditorAware<String> defaultAuditorAware() {
return new Pac4jAuditorAware();
}
}
10 changes: 10 additions & 0 deletions pac4j-module/src/test/docker/conf/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
spring:
profiles:
include:
datasource:
platform: mariadb
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://db:3306/shibui
username: shibui
password: shibui
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MariaDBDialect
server:
port: 8443
ssl:
Expand Down
15 changes: 14 additions & 1 deletion pac4j-module/src/test/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
version: "3.7"

services:
db:
image: mariadb
container_name: db
environment:
MYSQL_USER: shibui
MYSQL_PASSWORD: shibui
MYSQL_DATABASE: shibui
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
networks:
- front
ports:
- 3306:3306
shibui:
image: unicon/shibui-pac4j
entrypoint: ["/usr/bin/java", "-Dspring.profiles.active=dev", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-jar", "app.jar"]
Expand All @@ -13,7 +25,8 @@ services:
- ./conf/application.yml:/application.yml
networks:
- front

depends_on:
- db
mailhog:
image: mailhog/mailhog:latest
ports:
Expand Down

0 comments on commit 6c7f34a

Please sign in to comment.