447318b91b4d9034b6f6d04a8f95c428cf4e0f01
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / hs / HandleServiceSAML.java
1 import java.io.*;
2 import java.util.*;
3 import edu.internet2.middleware.shibboleth.*;
4 import edu.internet2.middleware.shibboleth.common.*;
5 import org.opensaml.*;
6
7
8 public class HandleServiceSAML {
9
10     protected String domain;
11     protected String AAurl;
12     public String[] policies = { Constants.POLICY_CLUBSHIB };
13     private ShibPOSTProfile spp;
14
15     public HandleServiceSAML( String domain, String AAurl, String issuer) 
16         throws SAMLException 
17     {
18         this.domain = domain;
19         this.AAurl = AAurl;
20         
21         spp = ShibPOSTProfileFactory.getInstance( policies, issuer );
22     }
23     
24     public byte[] prepare ( String handle, String shireURL, 
25     String clientAddress, String authMethod, Date authInstant ) 
26         throws HandleException {
27
28         try { 
29             SAMLAuthorityBinding[] bindings = new SAMLAuthorityBinding[1];
30             bindings[0] = new SAMLAuthorityBinding
31                 ( SAMLBinding.SAML_SOAP_HTTPS, AAurl, 
32                   new QName(org.opensaml.XML.SAMLP_NS,"AttributeQuery") );
33             SAMLResponse r = spp.prepare 
34             ( shireURL, handle, domain, clientAddress, authMethod, 
35               authInstant, bindings, null, null, null, null
36               );
37             byte[] buf = r.toBase64();
38             
39             return buf;
40         }
41         catch (SAMLException ex) {
42             throw new HandleException( "Error creating SAML assertion: "+ex );
43         }
44         catch (IOException ex) {
45             throw new HandleException( "Error converting SAML assertion: "+ex);
46         }
47     }
48 }
49                                       
50                                 
51               
52                             
53
54