Esempio n. 1
0
  public SecurityToken logon(
      String anEndpointReference, String aUserName, String aPassword, String anApplicationID)
      throws LogonManagerException, SOAPException, IOException {
    SecurityToken result;
    SOAPMessage message;
    SOAPConnection conn = null;

    try {
      result = null;
      String request =
          REQUEST_FORMAT.format(
              ((Object) (new Object[] {fURL, aUserName, aPassword, anEndpointReference})));
      message =
          MessageFactory.newInstance()
              .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes()));
      conn = SOAPConnectionFactory.newInstance().createConnection();
      SOAPMessage response = conn.call(message, fURL);
      SOAPBody body = response.getSOAPBody();
      if (body.hasFault()) throw new LogonManagerException(body.getFault());
      result = new SecurityToken();
      result.setSOAPBody(body);
      for (Iterator it = body.getChildElements(); it.hasNext(); fill(result, (Node) it.next())) ;
      return result;
    } finally {
      if (conn != null) conn.close();
    }
  }
Esempio n. 2
0
 public static void main(String args[]) {
   if (args.length > 1)
     try {
       SecurityToken securityToken = (new LogonManager()).logon("live.com", args[0], args[1]);
       System.out.println("Logon succeeded!");
       System.out.println("Passport Token: " + securityToken.getBinarySecurityToken());
       System.out.println("Issue Date:     " + securityToken.getIssueDate());
       System.out.println("Expire Date:    " + securityToken.getExpireDate());
     } catch (LogonManagerException lm) {
       System.out.println("Logon failed: " + lm.getDetailedMessage());
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   System.exit(0);
 }
Esempio n. 3
0
 protected void fill(SecurityToken aSecurityToken, Node aNode) {
   if ("BinarySecurityToken".equalsIgnoreCase(aNode.getLocalName())) {
     NodeList children = aNode.getChildNodes();
     if (children.getLength() > 0)
       aSecurityToken.setBinarySecurityToken(children.item(0).getNodeValue());
   } else if ("Created".equalsIgnoreCase(aNode.getLocalName())) {
     NodeList children = aNode.getChildNodes();
     if (children.getLength() > 0)
       aSecurityToken.setIssueDate(parseDate(children.item(0).getNodeValue()));
   } else if ("Expires".equalsIgnoreCase(aNode.getLocalName())) {
     NodeList children = aNode.getChildNodes();
     if (children.getLength() > 0)
       aSecurityToken.setExpireDate(parseDate(children.item(0).getNodeValue()));
   } else if (aNode.hasChildNodes()) {
     NodeList list = aNode.getChildNodes();
     for (int i = 0; i < list.getLength(); i++) fill(aSecurityToken, list.item(i));
   }
 }