Bunch o' bug fixes, all IdP configuration files now load.
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / idp / profile / saml1 / AttributeQuery.java
1 /*
2  * Copyright [2006] [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.saml1;
18
19 import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
20 import edu.internet2.middleware.shibboleth.common.profile.ProfileRequest;
21 import edu.internet2.middleware.shibboleth.common.profile.ProfileResponse;
22
23 import javax.servlet.ServletException;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
26
27 import org.apache.log4j.Logger;
28 import org.joda.time.DateTime;
29 import org.opensaml.common.SAMLObjectBuilder;
30 import org.opensaml.common.binding.BindingException;
31 import org.opensaml.saml1.core.Advice;
32 import org.opensaml.saml1.core.Assertion;
33 import org.opensaml.saml1.core.AttributeStatement;
34 import org.opensaml.saml1.core.Conditions;
35 import org.opensaml.saml1.core.Response;
36 import org.opensaml.saml1.core.Status;
37 import org.opensaml.saml1.core.StatusCode;
38 import org.opensaml.saml1.core.Subject;
39 import org.opensaml.saml1.core.SubjectStatement;
40 import org.opensaml.xml.encryption.EncryptionException;
41
42 import edu.internet2.middleware.shibboleth.common.attribute.filtering.AttributeFilteringException;
43 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
44
45 /**
46  * SAML 1 Attribute Query profile handler.
47  */
48 public class AttributeQuery extends AbstractSAML1ProfileHandler {
49
50     /** {@inheritDoc} */
51     public String getProfileId() {
52         // TODO Auto-generated method stub
53         return null;
54     }
55
56     /** {@inheritDoc} */
57     public void processRequest(ProfileRequest<ServletRequest> request, ProfileResponse<ServletResponse> response) throws ProfileException {
58         // TODO Auto-generated method stub
59         
60     }
61 //
62 //    /** Class logger. */
63 //    private static Logger log = Logger.getLogger(AttributeQuery.class);
64 //
65 //    /** {@inheritDoc} */
66 //    public boolean processRequest(ProfileRequest request, ProfileResponse response) throws ServletException {
67 //        if (log.isDebugEnabled()) {
68 //            log.debug("begin processRequest");
69 //        }
70 //
71 //        // get message from the decoder
72 //        org.opensaml.saml1.core.AttributeQuery message = null;
73 //        try {
74 //            message = (org.opensaml.saml1.core.AttributeQuery) decodeMessage(request);
75 //        } catch (BindingException e) {
76 //            log.error("Error decoding attribute query message", e);
77 //            throw new ServletException("Error decoding attribute query message");
78 //        }
79 //
80 //        // get attribute statement from attribute authority
81 //        AttributeAuthority aa = new AttributeAuthority();
82 //        aa.setAttributeResolver(getAttributeResolver());
83 //        aa.setFilteringEngine(getFilteringEngine());
84 //        aa.setRelyingPartyConfiguration(getRelyingPartyConfiguration());
85 //        aa.setSecurityPolicy(getDecoder().getSecurityPolicy());
86 //        aa.setRequest(request);
87 //        AttributeStatement statement = null;
88 //        try {
89 //            statement = aa.performAttributeQuery(message);
90 //        } catch (AttributeResolutionException e) {
91 //            log.error("Error resolving attributes", e);
92 //            throw new ServletException("Error resolving attributes");
93 //        } catch (FilteringException e) {
94 //            log.error("Error filtering attributes", e);
95 //            throw new ServletException("Error filtering attributes");
96 //        }
97 //
98 //        // construct response
99 //        Response samlResponse = null;
100 //        try {
101 //            samlResponse = buildResponse(message, request.getRemoteHost(), new DateTime(), statement);
102 //        } catch (EncryptionException e) {
103 //            log.error("Error encrypting SAML response", e);
104 //            throw new ServletException("Error encrypting SAML response");
105 //        }
106 //        if (log.isDebugEnabled()) {
107 //            log.debug("built saml1 response: " + samlResponse);
108 //        }
109 //
110 //        // encode response
111 //        try {
112 //            encodeResponse(samlResponse);
113 //        } catch (BindingException e) {
114 //            log.error("Error encoding attribute query response", e);
115 //            throw new ServletException("Error encoding attribute query response");
116 //        }
117 //
118 //        return true;
119 //    }
120 //
121 //    /**
122 //     * This builds the response for this SAML request.
123 //     * 
124 //     * @param message <code>AttributeQuery</code>
125 //     * @param dest <code>String</code>
126 //     * @param issueInstant <code>DateTime</code>
127 //     * @param statement <code>AttributeStatement</code>
128 //     * @return <code>Response</code>
129 //     * @throws EncryptionException if an error occurs attempting to encrypt data
130 //     */
131 //    private Response buildResponse(org.opensaml.saml1.core.AttributeQuery message, String dest, DateTime issueInstant,
132 //            AttributeStatement statement) throws EncryptionException {
133 //        SAMLObjectBuilder<Response> responseBuilder = (SAMLObjectBuilder<Response>) getBuilderFactory().getBuilder(
134 //                Response.DEFAULT_ELEMENT_NAME);
135 //        /*
136 //         * required: samlp:Status, ID, Version, IssueInstant
137 //         */
138 //        Response response = responseBuilder.buildObject();
139 //        response.setVersion(SAML_VERSION);
140 //        response.setID(getIdGenerator().generateIdentifier());
141 //        response.setInResponseTo(getDecoder().getSecurityPolicy().getIssuer().toString());
142 //        response.setIssueInstant(issueInstant);
143 //        response.setRecipient(dest);
144 //
145 //        response.setStatus(buildStatus());
146 //        response.getAssertions().add(buildAssertion(message.getSubject(), issueInstant, statement));
147 //        return response;
148 //    }
149 //
150 //    /**
151 //     * This builds the status response for this SAML request.
152 //     * 
153 //     * @return <code>Status</code>
154 //     */
155 //    private Status buildStatus() {
156 //        // build status
157 //        SAMLObjectBuilder<Status> statusBuilder = (SAMLObjectBuilder<Status>) getBuilderFactory().getBuilder(
158 //                Status.DEFAULT_ELEMENT_NAME);
159 //        Status status = statusBuilder.buildObject();
160 //
161 //        // build status code
162 //        SAMLObjectBuilder<StatusCode> statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) getBuilderFactory()
163 //                .getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
164 //        StatusCode statusCode = statusCodeBuilder.buildObject();
165 //        statusCode.setValue("Success");
166 //        status.setStatusCode(statusCode);
167 //        return status;
168 //    }
169 //
170 //    /**
171 //     * This builds the assertion for this SAML request.
172 //     * 
173 //     * @param messageSubject <code>Subject</code>
174 //     * @param issueInstant <code>DateTime</code>
175 //     * @param statement <code>AttributeStatement</code> of attributes
176 //     * @return <code>Assertion</code>
177 //     * @throws EncryptionException if an error occurs attempting to encrypt data
178 //     */
179 //    private Assertion buildAssertion(Subject messageSubject, DateTime issueInstant, AttributeStatement statement)
180 //            throws EncryptionException {
181 //        // build assertion
182 //        SAMLObjectBuilder<Assertion> assertionBuilder = (SAMLObjectBuilder<Assertion>) getBuilderFactory().getBuilder(
183 //                Assertion.DEFAULT_ELEMENT_NAME);
184 //        /*
185 //         * required: saml:Issuer, ID, Version, IssueInstant
186 //         */
187 //        Assertion assertion = assertionBuilder.buildObject();
188 //        assertion.setID(getIdGenerator().generateIdentifier());
189 //        assertion.setIssueInstant(issueInstant);
190 //        assertion.setVersion(SAML_VERSION);
191 //        assertion.setIssuer(getRelyingPartyConfiguration().getProviderID());
192 //
193 //        // build subject
194 //        assertion.getSubjectStatements().add(buildSubjectStatement(messageSubject));
195 //        // build conditions
196 //        assertion.setConditions(buildConditions(issueInstant));
197 //        // build advice
198 //        assertion.setAdvice(buildAdvice());
199 //        // add attribute statement
200 //        assertion.getAttributeStatements().add(statement);
201 //        return assertion;
202 //    }
203 //
204 //    /**
205 //     * This builds the subject statement for this SAML request.
206 //     * 
207 //     * @param messageSubject <code>Subject</code>
208 //     * @return <code>SubjectStatement</code>
209 //     */
210 //    private SubjectStatement buildSubjectStatement(Subject messageSubject) {
211 //        // build subject
212 //        SAMLObjectBuilder<SubjectStatement> subjectStatementBuilder = (SAMLObjectBuilder<SubjectStatement>) getBuilderFactory()
213 //                .getBuilder(SubjectStatement.DEFAULT_ELEMENT_NAME);
214 //        SubjectStatement subjectStatement = subjectStatementBuilder.buildObject();
215 //        subjectStatement.setSubject(messageSubject);
216 //        return subjectStatement;
217 //    }
218 //
219 //    /**
220 //     * This builds the conditions for this SAML request.
221 //     * 
222 //     * @param issueInstant <code>DateTime</code>
223 //     * @return <code>Conditions</code>
224 //     */
225 //    private Conditions buildConditions(DateTime issueInstant) {
226 //        SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) getBuilderFactory()
227 //                .getBuilder(Conditions.DEFAULT_ELEMENT_NAME);
228 //        Conditions conditions = conditionsBuilder.buildObject();
229 //        conditions.setNotBefore(issueInstant);
230 //        // TODO conditions.setNotOnOrAfter();
231 //        // TODO add additional conditions : conditions.getConditions().add(Condition);
232 //        // TODO what about AudienceRestriction, OneTimeUse, ProxyRestriction?
233 //        return conditions;
234 //    }
235 //
236 //    /**
237 //     * This builds the advice for this SAML request.
238 //     * 
239 //     * @return <code>Advice</code>
240 //     */
241 //    private Advice buildAdvice() {
242 //        SAMLObjectBuilder<Advice> adviceBuilder = (SAMLObjectBuilder<Advice>) getBuilderFactory().getBuilder(
243 //                Advice.DEFAULT_ELEMENT_NAME);
244 //        Advice advice = adviceBuilder.buildObject();
245 //        // advice.getAssertionIDReferences().add();
246 //        // advice.getAssertionURIReferences().add();
247 //        // advice.getAssertions().add();
248 //        // advice.getEncryptedAssertions().add();
249 //        // advice.addNamespace(namespace);
250 //        return advice;
251 //    }
252 }