001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nelson Silva <nelson.silva@inevo.pt>
016 */
017package org.nuxeo.ecm.platform.auth.saml.binding;
018
019import org.opensaml.common.xml.SAMLConstants;
020import org.opensaml.saml2.binding.decoding.HTTPPostDecoder;
021import org.opensaml.ws.transport.InTransport;
022import org.opensaml.ws.transport.OutTransport;
023import org.opensaml.ws.transport.http.HTTPInTransport;
024import org.opensaml.ws.transport.http.HTTPOutTransport;
025import org.opensaml.ws.transport.http.HTTPTransport;
026
027/**
028 * HTTP Post Binding
029 *
030 * @since 6.0
031 */
032public class HTTPPostBinding extends SAMLBinding {
033
034    public static final String SAML_REQUEST = "SAMLRequest";
035
036    public static final String SAML_RESPONSE = "SAMLResponse";
037
038    public HTTPPostBinding() {
039        super(new HTTPPostDecoder(), null);// TODO(nfgs): add HTTPPostEncoder
040    }
041
042    public boolean supports(InTransport transport) {
043        if (transport instanceof HTTPInTransport) {
044            HTTPTransport t = (HTTPTransport) transport;
045            return "POST".equalsIgnoreCase(t.getHTTPMethod())
046                    && (t.getParameterValue(SAML_REQUEST) != null || t.getParameterValue(SAML_RESPONSE) != null);
047        } else {
048            return false;
049        }
050    }
051
052    public boolean supports(OutTransport transport) {
053        return transport instanceof HTTPOutTransport;
054    }
055
056    public String getBindingURI() {
057        return SAMLConstants.SAML2_POST_BINDING_URI;
058    }
059}