More work converting to multi-federation HS.
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / common / RelyingParty.java
1 /*
2  * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation
3  * for Advanced Internet Development, Inc. All rights reserved
4  * 
5  * 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * 
9  * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 
12  * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution, if any, must include
15  * the following acknowledgment: "This product includes software developed by
16  * the University Corporation for Advanced Internet Development
17  * <http://www.ucaid.edu> Internet2 Project. Alternately, this acknowledegement
18  * may appear in the software itself, if and wherever such third-party
19  * acknowledgments normally appear.
20  * 
21  * Neither the name of Shibboleth nor the names of its contributors, nor
22  * Internet2, nor the University Corporation for Advanced Internet Development,
23  * Inc., nor UCAID may be used to endorse or promote products derived from this
24  * software without specific prior written permission. For written permission,
25  * please contact shibboleth@shibboleth.org
26  * 
27  * Products derived from this software may not be called Shibboleth, Internet2,
28  * UCAID, or the University Corporation for Advanced Internet Development, nor
29  * may Shibboleth appear in their name, without prior written permission of the
30  * University Corporation for Advanced Internet Development.
31  * 
32  * 
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34  * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
36  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
37  * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
38  * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
39  * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY
40  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  */
47
48 package edu.internet2.middleware.shibboleth.common;
49
50 import java.util.Properties;
51
52 import org.w3c.dom.Element;
53
54 /**
55  * @author Walter Hoehn
56  */
57 public class RelyingParty implements ServiceProvider {
58
59         private ShibbolethOriginConfig originConfig;
60         private Properties partyOverrides = new Properties();
61         //TODO stub
62         private String id = "test:id";
63         private RelyingPartyIdentityProvider identityProvider;
64
65         public RelyingParty(Element partyConfig, ShibbolethOriginConfig globalConfig, Credentials credentials) {
66                 this.originConfig = globalConfig;
67                 //TODO setup things
68
69                 //TODO this is just a stub... has to come from configuration
70                 partyOverrides.setProperty(
71                         "edu.internet2.middleware.shibboleth.hs.HandleServlet.responseSigningCredential",
72                         "foo");
73
74                 identityProvider =
75                         new RelyingPartyIdentityProvider(
76                                 getConfigProperty("edu.internet2.middleware.shibboleth.hs.HandleServlet.providerId"),
77                                 credentials.getCredential(
78                                         getConfigProperty("edu.internet2.middleware.shibboleth.hs.HandleServlet.responseSigningCredential")));
79         }
80
81         public String getProviderId() {
82                 return id;
83         }
84
85         public String getName() {
86                 return id;
87         }
88
89         public String getConfigProperty(String key) {
90                 if (partyOverrides.containsKey(key)) {
91                         return partyOverrides.getProperty(key);
92                 }
93                 return originConfig.getConfigProperty(key);
94         }
95
96         public boolean isLegacyProvider() {
97                 //TODO implement
98                 return true;
99         }
100
101         public String getHSNameFormatId() {
102                 return null;
103         }
104
105         public RelyingPartyIdentityProvider getIdentityProvider() {
106                 return identityProvider;
107         }
108 }
109
110 class RelyingPartyIdentityProvider implements IdentityProvider {
111
112         private String providerId;
113         private Credential responseSigningCredential;
114
115         RelyingPartyIdentityProvider(String providerId, Credential responseSigningCred) {
116                 this.providerId = providerId;
117                 this.responseSigningCredential = responseSigningCred;
118         }
119         public String getProviderId() {
120                 return providerId;
121         }
122
123         public Credential getResponseSigningCredential() {
124                 return responseSigningCredential;
125         }
126
127         public Credential getAssertionSigningCredential() {
128                 return null;
129         }
130
131 }