Search in sources :

Example 6 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class CoreSamlConfiguration method parserPool.

@SneakyThrows
@Bean(name = "shibboleth.ParserPool", initMethod = "initialize")
public BasicParserPool parserPool() {
    final BasicParserPool pool = new BasicParserPool();
    pool.setMaxPoolSize(POOL_SIZE);
    pool.setCoalescing(true);
    pool.setIgnoreComments(true);
    pool.setXincludeAware(false);
    pool.setExpandEntityReferences(false);
    pool.setIgnoreComments(true);
    pool.setNamespaceAware(true);
    final Map<String, Object> attributes = new HashMap<>();
    final Class clazz = ClassUtils.getClass(casProperties.getSamlCore().getSecurityManager());
    attributes.put("http://apache.org/xml/properties/security-manager", clazz.getDeclaredConstructor().newInstance());
    pool.setBuilderAttributes(attributes);
    final Map<String, Boolean> features = new HashMap<>();
    features.put("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
    features.put("http://apache.org/xml/features/validation/schema/normalized-value", Boolean.FALSE);
    features.put("http://javax.xml.XMLConstants/feature/secure-processing", Boolean.TRUE);
    features.put("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
    features.put("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
    pool.setBuilderFeatures(features);
    return pool;
}
Also used : HashMap(java.util.HashMap) BasicParserPool(net.shibboleth.utilities.java.support.xml.BasicParserPool) SneakyThrows(lombok.SneakyThrows) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class FileSystemSamlIdPMetadataGenerator method buildSelfSignedSigningCert.

/**
 * Build self signed signing cert.
 */
@SneakyThrows
protected void buildSelfSignedSigningCert() {
    final File signingCert = this.samlIdPMetadataLocator.getSigningCertificate().getFile();
    if (signingCert.exists()) {
        FileUtils.forceDelete(signingCert);
    }
    final File signingKey = this.samlIdPMetadataLocator.getSigningKey().getFile();
    if (signingKey.exists()) {
        FileUtils.forceDelete(signingKey);
    }
    this.samlIdPCertificateAndKeyWriter.writeCertificateAndKey(Files.newBufferedWriter(signingKey.toPath(), StandardCharsets.UTF_8), Files.newBufferedWriter(signingCert.toPath(), StandardCharsets.UTF_8));
}
Also used : File(java.io.File) SneakyThrows(lombok.SneakyThrows)

Example 8 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class FileSystemSamlIdPMetadataGenerator method buildMetadataGeneratorParameters.

/**
 * Build metadata generator parameters by passing the encryption,
 * signing and back-channel certs to the parameter generator.
 */
@SneakyThrows
protected void buildMetadataGeneratorParameters() {
    final Resource template = this.resourceLoader.getResource("classpath:/template-idp-metadata.xml");
    String signingCert = FileUtils.readFileToString(this.samlIdPMetadataLocator.getSigningCertificate().getFile(), StandardCharsets.UTF_8);
    signingCert = StringUtils.remove(signingCert, BEGIN_CERTIFICATE);
    signingCert = StringUtils.remove(signingCert, END_CERTIFICATE).trim();
    String encryptionCert = FileUtils.readFileToString(this.samlIdPMetadataLocator.getEncryptionCertificate().getFile(), StandardCharsets.UTF_8);
    encryptionCert = StringUtils.remove(encryptionCert, BEGIN_CERTIFICATE);
    encryptionCert = StringUtils.remove(encryptionCert, END_CERTIFICATE).trim();
    try (StringWriter writer = new StringWriter()) {
        IOUtils.copy(template.getInputStream(), writer, StandardCharsets.UTF_8);
        final String metadata = writer.toString().replace("${entityId}", this.entityId).replace("${scope}", this.scope).replace("${idpEndpointUrl}", getIdPEndpointUrl()).replace("${encryptionKey}", encryptionCert).replace("${signingKey}", signingCert);
        writeMetadata(metadata);
    }
}
Also used : StringWriter(java.io.StringWriter) Resource(org.springframework.core.io.Resource) SneakyThrows(lombok.SneakyThrows)

Example 9 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class CasConfigurationPropertiesEnvironmentManager method savePropertyForStandaloneProfile.

/**
 * Save property for standalone profile.
 *
 * @param pair the pair
 */
@SneakyThrows
public void savePropertyForStandaloneProfile(final Pair<String, String> pair) {
    final File file = getStandaloneProfileConfigurationDirectory();
    final Parameters params = new Parameters();
    final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.properties().setFile(new File(file, getApplicationName() + ".properties")));
    final Configuration config = builder.getConfiguration();
    config.setProperty(pair.getKey(), pair.getValue());
    builder.save();
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) SneakyThrows(lombok.SneakyThrows)

Example 10 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class ConfigurationMetadataGenerator method parseCompilationUnit.

@SneakyThrows
private void parseCompilationUnit(final Set<ConfigurationMetadataProperty> collectedProps, final Set<ConfigurationMetadataProperty> collectedGroups, final ConfigurationMetadataProperty p, final String typePath, final String typeName, final boolean indexNameWithBrackets) {
    try (InputStream is = new FileInputStream(typePath)) {
        final CompilationUnit cu = JavaParser.parse(is);
        new FieldVisitor(collectedProps, collectedGroups, indexNameWithBrackets, typeName).visit(cu, p);
        if (cu.getTypes().size() > 0) {
            final ClassOrInterfaceDeclaration decl = ClassOrInterfaceDeclaration.class.cast(cu.getType(0));
            for (int i = 0; i < decl.getExtendedTypes().size(); i++) {
                final ClassOrInterfaceType parentType = decl.getExtendedTypes().get(i);
                final Class parentClazz = locatePropertiesClassForType(parentType);
                final String parentTypePath = buildTypeSourcePath(parentClazz.getName());
                parseCompilationUnit(collectedProps, collectedGroups, p, parentTypePath, parentClazz.getName(), indexNameWithBrackets);
            }
        }
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) FileInputStream(java.io.FileInputStream) ValueHint(org.springframework.boot.configurationmetadata.ValueHint) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)592 lombok.val (lombok.val)292 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)59 HashMap (java.util.HashMap)51 List (java.util.List)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 LinkedHashMap (java.util.LinkedHashMap)29 File (java.io.File)27 Collectors (java.util.stream.Collectors)25 Path (java.nio.file.Path)24 IOException (java.io.IOException)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 URL (java.net.URL)20 Slf4j (lombok.extern.slf4j.Slf4j)20 InputStream (java.io.InputStream)19 Map (java.util.Map)19 Cleanup (lombok.Cleanup)17 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)16 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)16