Search code examples
javajspjaas

JAAS - why are my .jsp import's not working?


I have the below JSP file:

<%@page import="RdbmsLoginModule, PassiveCallbackHandler" %>
<%@page import="SessionLoginContext" %>
<%@page import="javax.security.auth.login.LoginContext, java.util.*" %>
<%@page import="java.io.*" %>

<!-- 
index.jsp: Simple JSP page to test a session-based LoginContext.
-->

<%
if(request.getParameter("user")==null) {
%>
<form action="jaas.jsp" method="POST">
    <input type=text name=user value=""><br>
    <input type=text name=pass value=""><br>
    <input type=submit value=submit>
</form>
<%
} else {
// just so you can see the debug messages
//System.setOut(new PrintStream(response.getOutputStream()));

String user = request.getParameter("user");
String pass = request.getParameter("pass");

PassiveCallbackHandler cbh = new PassiveCallbackHandler(user, pass);

SessionLoginContext lc = new SessionLoginContext("Example", cbh);

session.setMaxInactiveInterval(10); // 10 second timeout

// Setting the SessionLoginContext object in the Session 
// will trigger the valueBound() method in the object which 
// calls login() on the SessionLoginContext. Having set the 
// timeout to 10 seconds, the valueUnbound() method will be 
// called after 10 seconds of inactivity and log the user out.
//
session.setAttribute("loginContext", lc);

Iterator it = lc.getSubject().getPrincipals().iterator();
   while(it.hasNext()) out.println("authenticated principal: " + it.next().toString() + "<br>");

    it = lc.getSubject().getPublicCredentials(Properties.class).iterator();

  while (it.hasNext()) 
    out.println(it.next().toString());

  lc.logout();
 }
 %>

And I keep getting the following error:

 HTTP Status 500 -

 type Exception report

 message

 descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

 exception

 org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

 PWC6199: Generated servlet error:
 string:///index_jsp.java:6: '.' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:6: ';' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:7: class, interface, or enum expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:8: '.' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:8: ';' expected

 PWC6199: Generated servlet error:
 string:///index_jsp.java:9: class, interface, or enum expected

How is this caused and how can I solve it?


Solution

  • Okay, so I figured it out... was really silly when I think about it. I had to reference the other files by giving them their own folder, so to get my login screen to open it had to modify the above code as follows:

    <%@page import="RdbmsLoginModule.RdbmsLoginModule,PassiveCallbackHandler.PassiveCallbackHandler" %>         
    
    <%@page import="SessionLoginContext.SessionLoginContext" %>
    

    Furthermore To get those other classes to function properly, I had to put:

      package RdbmsLoginModule;// in the RdbmsLoginModule class
      package PassiveCallbackHandler; //in the PassiveCallbackHandler class
    
      etc. . . .
    

    Rookie stuff I know, but hey I'm a rookie. . . I'll never make that mistake again (at least and not know how to correct it:)

    Thanks everybody for trying to help.