Skip to content

Commit

Permalink
Merge branch 'master' into SHIBUI-808
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/build.gradle
  • Loading branch information
jj committed Sep 25, 2018
2 parents 1addbbd + bdb6bd5 commit 857dda5
Show file tree
Hide file tree
Showing 175 changed files with 3,324 additions and 5,410 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pipeline {
}
}
steps {
sh '''./gradlew docker
sh '''./gradlew docker -x test
'''
}
}
Expand All @@ -36,7 +36,7 @@ pipeline {
steps {
sh '''
docker stop shibui || true && docker rm shibui || true
docker run -d --restart always --name shibui -p 8080:8080 -v /etc/shibui/application.properties:/application.properties unicon/shibui:latest
docker run -d --restart always --name shibui -p 8080:8080 -v /etc/shibui/application.properties:/application.properties -m 3GB --memory-swap=3GB unicon/shibui:latest
'''
}
}
Expand Down
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ dependencies {
// TODO: figure out what this should really be
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'

//Spring Configuration Annotation Processor - makes IntelliJ happy about @ConfigurationProperties
compileOnly "org.springframework.boot:spring-boot-configuration-processor"

// lucene deps
['core', 'analyzers-common', 'queryparser'].each {
compile "org.apache.lucene:lucene-${it}:${project.'lucene.version'}"
Expand All @@ -120,6 +123,7 @@ dependencies {

//Swagger
compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox:springfox-swagger-ui:2.9.2'

testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.configuration;

import com.fasterxml.jackson.databind.Module;
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.repository.MetadataResolverRepository;
Expand Down Expand Up @@ -28,6 +29,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
Expand All @@ -41,6 +43,7 @@
import javax.servlet.http.HttpServletRequest;

@Configuration
@EnableConfigurationProperties(CustomAttributesConfiguration.class)
public class CoreShibUiConfiguration {
private static final Logger logger = LoggerFactory.getLogger(CoreShibUiConfiguration.class);

Expand Down Expand Up @@ -168,4 +171,14 @@ public DirectoryService directoryService() {
public LuceneUtility luceneUtility(DirectoryService directoryService) {
return new LuceneUtility(directoryService);
}

@Bean
public CustomAttributesConfiguration customAttributesConfiguration() {
return new CustomAttributesConfiguration();
}

@Bean
public Module stringTrimModule() {
return new StringTrimModule();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.internet2.tier.shibboleth.admin.ui.configuration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author Bill Smith (wsmith@unicon.net)
*/
@Configuration
@ConfigurationProperties(prefix="custom")
public class CustomAttributesConfiguration {

private List<? extends Map<String, String>> attributes = new ArrayList<>();

public List<? extends Map<String, String>> getAttributes() {
return attributes;
}

public void setAttributes(List<? extends Map<String, String>> attributes) {
this.attributes = attributes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.internet2.tier.shibboleth.admin.ui.configuration;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.io.IOException;

/**
* @author Bill Smith (wsmith@unicon.net)
*
* Adapted from Maciej Marczuk's answer on Stack Overflow here:
* https://stackoverflow.com/questions/6852213/can-jackson-be-configured-to-trim-leading-trailing-whitespace-from-all-string-pr/33765854#33765854
*/
public class StringTrimModule extends SimpleModule {

public StringTrimModule() {
addDeserializer(String.class, new StdScalarDeserializer<String>(String.class) {
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
return jsonParser.getValueAsString().trim();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package edu.internet2.tier.shibboleth.admin.ui.controller;

import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomAttributesConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* @author Bill Smith (wsmith@unicon.net)
*/
@Controller
@RequestMapping(value = "/api")
public class ConfigurationController {

@Autowired
CustomAttributesConfiguration customAttributesConfiguration;

@GetMapping(value = "/customAttributes")
public ResponseEntity<?> getCustomAttributes() {
return ResponseEntity.ok(customAttributesConfiguration.getAttributes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Bill Smith (wsmith@unicon.net)
Expand All @@ -22,4 +28,33 @@ public class InternationalizationMessagesController {
public ResponseEntity<?> getAll(Locale locale) {
return ResponseEntity.ok(messageSource.getMessagesMap(locale));
}

@GetMapping(value = "/available")
public ResponseEntity<?> getAvailableLocales() {
Set<ResourceBundle> supportedLocaleResourceBundles = getResourceBundles();
Set<Locale> supportedLocales = supportedLocaleResourceBundles
.stream()
.map(ResourceBundle::getLocale)
.collect(Collectors.toSet());
return ResponseEntity.ok(supportedLocales);
}

/**
* Get all available resource bundles in i18n/messages that matches a locale supported by this JRE.
*
* @return a set of resource bundles for supported locales for this system
*/
private Set<ResourceBundle> getResourceBundles() {
Set<ResourceBundle> resourceBundles = new HashSet<>();

for (Locale locale : Locale.getAvailableLocales()) {
try {
resourceBundles.add(ResourceBundle.getBundle("i18n/messages", locale));
} catch (MissingResourceException e) {
// do nothing
}
}

return Collections.unmodifiableSet(resourceBundles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ public static List<String> getAttributeReleaseListFromAttributeList(List<Attribu
.filter(attribute -> attribute.getName().equals(MDDCConstants.RELEASE_ATTRIBUTES))
.collect(Collectors.toList());

if (releaseAttributes.size() != 1) {
// TODO: What do we do if there is more than one?
}
if (releaseAttributes.size() == 0) {
return new ArrayList<>();
} else {
return getStringListOfAttributeValues(releaseAttributes.get(0).getAttributeValues());
List<String> attributeValues = new ArrayList<>();
for (Attribute attribute : releaseAttributes) {
attributeValues.addAll(getStringListOfAttributeValues(attribute.getAttributeValues()));
}
return attributeValues;
}

public static boolean getBooleanValueOfAttribute(Attribute attribute) {
Expand Down
28 changes: 28 additions & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
custom:
attributes:
# Default attributes
- name: eduPersonPrincipalName
displayName: label.attribute-eduPersonPrincipalName
- name: uid
displayName: label.attribute-uid
- name: mail
displayName: label.attribute-mail
- name: surname
displayName: label.attribute-surname
- name: givenName
displayName: label.attribute-givenName
- name: eduPersonAffiliation
displayName: label.attribute-eduPersonAffiliation
- name: eduPersonScopedAffiliation
displayName: label.attribute-eduPersonScopedAffiliation
- name: eduPersonPrimaryAffiliation
displayName: label.attribute-eduPersonPrimaryAffiliation
- name: eduPersonEntitlement
displayName: label.attribute-eduPersonEntitlement
- name: eduPersonAssurance
displayName: label.attribute-eduPersonAssurance
- name: eduPersonUniqueId
displayName: label.attribute-eduPersonUniqueId
- name: employeeNumber
displayName: label.attribute-employeeNumber
# Custom attributes
Loading

0 comments on commit 857dda5

Please sign in to comment.