package org.jboss.test;
import java.net.URL;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import org.jboss.security.auth.callback.UsernamePasswordHandler;
public class SRPLoginTest extends junit.framework.TestCase
{
public SRPLoginTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
String policyName = "tst-policy.xml";
URL policyURL = getClass().getClassLoader().getResource(policyName);
if( policyURL == null )
throw new IllegalStateException("Failed to find "+policyName+" in classpath");
}
public void testLogin()
{
CallbackHandler handler = new UsernamePasswordHandler("scott", "stark".toCharArray());
try
{
LoginContext lc = new LoginContext("srp-login", handler);
lc.login();
Subject subject = lc.getSubject();
System.out.println("Subject="+subject);
}
catch(LoginException e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
public static void main(String args[])
{
try
{
SRPLoginTest tst = new SRPLoginTest("main");
tst.setUp();
}
catch(Exception e)
{
e.printStackTrace(System.out);
}
}
}