/** * Does resource exist? * * @param location the resource * @return the boolean */ public static boolean doesResourceExist(final String location) { try { return getResourceFrom(location) != null; } catch (final Exception e) { LOGGER.trace(e.getMessage(), e); } return false; }
@SneakyThrows private void buildGroovyMultifactorPolicyInstanceIfNeeded() { if (this.groovyPolicyInstance == null) { val groovyResource = ResourceUtils.getResourceFrom(this.groovyScript); this.groovyPolicyInstance = ScriptingUtils.getObjectInstanceFromGroovyResource(groovyResource, RegisteredServiceMultifactorPolicy.class); } }
@Override public boolean supports(final SamlRegisteredService service) { try { val metadataLocation = service.getMetadataLocation(); val metadataResource = ResourceUtils.getResourceFrom(metadataLocation); return metadataResource instanceof ClassPathResource; } catch (final Exception e) { LOGGER.trace(e.getMessage(), e); } return false; }
@SneakyThrows private void buildGroovyAccessStrategyInstanceIfNeeded() { if (this.groovyStrategyInstance == null) { val groovyResource = ResourceUtils.getResourceFrom(this.groovyScript); this.groovyStrategyInstance = ScriptingUtils.getObjectInstanceFromGroovyResource(groovyResource, RegisteredServiceAccessStrategy.class); } } }
@Override public boolean supports(final SamlRegisteredService service) { try { val metadataLocation = service.getMetadataLocation(); val metadataResource = ResourceUtils.getResourceFrom(metadataLocation); return metadataResource instanceof FileSystemResource; } catch (final Exception e) { LOGGER.trace(e.getMessage(), e); } return false; }
@Override public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) { try { final Object[] args = {attributes, LOGGER, principal, service}; val resource = ResourceUtils.getResourceFrom(this.groovyScript); return ScriptingUtils.executeGroovyScript(resource, args, Map.class, true); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } LOGGER.warn("Groovy script [{}] does not exist or cannot be loaded", groovyScript); return new HashMap<>(0); } }
@Override protected Map<String, Object> getAttributesForSamlRegisteredService(final Map<String, Object> attributes, final SamlRegisteredService service, final ApplicationContext applicationContext, final SamlRegisteredServiceCachingMetadataResolver resolver, final SamlRegisteredServiceServiceProviderMetadataFacade facade, final EntityDescriptor entityDescriptor) { try { final Object[] args = {attributes, service, resolver, facade, entityDescriptor, applicationContext, LOGGER}; val resource = ResourceUtils.getResourceFrom(this.groovyScript); return ScriptingUtils.executeGroovyScript(resource, args, Map.class, true); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } LOGGER.warn("Groovy script [{}] does not exist or cannot be loaded", groovyScript); return new HashMap<>(0); } }
private String resolveUsernameFromExternalGroovyScript(final Principal principal, final Service service, final String scriptFile) { try { LOGGER.debug("Found groovy script to execute"); val resourceFrom = ResourceUtils.getResourceFrom(scriptFile); val script = IOUtils.toString(resourceFrom.getInputStream(), StandardCharsets.UTF_8); val result = getGroovyAttributeValue(principal, script); if (result != null) { LOGGER.debug("Found username [{}] from script [{}]", result, scriptFile); return result.toString(); } } catch (final IOException e) { LOGGER.error(e.getMessage(), e); } LOGGER.warn("Groovy script [{}] returned no value for username attribute. Fallback to default [{}]", this.groovyScript, principal.getId()); return principal.getId(); }
@Override public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service) { try { val metadataLocation = service.getMetadataLocation(); LOGGER.info("Loading SAML metadata via [{}]", metadataLocation); val metadataResource = ResourceUtils.getResourceFrom(metadataLocation); final Object[] args = {service, this.configBean, this.samlIdPProperties, LOGGER}; val metadataResolver = ScriptingUtils.executeGroovyScript(metadataResource, args, MetadataResolver.class, true); if (metadataResolver != null) { return CollectionUtils.wrap(metadataResolver); } } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return new ArrayList<>(0); }
@Override public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) { if (isSurrogateAuthenticationSession(principalAttributes)) { try { final Object[] args = {principal, principalAttributes, LOGGER}; val resource = ResourceUtils.getResourceFrom(this.groovyScript); return ScriptingUtils.executeGroovyScript(resource, args, Boolean.class, true); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return false; } return super.doPrincipalAttributesAllowServiceAccess(principal, principalAttributes); } }
val resourceFrom = ResourceUtils.getResourceFrom(scriptFile); val theScriptFile = resourceFrom.getFile(); if (theScriptFile.exists()) {
@Override public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service) { try { val metadataLocation = service.getMetadataLocation(); LOGGER.info("Loading SAML metadata from [{}]", metadataLocation); val metadataResource = ResourceUtils.getResourceFrom(metadataLocation); val metadataFile = metadataResource.getFile(); val metadataResolver = getMetadataResolver(metadataResource, metadataFile); configureAndInitializeSingleMetadataResolver(metadataResolver, service); return CollectionUtils.wrap(metadataResolver); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return new ArrayList<>(0); }
@Override public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service) { val metadataLocation = service.getMetadataLocation(); LOGGER.info("Loading SAML metadata from [{}]", metadataLocation); try (val in = ResourceUtils.getResourceFrom(metadataLocation).getInputStream()) { LOGGER.debug("Parsing metadata from [{}]", metadataLocation); val document = this.configBean.getParserPool().parse(in); val metadataRoot = document.getDocumentElement(); val metadataProvider = new DOMMetadataResolver(metadataRoot); configureAndInitializeSingleMetadataResolver(metadataProvider, service); return CollectionUtils.wrap(metadataProvider); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } return new ArrayList<>(0); }
/** * Extract private key from resource private key. * * @param signingSecretKey the signing secret key * @return the private key */ @SneakyThrows public static PrivateKey extractPrivateKeyFromResource(final String signingSecretKey) { LOGGER.debug("Attempting to extract private key..."); val resource = ResourceUtils.getResourceFrom(signingSecretKey); val factory = new PrivateKeyFactoryBean(); factory.setAlgorithm(RsaKeyUtil.RSA); factory.setLocation(resource); factory.setSingleton(false); return factory.getObject(); }
/** * Extract public key from resource public key. * * @param secretKeyToUse the secret key to use * @return the public key */ @SneakyThrows public static PublicKey extractPublicKeyFromResource(final String secretKeyToUse) { LOGGER.debug("Attempting to extract public key from [{}]...", secretKeyToUse); val resource = ResourceUtils.getResourceFrom(secretKeyToUse); val factory = new PublicKeyFactoryBean(); factory.setAlgorithm(RsaKeyUtil.RSA); factory.setResource(resource); factory.setSingleton(false); return factory.getObject(); }