More work on profile handlers, still have some more refactoring to do
[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
22 import org.opensaml.common.binding.decoding.MessageDecoder;
23 import org.opensaml.common.binding.encoding.MessageEncoder;
24
25 import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
26
27 /**
28  * SAML 2.0 SOAP Attribute Query profile handler.
29  */
30 public class HTTPSOAPAttributeQuery extends AbstractAttributeQuery {
31
32     /** SAML binding URI. */
33     public static final String BINDING = "urn:oasis:names:tc:SAML:2.0:bindings:SOAP";
34
35     /** Constructor. */
36     public HTTPSOAPAttributeQuery() {
37         super();
38     }
39
40     /** {@inheritDoc} */
41     @SuppressWarnings("unchecked")
42     protected void getMessageDecoder(AttributeQueryRequestContext requestContext) throws ProfileException {
43         MessageDecoder<ServletRequest> decoder = getMessageDecoderFactory().getMessageDecoder(BINDING);
44         if (decoder == null) {
45             throw new ProfileException("No request decoder was registered for binding type: " + BINDING);
46         }
47
48         requestContext.setMessageDecoder(decoder);
49         decoder.setRequest(requestContext.getProfileRequest().getRawRequest());
50     }
51
52     /** {@inheritDoc} */
53     @SuppressWarnings("unchecked")
54     protected void getMessageEncoder(AttributeQueryRequestContext requestContext) throws ProfileException {
55
56         MessageEncoder<ServletResponse> encoder = getMessageEncoderFactory().getMessageEncoder(BINDING);
57         if (encoder == null) {
58             throw new ProfileException("No response encoder was registered for binding type: " + BINDING);
59         }
60
61         requestContext.setMessageEncoder(encoder);
62         encoder.setResponse(requestContext.getProfileResponse().getRawResponse());
63         encoder.setSamlMessage(requestContext.getAttributeQueryResponse());
64     }
65 }