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