2 * FilterSupportImpl.java
4 * Provide access to the Filter to configuration information
9 * University Corporation for Advanced Internet Development, Inc.
11 * [Thats all we have to say to protect ourselves]
12 * Your permission to use this code is governed by "The Shibboleth License".
13 * A copy may be found at http://shibboleth.internet2.edu/license.html
14 * [Nothing in copyright law requires license text in every file.]
16 package edu.internet2.middleware.shibboleth.serviceprovider;
20 import org.opensaml.SAMLException;
22 import x0.maceShibbolethTargetConfig1.SessionsDocument.Sessions;
24 import edu.internet2.middleware.shibboleth.common.AAP;
25 import edu.internet2.middleware.shibboleth.common.AttributeRule;
26 import edu.internet2.middleware.shibboleth.metadata.MetadataException;
27 import edu.internet2.middleware.shibboleth.resource.FilterSupport;
28 import edu.internet2.middleware.shibboleth.serviceprovider.ServiceProviderConfig.ApplicationInfo;
31 * Provide access from the Filter to the /shibboleth configuration and Sessions.
33 * @author Howard Gilbert
35 public class FilterSupportImpl implements FilterSupport {
37 public static ServiceProviderContext context = ServiceProviderContext.getInstance();
40 * Given a Resource URL, go to the RequestMap logic to find an applicationId.
42 * @param url The URL of the Resource presented by the browser
43 * @return applicationId string
45 public String getApplicationId(String url) {
46 ServiceProviderConfig config = context.getServiceProviderConfig();
47 String applicationId = config.mapRequest(url);
52 * Get the "providerId" (site name) of the ServiceProvider
54 * @param applicationId
55 * @return providerId string
57 public String getProviderId(String applicationId) {
58 ServiceProviderConfig config = context.getServiceProviderConfig();
59 ApplicationInfo application = config.getApplication(applicationId);
60 String providerId = application.getApplicationConfig().getProviderId();
65 * Get the URL of the local AuthenticationAssertionConsumerServlet.
67 * @param applicationId
70 public String getShireUrl(String applicationId) {
71 ServiceProviderConfig config = context.getServiceProviderConfig();
72 ApplicationInfo application = config.getApplication(applicationId);
73 String shireUrl = application.getApplicationConfig().getSessions().getShireURL();
78 * Get the URL to which the Browser should be initially redirected.
80 * @param applicationId
83 public String getWayfUrl(String applicationId) {
84 ServiceProviderConfig config = context.getServiceProviderConfig();
85 ApplicationInfo application = config.getApplication(applicationId);
86 String wayfUrl = application.getApplicationConfig().getSessions().getWayfURL();
91 * Does the requested resource require Shibboleth authentication?
93 * @param url request url
94 * @return true if Shibboleth is required
96 public boolean isProtected(String url) {
97 // TODO Add some real logic. This is just a placeholder
98 if (url.endsWith("test.txt"))
104 * Get attributes for this Session
107 * @param applicationId
108 * @return Map of (attribute,value) pairs
110 public Map /*<String,String>*/
111 getSessionAttributes(String sessionId, String applicationId) {
112 SessionManager sm = context.getSessionManager();
114 sm.findSession(sessionId, applicationId);
117 Map /*<String,String>*/ attributes = SessionManager.mapAttributes(session);
122 * Map attribute name to pseudo-HTTP-Headers
124 * @param attributeName
125 * @param applicationId
126 * @return null or Header name string
128 public String getHeader(String attributeName, String applicationId) {
129 ServiceProviderConfig config = context.getServiceProviderConfig();
130 ApplicationInfo application = config.getApplication(applicationId);
131 AAP[] providers = application.getAAPProviders();
132 for (int i=0;i<providers.length;i++) {
133 AAP aap = providers[i];
134 AttributeRule rule = aap.lookup(attributeName, null);
136 return rule.getHeader();
143 * @param bin64Assertion
144 * @param applicationId
149 public String createSessionFromPost(
151 byte[] bin64Assertion,
152 String applicationId,
157 sessionid = AuthenticationAssertionConsumerServlet.createSessionFromPost(
158 ipaddr, bin64Assertion, applicationId, shireURL, providerId);
159 } catch (SAMLException e) {
161 } catch (MetadataException e) {
168 public boolean getShireSSL(String applicationId) {
169 ServiceProviderConfig config = context.getServiceProviderConfig();
170 ApplicationInfo appinfo = config.getApplication(applicationId);
171 Sessions appSessionValues = appinfo.getApplicationConfig().getSessions();
172 return appSessionValues.getShireSSL();