1 22 package org.jboss.test; 23 24 import java.net.URL ; 25 import javax.security.auth.Subject ; 26 import javax.security.auth.callback.CallbackHandler ; 27 import javax.security.auth.login.LoginContext ; 28 import javax.security.auth.login.LoginException ; 29 30 import org.jboss.security.auth.callback.UsernamePasswordHandler; 31 32 39 public class SRPLoginTest extends junit.framework.TestCase 40 { 41 public SRPLoginTest(String name) 42 { 43 super(name); 44 } 45 46 49 protected void setUp() throws Exception 50 { 51 String policyName = "tst-policy.xml"; 53 URL policyURL = getClass().getClassLoader().getResource(policyName); 54 if( policyURL == null ) 55 throw new IllegalStateException ("Failed to find "+policyName+" in classpath"); 56 63 } 64 65 public void testLogin() 66 { 67 CallbackHandler handler = new UsernamePasswordHandler("scott", "stark".toCharArray()); 68 try 69 { 70 LoginContext lc = new LoginContext ("srp-login", handler); 71 lc.login(); 72 Subject subject = lc.getSubject(); 73 System.out.println("Subject="+subject); 74 } 75 catch(LoginException e) 76 { 77 e.printStackTrace(); 78 fail(e.getMessage()); 79 } 80 } 81 82 public static void main(String args[]) 83 { 84 try 85 { 86 SRPLoginTest tst = new SRPLoginTest("main"); 87 tst.setUp(); 88 } 89 catch(Exception e) 90 { 91 e.printStackTrace(System.out); 92 } 93 } 94 } 95 | Popular Tags |