001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nelson Silva <nelson.silva@inevo.pt>
018 */
019package org.nuxeo.ecm.platform.auth.saml.binding;
020
021import org.opensaml.common.xml.SAMLConstants;
022import org.opensaml.saml2.binding.decoding.HTTPPostDecoder;
023import org.opensaml.ws.transport.InTransport;
024import org.opensaml.ws.transport.OutTransport;
025import org.opensaml.ws.transport.http.HTTPInTransport;
026import org.opensaml.ws.transport.http.HTTPOutTransport;
027import org.opensaml.ws.transport.http.HTTPTransport;
028
029/**
030 * HTTP Post Binding
031 *
032 * @since 6.0
033 */
034public class HTTPPostBinding extends SAMLBinding {
035
036    public static final String SAML_REQUEST = "SAMLRequest";
037
038    public static final String SAML_RESPONSE = "SAMLResponse";
039
040    public HTTPPostBinding() {
041        super(new HTTPPostDecoder(), null);// TODO(nfgs): add HTTPPostEncoder
042    }
043
044    public boolean supports(InTransport transport) {
045        if (transport instanceof HTTPInTransport) {
046            HTTPTransport t = (HTTPTransport) transport;
047            return "POST".equalsIgnoreCase(t.getHTTPMethod())
048                    && (t.getParameterValue(SAML_REQUEST) != null || t.getParameterValue(SAML_RESPONSE) != null);
049        } else {
050            return false;
051        }
052    }
053
054    public boolean supports(OutTransport transport) {
055        return transport instanceof HTTPOutTransport;
056    }
057
058    public String getBindingURI() {
059        return SAMLConstants.SAML2_POST_BINDING_URI;
060    }
061}