Changeset 7458
- Timestamp:
- 08/09/10 15:58:46 (10 years ago)
- Location:
- TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security/DnWhitelistX509TrustMgr.properties
r7309 r7458 14 14 # @author pjkersha 15 15 # @version $Revision$ 16 org.earthsystemgrid.security.DnWhitelistX509TrustMgr.keyStoreFilePath = /home/pjkersha/workspace/EsgYadisParser/src/org/earthsystemgrid/security/yadis/test.ks 17 org.earthsystemgrid.security.DnWhitelistX509TrustMgr.keyStorePassphrase = testpass 16 18 org.earthsystemgrid.security.DnWhitelistX509TrustMgr.dn0 = CN=ceda.ac.uk, OU=RAL-SPBU, O=Science and Technology Facilities Council, C=GB 17 org.earthsystemgrid.security.DnWhitelistX509TrustMgr.dn1 = CN=localhost, OU= Test, O=Test Org19 org.earthsystemgrid.security.DnWhitelistX509TrustMgr.dn1 = CN=localhost, OU=Security, O=NDG -
TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security/openid2emailresolution/OpenId2EmailAddrResolution.java
r7453 r7458 5 5 import java.io.InputStream; 6 6 import java.io.InputStreamReader; 7 import java.io.OutputStream; 8 import java.io.OutputStreamWriter; 7 9 import java.net.MalformedURLException; 10 import java.net.ProtocolException; 8 11 import java.net.URL; 9 12 import java.security.KeyManagementException; … … 11 14 import java.security.NoSuchAlgorithmException; 12 15 import java.security.cert.CertificateException; 16 import java.util.ArrayList; 13 17 import java.util.Arrays; 14 18 import java.util.Collections; … … 17 21 import java.util.Set; 18 22 23 import javax.mail.internet.AddressException; 19 24 import javax.mail.internet.InternetAddress; 20 25 import javax.net.ssl.HttpsURLConnection; … … 24 29 25 30 import esg.saml.attr.service.impl.SAMLAttributeServiceClientSoapImpl; 31 import esg.saml.attr.service.impl.SAMLAttributesImpl; 32 import esg.saml.common.SAMLBuilder; 33 import esg.saml.common.SAMLParameters; 34 35 import org.opensaml.saml2.core.Attribute; 36 import org.opensaml.saml2.core.impl.AttributeBuilder; 37 import org.opensaml.saml2.core.impl.AttributeImpl; 26 38 import org.opensaml.xml.io.MarshallingException; 39 import org.opensaml.xml.io.UnmarshallingException; 40 import org.opensaml.xml.parse.XMLParserException; 27 41 28 42 import org.earthsystemgrid.security.DnWhitelistX509TrustMgr; … … 105 119 } 106 120 107 /* 121 /** 108 122 * Call Attribute Service to retrieve user's e-mail address 123 * 124 * @param attributeServiceEndpoint 125 * @param openidURL 126 * @return 127 * @throws AttributeServiceQueryException 109 128 */ 110 129 protected InternetAddress queryAttributeService(URL attributeServiceEndpoint, 111 130 URL openidURL) throws AttributeServiceQueryException 112 131 { 113 String issuer = " my issuer";132 String issuer = "CN=localhost, OU=Security, O=NDG"; 114 133 SAMLAttributeServiceClientSoapImpl attributeServiceClient = 115 134 new SAMLAttributeServiceClientSoapImpl(issuer); 116 135 117 136 // Create query 137 AttributeBuilder attributeBuilder = new AttributeBuilder(); 138 Attribute emailAttribute = attributeBuilder.buildObject(); 139 emailAttribute.setName(SAMLParameters.EMAIL_ADDRESS); 140 emailAttribute.setFriendlyName(SAMLParameters.EMAIL_ADDRESS_FRIENDLY); 141 emailAttribute.setNameFormat("http://www.w3.org/2001/XMLSchema#string"); 142 143 List<Attribute> attributes = new ArrayList<Attribute>(); 144 attributes.add(emailAttribute); 145 118 146 String query = null; 119 147 try { 120 query = attributeServiceClient.buildAttributeRequest(openidURL.toString()); 148 query = attributeServiceClient.buildAttributeRequest( 149 openidURL.toString(), attributes); 150 121 151 } catch (MarshallingException e) { 122 152 throw new AttributeServiceQueryException("Marshalling attribute " + … … 148 178 } 149 179 connection.setSSLSocketFactory(socketFactory); 150 180 connection.setDoOutput(true); 181 182 try { 183 connection.setRequestMethod("POST"); 184 } catch (ProtocolException e) { 185 throw new AttributeServiceQueryException( 186 "Setting HTTP request method to \"POST\"", e); 187 } 188 189 OutputStream ops = null; 190 try { 191 ops = connection.getOutputStream(); 192 } catch (IOException e) { 193 throw new AttributeServiceQueryException( 194 "Getting output stream for attribute query", e); 195 } 196 197 OutputStreamWriter osw = new OutputStreamWriter(ops); 198 try { 199 osw.write(query); 200 osw.flush(); 201 osw.close(); 202 } catch (IOException e) { 203 throw new AttributeServiceQueryException( 204 "Error writing attribute query for dispatch", e); 205 } 206 151 207 InputStream ins = null; 152 208 try { … … 155 211 throw new AttributeServiceQueryException("Getting input stream", e); 156 212 } 213 157 214 InputStreamReader isr = new InputStreamReader(ins); 158 215 BufferedReader in = new BufferedReader(isr); … … 161 218 162 219 try { 163 while ((inputLine = in.readLine()) != null) 164 { 220 while ((inputLine = in.readLine()) != null) { 165 221 buf.append(inputLine); 166 222 buf.append(System.getProperty("line.separator")); … … 171 227 } 172 228 173 return buf.toString(); 174 175 return null; 176 } 229 /* 230 * Parse the response 231 */ 232 String response = buf.toString(); 233 SAMLAttributesImpl samlAttrs = null; 234 try { 235 samlAttrs = (SAMLAttributesImpl) 236 attributeServiceClient.parseAttributeResponse(response); 237 238 } catch (XMLParserException e) { 239 throw new AttributeServiceQueryException( 240 "Parsing attribute query response", e); 241 } catch (UnmarshallingException e) { 242 throw new AttributeServiceQueryException( 243 "Unmarshalling attribute query response", e); 244 } 245 246 String sEmail = samlAttrs.getEmail(); 247 if (sEmail == null) { 248 throw new AttributeServiceQueryException( 249 "Error retrieving e-mail address for user " + openidURL + 250 " from Attribute Service " + attributeServiceEndpoint); 251 } 252 253 InternetAddress email; 254 try { 255 email = new InternetAddress(sEmail); 256 } catch (AddressException e) { 257 throw new AttributeServiceQueryException( 258 "Error parsing e-mail address", e); 259 } 260 return email; 261 } 262 177 263 public static void main(String[] args) throws IOException, 178 264 NoMatchingXrdsServiceException, … … 181 267 AttributeServiceQueryException 182 268 { 183 OpenId2EmailAddrResolution openid2EmailAddr = new OpenId2EmailAddrResolution(); 269 // Input DNs from a file 270 InputStream propertiesFile = 271 DnWhitelistX509TrustMgr.class.getResourceAsStream( 272 "DnWhitelistX509TrustMgr.properties"); 273 274 OpenId2EmailAddrResolution openid2EmailAddr = new 275 OpenId2EmailAddrResolution(propertiesFile); 184 276 185 277 // URL yadisURL = new URL("https://ceda.ac.uk/openid/Philip.Kershaw"); 186 URL yadisURL = new URL("https://localhost:7443/openid/PJKershaw"); 187 InternetAddress emailAddr = null; 188 emailAddr = openid2EmailAddr.resolve(yadisURL); 278 URL yadisURL = new URL("https://localhost:7443/openid/philip.kershaw"); 279 280 InternetAddress email; 281 email = openid2EmailAddr.resolve(yadisURL); 282 System.out.println("OpenID: " + yadisURL.toString() + " resolves to " + 283 "e-mail address: " + email.toString()); 189 284 } 190 285 } -
TI12-security/trunk/EsgYadisParser/src/org/earthsystemgrid/security/yadis
-
Property
svn:ignore
set to
d573507a.der
test.ks
-
Property
svn:ignore
set to
Note: See TracChangeset
for help on using the changeset viewer.