Java Code Examples for org.opensaml.xml.util.DatatypeHelper#safeTrimOrNullString()
The following examples show how to use
org.opensaml.xml.util.DatatypeHelper#safeTrimOrNullString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSSecurityHelper.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Gets the <code>wsu:Id</code> attribute from a given SOAP object. * * @param soapObject the SOAP object to add the attribute to * * @return the value of the Id attribute, or null if not present */ public static String getWSUId(XMLObject soapObject) { String value = null; if (soapObject instanceof IdBearing) { value = DatatypeHelper.safeTrimOrNullString(((IdBearing)soapObject).getWSUId()); if (value != null) { return value; } } if (soapObject instanceof AttributeExtensibleXMLObject) { value = DatatypeHelper.safeTrimOrNullString(((AttributeExtensibleXMLObject)soapObject) .getUnknownAttributes().get(IdBearing.WSU_ID_ATTR_NAME)); return value; } return null; }
Example 2
Source File: XMLConfigurator.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Constructs an instance of the given class. * * @param configuration the current configuration element * * @return an instance of the given class * * @throws ConfigurationException thrown if the class can not be instaniated */ protected Object createClassInstance(Element configuration) throws ConfigurationException { String className = configuration.getAttributeNS(null, "className"); className = DatatypeHelper.safeTrimOrNullString(className); if (className == null) { return null; } try { log.trace("Creating instance of {}", className); ClassLoader classLoader = this.getClass().getClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } Class clazz = classLoader.loadClass(className); Constructor constructor = clazz.getConstructor(); return constructor.newInstance(); } catch (Exception e) { log.error("Can not create instance of " + className, e); throw new ConfigurationException("Can not create instance of " + className, e); } }
Example 3
Source File: SOAPHelper.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Gets the <code>soap11:actor</code> attribute from a given SOAP object. * * @param soapObject the SOAP object to add the attribute to * * @return the value of the actor attribute, or null if not present */ public static String getSOAP11ActorAttribute(XMLObject soapObject) { String value = null; if (soapObject instanceof ActorBearing) { value = DatatypeHelper.safeTrimOrNullString(((ActorBearing) soapObject).getSOAP11Actor()); if (value != null) { return value; } } if (soapObject instanceof AttributeExtensibleXMLObject) { value = DatatypeHelper.safeTrimOrNullString(((AttributeExtensibleXMLObject) soapObject) .getUnknownAttributes().get(ActorBearing.SOAP11_ACTOR_ATTR_NAME)); return value; } return null; }
Example 4
Source File: BaseSAML1MessageDecoder.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Extract the issuer, and populate message context, from the Resource attribute of the Attribute query if * {@link #useQueryResourceAsEntityId} is true. * * @param messageContext current message context * @param query query to extract resource name from */ protected void extractAttributeQueryInfo(SAMLMessageContext messageContext, AttributeQuery query) { if (useQueryResourceAsEntityId) { log.debug("Attempting to extract issuer from SAML 1 AttributeQuery Resource attribute"); String resource = DatatypeHelper.safeTrimOrNullString(query.getResource()); if (resource != null) { messageContext.setInboundMessageIssuer(resource); log.debug("Extracted issuer from SAML 1.x AttributeQuery: {}", resource); } } }
Example 5
Source File: RoleDescriptorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public void removeSupportedProtocol(String protocol) { protocol = DatatypeHelper.safeTrimOrNullString(protocol); if (protocol != null && supportedProtocols.contains(protocol)) { releaseThisandParentDOM(); supportedProtocols.remove(protocol); } }
Example 6
Source File: X509KeyManagerX509CredentialAdapter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Constructor. * * @param manager wrapped key manager * @param alias alias used to reference the credential in the key manager */ public X509KeyManagerX509CredentialAdapter(X509KeyManager manager, String alias) { if (manager == null) { throw new IllegalArgumentException("Key manager may not be null"); } keyManager = manager; credentialAlias = DatatypeHelper.safeTrimOrNullString(alias); if (credentialAlias == null) { throw new IllegalArgumentException("Entity alias may not be null"); } }
Example 7
Source File: HttpResource.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Constructor. * * @param resource HTTP(S) URL of the resource * @param resourceFilter filter to apply to this resource * * @deprecated use {@link #setResourceFilter(ResourceFilter)} instead */ public HttpResource(String resource, ResourceFilter resourceFilter) { super(resourceFilter); resourceUrl = DatatypeHelper.safeTrimOrNullString(resource); if (resourceUrl == null) { throw new IllegalArgumentException("Resource URL may not be null or empty"); } httpClient = new HttpClient(); }
Example 8
Source File: NamespaceManager.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Build a {@link Namespace} instance from a {@link QName}. * * @param name the source QName * @return a Namespace built using the information in the QName */ private Namespace buildNamespace(QName name) { String uri = DatatypeHelper.safeTrimOrNullString(name.getNamespaceURI()); if (uri == null) { throw new IllegalArgumentException("A non-empty namespace URI must be supplied"); } String prefix = DatatypeHelper.safeTrimOrNullString(name.getPrefix()); return new Namespace(uri, prefix); }
Example 9
Source File: RelatesToMarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { RelatesTo relatesTo = (RelatesTo) xmlObject; String relationshipType = DatatypeHelper.safeTrimOrNullString(relatesTo.getRelationshipType()); if (relationshipType != null) { domElement.setAttributeNS(null, RelatesTo.RELATIONSHIP_TYPE_ATTRIB_NAME, relationshipType); } XMLHelper.marshallAttributeMap(relatesTo.getUnknownAttributes(), domElement); }
Example 10
Source File: HTTPArtifactDecoder.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Process the incoming artifact by decoding the artifacts, dereferencing it from the artifact issuer and * storing the resulting protocol message in the message context. * * @param samlMsgCtx current message context * * @throws MessageDecodingException thrown if there is a problem decoding or dereferencing the artifact */ protected void processArtifact(SAMLMessageContext samlMsgCtx) throws MessageDecodingException { HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport(); String encodedArtifact = DatatypeHelper.safeTrimOrNullString(inTransport.getParameterValue("SAMLart")); if (encodedArtifact == null) { log.error("URL SAMLart parameter was missing or did not contain a value."); throw new MessageDecodingException("URL TARGET parameter was missing or did not contain a value."); } // TODO decode artifact; resolve issuer resolution endpoint; dereference using ArtifactResolve // over synchronous backchannel binding; store resultant protocol message as the inbound SAML message. }
Example 11
Source File: SOAPHelper.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Gets the <code>soap12:role</code>. * * @param soapObject the SOAP object which may contain the role * * @return the role or null if it is not set on the object */ public static String getSOAP12RoleAttribute(XMLObject soapObject) { String role = null; if (soapObject instanceof org.opensaml.ws.soap.soap12.RoleBearing) { role = ((org.opensaml.ws.soap.soap12.RoleBearing) soapObject).getSOAP12Role(); } if (role == null && soapObject instanceof AttributeExtensibleXMLObject) { role = DatatypeHelper.safeTrimOrNullString(((AttributeExtensibleXMLObject) soapObject) .getUnknownAttributes().get( org.opensaml.ws.soap.soap12.RoleBearing.SOAP12_ROLE_ATTR_LOCAL_NAME)); } return role; }
Example 12
Source File: SchemaValidationFilter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Constructor. * * @param extensionSchemas classpath location of metadata extension schemas, may be null */ public SchemaValidationFilter(String[] extensionSchemas) { if (extensionSchemas != null) { for (String extension : extensionSchemas) { extension = DatatypeHelper.safeTrimOrNullString(extension); if (extension != null) { SAMLSchemaBuilder.addExtensionSchema(extension); } } } }
Example 13
Source File: XSBooleanValue.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Parses a string meant to represent a boolean. If the string is "1" or "0" the returned object will use a numeric * representation and have a value of TRUE or FALSE, respectively. If the string is "true" the returned object will * use a lexical representation and have a value of TRUE. If the string is anything else the returned object will * use a lexical representation and have a value of FALSE. * * @param booleanString the string to parse * * @return the boolean value */ public static XSBooleanValue valueOf(String booleanString) { String trimmedBooleanString = DatatypeHelper.safeTrimOrNullString(booleanString); if (trimmedBooleanString != null) { if (trimmedBooleanString.equals("1")) { return new XSBooleanValue(Boolean.TRUE, true); } else if (trimmedBooleanString.equals("0")) { return new XSBooleanValue(Boolean.FALSE, true); } else if (trimmedBooleanString.equals("true")) { return new XSBooleanValue(Boolean.TRUE, false); } } return new XSBooleanValue(Boolean.FALSE, false); }
Example 14
Source File: Decrypter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Build decryption key credential criteria according to information in the encrypted type object. * * @param encryptedType the encrypted type from which to deduce decryption key criteria * @return a set of credential criteria pertaining to the decryption key */ private Set<Criteria> buildKeyCriteria(EncryptedType encryptedType) { EncryptionMethod encMethod = encryptedType.getEncryptionMethod(); if (encMethod == null) { // This element is optional return Collections.emptySet(); } String encAlgorithmURI = DatatypeHelper.safeTrimOrNullString(encMethod.getAlgorithm()); if (encAlgorithmURI == null) { return Collections.emptySet(); } Set<Criteria> critSet = new HashSet<Criteria>(2); KeyAlgorithmCriteria algoCrit = buildKeyAlgorithmCriteria(encAlgorithmURI); if (algoCrit != null) { critSet.add(algoCrit); log.debug("Added decryption key algorithm criteria: {}", algoCrit.getKeyAlgorithm()); } KeyLengthCriteria lengthCrit = buildKeyLengthCriteria(encAlgorithmURI); if (lengthCrit != null) { critSet.add(lengthCrit); log.debug("Added decryption key length criteria from EncryptionMethod algorithm URI: {}", lengthCrit .getKeyLength()); } else { if (encMethod.getKeySize() != null && encMethod.getKeySize().getValue() != null) { lengthCrit = new KeyLengthCriteria(encMethod.getKeySize().getValue()); critSet.add(lengthCrit); log.debug("Added decryption key length criteria from EncryptionMethod/KeySize: {}", lengthCrit .getKeyLength()); } } return critSet; }
Example 15
Source File: NamespaceManager.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Add the prefixes from a collection of namespaces to a set of prefixes. The * value used to represent the default namespace will be normalized to {@link NamespaceManager#DEFAULT_NS_TOKEN}. * * @param prefixes the set of prefixes to which to add * @param namespaces the source set of Namespaces */ private void addPrefixes(Set<String> prefixes, Collection<Namespace> namespaces) { for (Namespace ns : namespaces) { String prefix = DatatypeHelper.safeTrimOrNullString(ns.getNamespacePrefix()); if (prefix == null) { prefix = DEFAULT_NS_TOKEN; } prefixes.add(prefix); } }
Example 16
Source File: X509DigestCriteria.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Set the digest algorithm. * * @param alg the digest algorithm to set */ public void setAlgorithm(String alg) { if (DatatypeHelper.isEmpty(alg)) { throw new IllegalArgumentException("Digest algorithm criteria value cannot be null or empty"); } algorithm = DatatypeHelper.safeTrimOrNullString(alg); }
Example 17
Source File: OpenHTTPPostSimpleSignDecoder.java From MaxKey with Apache License 2.0 | 4 votes |
/** * Check the validity of the SAML protocol message receiver endpoint against * requirements indicated in the message. * * @param messageContext * current message context * * @throws SecurityException * thrown if the message Destination attribute is invalid with * respect to the receiver's endpoint * @throws MessageDecodingException * thrown if there is a problem decoding and processing the * message Destination or receiver endpoint information */ @Override @SuppressWarnings("rawtypes") protected void checkEndpointURI(SAMLMessageContext messageContext) throws SecurityException, MessageDecodingException { log.debug("Checking SAML message intended destination endpoint against receiver endpoint"); String messageDestination = DatatypeHelper .safeTrimOrNullString(getIntendedDestinationEndpointURI(messageContext)); boolean bindingRequires = isIntendedDestinationEndpointURIRequired(messageContext); if (messageDestination == null) { if (bindingRequires) { log.error("SAML message intended destination endpoint URI required by binding was empty"); throw new SecurityException("SAML message intended destination (required by binding) was not present"); } else { log.debug("SAML message intended destination endpoint in message was empty, not required by binding, skipping"); return; } } String receiverEndpoint = DatatypeHelper.safeTrimOrNullString(getActualReceiverEndpointURI(messageContext)); log.debug("Intended message destination endpoint: {}",messageDestination); log.debug("Actual message receiver endpoint: {}", receiverEndpoint); // 协议头统一(http或https,需要和destination统一) if (messageDestination.indexOf("/") != -1 && receiverEndpoint.indexOf("/") != -1) { if (!messageDestination.substring(0,messageDestination.indexOf("/")) .equalsIgnoreCase(receiverEndpoint.substring(0,receiverEndpoint.indexOf("/")))) { receiverEndpoint = messageDestination.substring(0,messageDestination.indexOf("/")) + receiverEndpoint.substring(receiverEndpoint.indexOf("/")); } } boolean matched = compareEndpointURIs(messageDestination, receiverEndpoint); if (!matched) { log.error("SAML message intended destination endpoint '{}' did not match the recipient endpoint '{}'", messageDestination, receiverEndpoint); throw new SecurityException("SAML message intended destination endpoint did not match recipient endpoint"); } else { log.debug("SAML message intended destination endpoint matched recipient endpoint"); } }
Example 18
Source File: BasicSAMLMessageContext.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void setLocalEntityId(String id) { localEntityId = DatatypeHelper.safeTrimOrNullString(id); }
Example 19
Source File: BasicSAMLMessageContext.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void setOutboundSAMLMessageId(String id) { outboundSAMLMessageId = DatatypeHelper.safeTrimOrNullString(id); }
Example 20
Source File: AbstractXMLObject.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void setSchemaLocation(String location) { schemaLocation = DatatypeHelper.safeTrimOrNullString(location); manageQualifiedAttributeNamespace(XMLConstants.XSI_SCHEMA_LOCATION_ATTRIB_NAME, schemaLocation != null); }