2d53b2c1e27f876efc1e5fd3f2bde9cd13b242b8
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / idp / profile / saml2 / HTTPSOAPAttributeQuery.java
1 /*
2  * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package edu.internet2.middleware.shibboleth.idp.profile.saml2;
18
19 import javax.servlet.ServletRequest;
20 import javax.servlet.ServletResponse;
21 import javax.servlet.http.HttpServletRequest;
22
23 import org.opensaml.common.binding.MessageDecoder;
24 import org.opensaml.common.binding.MessageEncoder;
25 import org.opensaml.saml2.binding.HTTPSOAP11Decoder;
26 import org.opensaml.saml2.binding.HTTPSOAP11Encoder;
27
28 import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
29 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
30 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
31 import edu.internet2.middleware.shibboleth.idp.session.Session;
32
33 /**
34  * SAML 2.0 SOAP Attribute Query profile handler.
35  */
36 public class HTTPSOAPAttributeQuery extends AbstractAttributeQuery {
37
38     /** Constructor. */
39     public HTTPSOAPAttributeQuery() {
40         super();
41     }
42
43     /** {@inheritDoc} */
44     @SuppressWarnings("unchecked")
45     protected MessageDecoder<ServletRequest> getMessageDecoder(ProfileRequest<ServletRequest> request)
46             throws ProfileException {
47         MessageDecoder decoder = new HTTPSOAP11Decoder();
48         decoder.setRequest(request.getRawRequest());
49         return decoder;
50     }
51
52     /** {@inheritDoc} */
53     @SuppressWarnings("unchecked")
54     protected MessageEncoder<ServletResponse> getMessageEncoder(ProfileResponse<ServletResponse> response)
55             throws ProfileException {
56         MessageEncoder encoder = new HTTPSOAP11Encoder();
57         encoder.setResponse(response.getRawResponse());
58         return encoder;
59     }
60
61     /** {@inheritDoc} */
62     protected String getUserSessionId(ProfileRequest<ServletRequest> request) {
63         HttpServletRequest rawRequest = (HttpServletRequest) request.getRawRequest();
64         if (rawRequest != null) {
65             return (String) rawRequest.getSession().getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE);
66         }
67
68         return null;
69     }
70 }