Đang chuẩn bị liên kết để tải về tài liệu:
Programming Web Services with SOAPn phần 7
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Cuối cùng, chúng ta có thể sử dụng phím chuẩn bị để ký khẳng định. Các hoạt động ký vào các đối tượng SignatureContext xử lý các quá trình mã hóa phức tạp để tạo ra chữ ký (xem ví dụ 7-26). Sau khi khẳng định đã được ký kết, chúng tôi trở lại các phần tử DOM có chứa các chữ ký vừa tạo ra | Programming Web Services with SOAP KeyStore keystore KeyStore.getInstance JKS keystore.load new FileInputStream keystorepath storepass.toCharArray X509Certificate cert X509Certificate keystore.getCertificate alias Key key keystore.getKey alias keypass.toCharArray if key null throw new IllegalArgumentException Invalid Key Info KeyInfo keyInfo new KeyInfo KeyInfo.X509Data x5data new KeyInfo.X509Data x5data.setCertificate cert x5data.setParameters cert true true true keyInfo.setX509Data new KeyInfo.X509Data x5data keyInfo.setKeyValue cert.getPublicKey siggen.setKeyInfoGenerator keyInfo Finally we can use the prepared key to sign the assertion. The sign operation on the SignatureContext object handles the complex cryptographic processes to create the signature see Example 7-26 . Once the assertion has been signed we return the DOM element that contains the signature just created. Example 7-26. Signing the assertion Element sig siggen.getSignatureElement SignatureContext context new SignatureContext context.sign sig key return sig 7.5.3.4 The login operation The encryption code is used in the login operation shown in Example 7-27. It verifies the user s password generates the SAML assertion and signs it. Example 7-27. The login operation public static Element login String userid String password throws Exception Element el doc.getDocumentElement NodeList nl el.getElementsByTagName user for int n 0 n nl.getLength n Element e Element nl.item n if e.getAttribute id .equals userid e.getAttribute password .equals password AuthenticationAssertion aa AssertionFactory.newInstance new String new Long System.currentTimeMillis .toString CodeShare.org new java.util.Date userid CodeShare.org http codeshare.org new java.util.Date java.net.InetAddress.getLocalHost . getHostAddress page 135 Programming Web Services with SOAP java.net.InetAddress.getLocalHost .getHostName Element sa AssertionSigner.sign aa CodeShare.db CodeShare CodeShareKeyPass CodeShareStorePass return sa return null .