Java Code Examples for org.opensaml.xml.util.DatatypeHelper#safeTrim()

The following examples show how to use org.opensaml.xml.util.DatatypeHelper#safeTrim() . 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: HTTPArtifactDecoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
    if (!(messageContext instanceof SAMLMessageContext)) {
        log.error("Invalid message context type, this decoder only support SAMLMessageContext");
        throw new MessageDecodingException(
                "Invalid message context type, this decoder only support SAMLMessageContext");
    }

    if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
        log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
        throw new MessageDecodingException(
                "Invalid inbound message transport type, this decoder only support HTTPInTransport");
    }

    SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;

    HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
    String relayState = DatatypeHelper.safeTrim(inTransport.getParameterValue("RelayState"));
    samlMsgCtx.setRelayState(relayState);
    
    processArtifact(samlMsgCtx);

    populateMessageContext(samlMsgCtx);
}
 
Example 2
Source File: ReplayCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param storageService the StorageService which serves as the backing store for the cache
 * @param storageParition name of storage service partition to use
 * @param duration default length of time that message state is valid
 */
public ReplayCache(StorageService<String, ReplayCacheEntry> storageService, String storageParition, long duration) {
    storage = storageService;
    entryDuration = duration;
    if (!DatatypeHelper.isEmpty(storageParition)) {
        partition = DatatypeHelper.safeTrim(storageParition);
    } else {
        partition = "replay";
    }
    cacheLock = new ReentrantLock(true);
}
 
Example 3
Source File: HTTPArtifactDecoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decodes the TARGET parameter and adds it to the message context.
 * 
 * @param samlMsgCtx current message context
 * 
 * @throws MessageDecodingException thrown if there is a problem decoding the TARGET parameter.
 */
protected void decodeTarget(SAMLMessageContext samlMsgCtx) throws MessageDecodingException {
    HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();

    String target = DatatypeHelper.safeTrim(inTransport.getParameterValue("TARGET"));
    if (target == null) {
        log.error("URL TARGET parameter was missing or did not contain a value.");
        throw new MessageDecodingException("URL TARGET parameter was missing or did not contain a value.");
    }
    samlMsgCtx.setRelayState(target);
}
 
Example 4
Source File: BasicSAMLArtifactMap.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param factory the SAML artifact map entry factory to use
 * @param storage artifact mapping storage
 * @param storageParition name of storage service partition to use
 * @param lifetime lifetime of an artifact in milliseconds
 */
public BasicSAMLArtifactMap(SAMLArtifactMapEntryFactory factory,
        StorageService<String, SAMLArtifactMapEntry> storage, 
        String storageParition, long lifetime) {
    entryFactory = factory;
    artifactStore = storage;
    if (!DatatypeHelper.isEmpty(storageParition)) {
        partition = DatatypeHelper.safeTrim(storageParition);
    } else {
        partition = DEFAULT_STORAGE_PARTITION;
    }
    artifactLifetime = lifetime;
}
 
Example 5
Source File: AuthnResponseEndpointSelector.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Selects the endpoint by way of the assertion consumer service URL given in the AuthnRequest.
 * 
 * @param request the AuthnRequest
 * @param endpoints list of endpoints to select from
 * 
 * @return the selected endpoint
 */
protected Endpoint selectEndpointByACSURL(AuthnRequest request, List<IndexedEndpoint> endpoints) {
    String acsBinding = DatatypeHelper.safeTrimOrNullString(request.getProtocolBinding());

    for (IndexedEndpoint endpoint : endpoints) {
        if (!getSupportedIssuerBindings().contains(endpoint.getBinding())) {
            log.debug(
                    "Endpoint '{}' with binding '{}' discarded because that is not a supported outbound binding.",
                    endpoint.getLocation(), endpoint.getBinding());
            continue;
        }

        if (acsBinding != null) {
            if (!DatatypeHelper.safeEquals(acsBinding, endpoint.getBinding())) {
                log.debug(
                        "Endpoint '{}' with binding '{}' discarded because it does not meet protocol binding selection criteria",
                        endpoint.getLocation(), endpoint.getBinding());
                continue;
            }
        }

        String responseLocation = DatatypeHelper.safeTrim(endpoint.getResponseLocation());
        if (responseLocation != null){
                if(DatatypeHelper.safeEquals(responseLocation, request.getAssertionConsumerServiceURL())) {
                    return endpoint;
                }
        }else{    
            String location = DatatypeHelper.safeTrim(endpoint.getLocation());
            if (location != null && DatatypeHelper.safeEquals(location, request.getAssertionConsumerServiceURL())) {
                return endpoint;
            }
        }

        log.debug("Endpoint with Location '{}' discarded because neither its Location nor ResponseLocation match ACS URL '{}'",
                endpoint.getLocation(), request.getAssertionConsumerServiceURL());
    }

    log.warn("Relying party '{}' requested the response to be returned to endpoint with ACS URL '{}' "
            + " and binding '{}' however no endpoint, with that URL and using a supported binding, "
            + " can be found in the relying party's metadata ", new Object[] {getEntityMetadata().getEntityID(),
            request.getAssertionConsumerServiceURL(), (acsBinding == null) ? "any" : acsBinding});
    return null;
}