<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page  import="java.util.Set" %>
<%@ page  import="javax.security.auth.Subject" %>
<%@ page  import="javax.security.auth.callback.CallbackHandler" %>
<%@ page  import="javax.security.auth.login.LoginContext" %>
<%@ page  import="javax.security.auth.login.LoginException" %>
<%@ page  import="org.jboss.security.SimplePrincipal" %>
<%@ page  import="org.jboss.security.auth.callback.SecurityAssociationHandler" %>
<%@ page  import="javax.servlet.http.HttpSession" %>


<%
String username= request.getParameter("userid");
String password= request.getParameter("pass");
try{
SecurityAssociationHandler handler = new    SecurityAssociationHandler();

SimplePrincipal  user = new SimplePrincipal(username);

handler.setSecurityInfo(user, password.toCharArray());

LoginContext loginContext = new LoginContext("example",(CallbackHandler)handler);

loginContext.login();
Subject subject = loginContext.getSubject();
Set principals = subject.getPrincipals();
principals.add(user);   
         
               HttpSession sess = request.getSession();
               sess.setAttribute("MySubject",loginContext.getSubject());
               
response.sendRedirect("main.html");
    }catch(LoginException e){ 
//errors.add("loginerror", new ActionError("Wrong Username or  Password")); //aveErrors(request, errors);
response.sendRedirect("login_failure.htm");
    }
%>