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;
}
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));
}
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);
}
}
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();
}
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);
}
}
}
}
Aggregations