/** * Signs the specified {@link SignableSAMLObject} with the specified {@link Credential} and * {@code signatureAlgorithm}, and then encodes the object into a base64 string. */ static String toSignedBase64(SignableSAMLObject signableObj, Credential signingCredential, String signatureAlgorithm) { sign(signableObj, signingCredential, signatureAlgorithm); final String messageStr = nodeToString(serialize(signableObj)); return Base64.getEncoder().encodeToString(messageStr.getBytes(StandardCharsets.UTF_8)); }
/** * Converts the supplied duration to milliseconds and divides it by the divisor. Useful for modifying durations * while resolving property replacement. * * @param duration string format * @param divisor to modify the duration with * * @return result of the division */ public static long buildDuration(final String duration, final long divisor) { return DOMTypeSupport.durationToLong(duration) / divisor; }
public OpenSamlImplementation(Clock time) { super(time); this.parserPool = new BasicParserPool(); }
private static void configureParserPool() throws Throwable { BasicParserPool pp = new BasicParserPool(); pp.setMaxPoolSize(50); pp.initialize(); providerRegistry.setParserPool(pp); }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { AssertionIDRef assertionIDRef = (AssertionIDRef) samlObject; ElementSupport.appendTextContent(domElement, assertionIDRef.getAssertionID()); } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException { XSQName qname = (XSQName) xmlObject; ElementSupport.appendTextContent(domElement, QNameSupport.qnameToContentString(qname.getValue())); } }
/** * Encodes the specified {@code message} into a deflated base64 string. */ static String toDeflatedBase64(SAMLObject message) { requireNonNull(message, "message"); final String messageStr; try { messageStr = nodeToString(XMLObjectSupport.marshall(message)); } catch (MarshallingException e) { throw new SamlException("failed to serialize a SAML message", e); } final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); try (DeflaterOutputStream deflaterStream = new DeflaterOutputStream(Base64.getEncoder().wrap(bytesOut), new Deflater(Deflater.DEFLATED, true))) { deflaterStream.write(messageStr.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new SamlException("failed to deflate a SAML message", e); } return bytesOut.toString(); }
/** {@inheritDoc} */ protected void marshallElementContent(final XMLObject xmlObject, final Element domElement) throws MarshallingException { final ScopedValue scopedValue = (ScopedValue) xmlObject; ElementSupport.appendTextContent(domElement, scopedValue.getValue()); } }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); expandedStorageThreshold = 1024 * 1024; }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException { XSQName qname = (XSQName) xmlObject; ElementSupport.appendTextContent(domElement, QNameSupport.qnameToContentString(qname.getValue())); } }
@Override public HttpResponse serve(ServiceRequestContext ctx, AggregatedHttpMessage msg, String defaultHostname, SamlPortConfig portConfig) { final HttpData metadata = metadataMap.computeIfAbsent(defaultHostname, h -> { try { final Element element = SamlMessageUtil.serialize(buildMetadataEntityDescriptorElement(h, portConfig)); final HttpData newMetadata = HttpData.ofUtf8(nodeToString(element)); logger.debug("SAML service provider metadata has been prepared for: {}.", h); return newMetadata; } catch (Throwable cause) { logger.warn("{} Unexpected metadata request.", ctx, cause); return HttpData.EMPTY_DATA; } }); if (metadata != HttpData.EMPTY_DATA) { return HttpResponse.of(HTTP_HEADERS, metadata); } else { return HttpResponse.of(HttpStatus.NOT_FOUND); } }
/** {@inheritDoc} */ protected void marshallElementContent(final XMLObject xmlObject, final Element domElement) throws MarshallingException { final Scope shibMDScope = (Scope) xmlObject; ElementSupport.appendTextContent(domElement, shibMDScope.getValue()); } }
/** Constructor. */ public ConsentFlowDescriptor() { lifetime = DOMTypeSupport.durationToLong("P1Y"); }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { EmailAddress address = (EmailAddress) samlObject; if (address.getAddress() != null) { ElementSupport.appendTextContent(domElement, address.getAddress()); } } }
@Override public long toMillis(Duration duration) { if (isNull(duration)) { return -1; } else { return DOMTypeSupport.durationToLong(duration); } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { StatusMessage statusMessage = (StatusMessage) samlObject; if (statusMessage.getMessage() != null) { ElementSupport.appendTextContent(domElement, statusMessage.getMessage()); } } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { AttributeProfile profile = (AttributeProfile) samlObject; if (profile.getProfileURI() != null) { ElementSupport.appendTextContent(domElement, profile.getProfileURI()); } } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { SessionIndex si = (SessionIndex) samlObject; if (si.getSessionIndex() != null) { ElementSupport.appendTextContent(domElement, si.getSessionIndex()); } } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { Company company = (Company) samlObject; if (company.getName() != null) { ElementSupport.appendTextContent(domElement, company.getName()); } } }
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject samlObject, Element domElement) throws MarshallingException { LocalizedName name = (LocalizedName) samlObject; if (name.getValue() != null) { ElementSupport.appendTextContent(domElement, name.getValue()); } } }