KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > TstClient


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test;
23
24 import java.io.IOException JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26
27 import org.jboss.logging.Logger;
28 import org.apache.log4j.ConsoleAppender;
29 import org.apache.log4j.PatternLayout;
30
31 import org.jboss.security.srp.SRPClientSession;
32 import org.jboss.security.srp.SRPServerInterface;
33 import org.jboss.security.srp.SRPParameters;
34 import org.jboss.logging.XLevel;
35
36 /** A simple test client that looks up the SimpleSRPServer in the RMI
37 registry and attempts to validate the username and password passed
38 on the command line.
39
40  @author Scott.Stark@jboss.org
41  @version $Revision: 58118 $
42  */

43 public class TstClient
44 {
45    public static void main(String JavaDoc[] args) throws Exception JavaDoc
46    {
47       String JavaDoc username = args[0];
48       char[] password = args[1].toCharArray();
49       String JavaDoc serviceName = args.length == 3 ? args[2] : "srp-test/SRPServerInterface";
50
51       // Set up a simple configuration that logs on the console.
52
Logger root = Logger.getRoot();
53       root.setLevel(XLevel.TRACE);
54       root.addAppender(new ConsoleAppender(new PatternLayout("%x%m%n")));
55
56       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
57       SRPServerInterface server = (SRPServerInterface) ctx.lookup(serviceName);
58       System.out.println("Found SRPServerInterface, "+server);
59       SRPParameters params = server.getSRPParameters(username);
60       System.out.println("Found params for username: " + username);
61       SRPClientSession client = new SRPClientSession(username, password, params);
62       byte[] A = client.exponential();
63       byte[] B = server.init(username, A);
64       System.out.println("Sent A public key, got B public key");
65       byte[] M1 = client.response(B);
66       byte[] M2 = server.verify(username, M1);
67       System.out.println("Sent M1 challenge, got M2 challenge");
68       if (client.verify(M2) == false)
69          throw new SecurityException JavaDoc("Failed to validate server reply");
70       System.out.println("Validation successful");
71       server.close(username);
72    }
73 }
74
Popular Tags