Changeset 7453
- Timestamp:
- 07/09/10 16:38:04 (10 years ago)
- Location:
- TI12-security/trunk/EsgYadisParser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/EsgYadisParser/.classpath
r7308 r7453 11 11 <classpathentry kind="lib" path="lib/xercesImpl-2.8.1.jar"/> 12 12 <classpathentry kind="lib" path="lib/mailapi.jar"/> 13 <classpathentry kind="lib" path="/esg-saml/lib/fetched"/> 14 <classpathentry kind="src" path="/esg-saml"/> 15 <classpathentry kind="lib" path="/esg-saml/dist/esg-saml-1.1.2.2.jar"/> 16 <classpathentry kind="lib" path="/esg-saml/dist/esg-saml-common-1.1.2.2.jar" sourcepath="/esg-saml/src/java/main/esg/saml/common"/> 17 <classpathentry kind="lib" path="/esg-saml/dist/esg-saml-connector-1.1.2.2.jar"/> 18 <classpathentry kind="lib" path="/esg-saml/dist/esg-saml-fe-1.1.2.2.jar"/> 19 <classpathentry kind="lib" path="/esg-saml/dist/esg-saml-test-1.1.2.2.jar"/> 20 <classpathentry kind="lib" path="/esg-saml/dist"/> 21 <classpathentry kind="lib" path="/esg-saml/lib/fetched/opensaml-2.3.2.jar"/> 22 <classpathentry kind="lib" path="/esg-saml/lib/fetched/xmltooling-1.2.2.jar"/> 13 23 <classpathentry kind="output" path="bin"/> 14 24 </classpath> -
TI12-security/trunk/EsgYadisParser/.project
r7308 r7453 4 4 <comment></comment> 5 5 <projects> 6 <project>esg-saml</project> 6 7 </projects> 7 8 <buildSpec> -
TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security/openid2emailresolution/OpenId2EmailAddrResolution.java
r7308 r7453 1 1 package org.earthsystemgrid.security.openid2emailresolution; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 4 7 import java.net.MalformedURLException; 5 8 import java.net.URL; … … 15 18 16 19 import javax.mail.internet.InternetAddress; 20 import javax.net.ssl.HttpsURLConnection; 21 import javax.net.ssl.SSLContext; 22 import javax.net.ssl.SSLSocketFactory; 23 import javax.net.ssl.X509TrustManager; 17 24 25 import esg.saml.attr.service.impl.SAMLAttributeServiceClientSoapImpl; 26 import org.opensaml.xml.io.MarshallingException; 27 28 import org.earthsystemgrid.security.DnWhitelistX509TrustMgr; 29 import org.earthsystemgrid.security.exceptions.DnWhitelistX509TrustMgrInitException; 18 30 import org.earthsystemgrid.security.openid2emailresolution.exceptions.AttributeServiceQueryException; 19 31 import org.earthsystemgrid.security.openid2emailresolution.exceptions.NoMatchingXrdsServiceException; … … 26 38 27 39 private String attributeServiceType; 28 public static final String DEF_ATTRIBUTE_SERVICE_XRD_SERVICE_TYPE = "urn:esg:security:attribute-service"; 40 private DnWhitelistX509TrustMgr x509TrustMgr; 41 public static final String DEF_ATTRIBUTE_SERVICE_XRD_SERVICE_TYPE = 42 "urn:esg:security:attribute-service"; 29 43 30 public OpenId2EmailAddrResolution(String attributeServiceType) { 31 super(); 44 public OpenId2EmailAddrResolution(String attributeServiceType, 45 InputStream propertiesFile) throws YadisRetrievalException { 46 47 // Create trust manager with given whitelist and keystore settings 48 // read from properties file 49 try { 50 x509TrustMgr = new DnWhitelistX509TrustMgr(propertiesFile); 51 52 } catch (DnWhitelistX509TrustMgrInitException e) { 53 throw new YadisRetrievalException("Creating trust manager", e); 54 } 55 32 56 if (this.attributeServiceType == null) 33 57 this.attributeServiceType = DEF_ATTRIBUTE_SERVICE_XRD_SERVICE_TYPE; … … 37 61 } 38 62 39 public OpenId2EmailAddrResolution() { 40 this(null); 63 public OpenId2EmailAddrResolution(InputStream propertiesFile) 64 throws YadisRetrievalException { 65 this(null, propertiesFile); 41 66 } 42 67 … … 47 72 AttributeServiceQueryException { 48 73 49 YadisRetrieval yadisRetriever = new YadisRetrieval( );74 YadisRetrieval yadisRetriever = new YadisRetrieval(x509TrustMgr); 50 75 List<XrdsServiceElem> serviceElems = null; 51 76 Set<String> targetTypes = new HashSet<String>() {{add(attributeServiceType);}}; … … 75 100 76 101 // Call Attribute Service querying for e-mail address 77 InternetAddress emailAddr = queryAttributeService(attributeServiceEndpoint); 102 InternetAddress emailAddr = queryAttributeService(attributeServiceEndpoint, 103 openidURL); 78 104 return emailAddr; 79 105 } … … 82 108 * Call Attribute Service to retrieve user's e-mail address 83 109 */ 84 protected InternetAddress queryAttributeService(URL attributeServiceEndpoint) 110 protected InternetAddress queryAttributeService(URL attributeServiceEndpoint, 111 URL openidURL) throws AttributeServiceQueryException 85 112 { 86 // TODO: Add Attribute Service call here 113 String issuer = "my issuer"; 114 SAMLAttributeServiceClientSoapImpl attributeServiceClient = 115 new SAMLAttributeServiceClientSoapImpl(issuer); 116 117 // Create query 118 String query = null; 119 try { 120 query = attributeServiceClient.buildAttributeRequest(openidURL.toString()); 121 } catch (MarshallingException e) { 122 throw new AttributeServiceQueryException("Marshalling attribute " + 123 "query to " + attributeServiceEndpoint + " for OpenID", e); 124 } 125 SSLContext ctx = null; 126 try { 127 ctx = SSLContext.getInstance("SSL"); 128 129 } catch (NoSuchAlgorithmException e) { 130 throw new AttributeServiceQueryException("Getting SSL context", e); 131 } 132 133 X509TrustManager tm[] = {x509TrustMgr}; 134 try { 135 ctx.init(null, tm, null); 136 } catch (KeyManagementException e) { 137 throw new AttributeServiceQueryException("Initialising SSL context", 138 e); 139 } 140 141 SSLSocketFactory socketFactory = ctx.getSocketFactory(); 142 HttpsURLConnection connection = null; 143 try { 144 connection = (HttpsURLConnection) 145 attributeServiceEndpoint.openConnection(); 146 } catch (IOException e) { 147 throw new AttributeServiceQueryException("Making connection", e); 148 } 149 connection.setSSLSocketFactory(socketFactory); 150 151 InputStream ins = null; 152 try { 153 ins = connection.getInputStream(); 154 } catch (IOException e) { 155 throw new AttributeServiceQueryException("Getting input stream", e); 156 } 157 InputStreamReader isr = new InputStreamReader(ins); 158 BufferedReader in = new BufferedReader(isr); 159 StringBuffer buf = new StringBuffer(); 160 String inputLine = null; 161 162 try { 163 while ((inputLine = in.readLine()) != null) 164 { 165 buf.append(inputLine); 166 buf.append(System.getProperty("line.separator")); 167 } 168 in.close(); 169 } catch (IOException e) { 170 throw new AttributeServiceQueryException("Reading content", e); 171 } 172 173 return buf.toString(); 174 87 175 return null; 88 176 } -
TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security/yadis/YadisRetrieval.java
r7309 r7453 59 59 60 60 /** 61 * Initialise from an existing trust manager 62 * @param x509TrustMgr 63 */ 64 public YadisRetrieval(X509TrustManager x509TrustMgr) { 65 this.x509TrustMgr = x509TrustMgr; 66 } 67 68 /** 61 69 * Retrieve XRD document from Yadis endpoint 62 70 *
Note: See TracChangeset
for help on using the changeset viewer.