1 2 Previous Next 24 Replies Latest reply on Oct 9, 2002 6:33 PM by kernel000

    Need help with FORM-based authentication (Jboss Developer He

    kenryu

      hi everyone;
      I tried to make the FORM based authentication work using Jboss 3.0.2 in windows 2000 but whenever I tried to login (http://localhost:8080/loginTest/index.jsp), I alwalys got the error page even though I successfuly login and got this message from Jboss:
      "WARN [JBossUserRealm#testDB] authentication failure: null"
      I also can still see the welcome page (http://localhost:8080/loginTest/) even though it's in secured folder which user can only see if you're login. But if I login using http://localhost:8080/loginTest/secured/welcome.jsp
      then it will bring me to the login page(index.jsp) that will take me to the welcome page if I login correctly.

      This is my login file (index.jsp):




      <!-- you can also use this : -->

      <!---->



      Username:
      Password:





      this is what I configured in login-config.xml
      ===========================

      <application-policy name = "testDB">

      <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
      flag = "required">
      <module-option name = "dsJndiName">java:/MSSQLDS</module-option>
      <module-option name = "principal">tj</module-option>

      <module-option name = "principalsQuery">select passwd from Users username where username=?</module-option>
      <module-option name = "rolesQuery">select userRoles, 'Roles' from UserRoles where username=?</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>

      </login-module>

      </application-policy>


      this is my jboss-web.xml
      ========================

      <jboss-web>
      <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</security-domain>
      -->

      <security-domain>java:/jaas/testDB</security-domain>


      </jboss-web>

      this is my web.xml
      ==================
      <?xml version="1.0"?>
      <!DOCTYPE web-app PUBLIC
      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">

      <web-app>
      <!--make sure to put the welcome-file-list before security-constraint tag-->
      <!--otherwise it will complain and does not work-->
      <!--if welcome-file contains : /secured/welcome.jsp then it will complain(but sometimes NOT)-->
      <!-- so you have to take / to be: secured/welcome.jsp so that it will not -->
      <!--complain again-->

      <welcome-file-list>
      <welcome-file>secured/welcome.jsp</welcome-file>
      </welcome-file-list>

      <security-constraint>
      <web-resource-collection>
      <web-resource-name>customer</web-resource-name>
      <!-- Define the context-relative URL(s) to be protected -->
      <url-pattern>/secured/*</url-pattern>
      <!-- If you list http methods, only those methods are protected -->
      <http-method>DELETE</http-method>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
      <http-method>PUT</http-method>
      </web-resource-collection>

      <auth-constraint>
      <!-- Anyone with one of the listed roles may access this area -->
      <role-name>customer</role-name>
      <role-name>manager</role-name>
      </auth-constraint>
      <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
      </user-data-constraint>
      </security-constraint>


      <!-- Default login configuration uses form-based authentication -->
      <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>testDB</realm-name>
      <form-login-config>
      <form-login-page>/index.jsp</form-login-page>
      <form-error-page>/error.jsp</form-error-page>
      </form-login-config>
      </login-config>

      <!--security-role>
      <role-name>customer</role-name>
      </security-role-->
      </web-app>



      I have read some couple posting in forum but I still don't see any complete working example for Jboss3.0.2 (including the .jsp page). Could anybody please post one working example ? I have posted couple questions before but I haven't had any help from the forum so please need help maybe somebody from Jboss Developer?

        • 1. Re: Need help with FORM-based authentication (Jboss Develope
          chgrimm

          i don't know if this is the error, but in your web.xml
          you have been setting the security role in comments:

          <!--security-role>
          <role-name>customer</role-name>
          </security-role-->

          also the manager role , you are using in the auth constraint is missing.

          • 2. Re: Need help with FORM-based authentication (Jboss Develope
            tdhak

            In your login.jsp, your user name field is j_subject, I'm pretty sure that should be j_username.

            • 3. Re: Need help with FORM-based authentication (Jboss Develope
              kenryu

              hi all;
              Thank's for replying and attaching me the example. I've modified the jsp page and web.xml but I'm still having problem. Also could anybody please attaching me example without struts? I just want to have a simple example up and running first.

              Let me explain it more to you.
              if I type: http://localhost:8080/loginTest/index.jsp
              and then try to login from there then error page will be displayed and when I tried to print
              request.getRemoteUser() in the error page , I got null as a result and I got false when I try to print out request.isUserInRole("AuthorisedUser").
              BUT when I try : http://localhost:8080/loginTest/secured/welcome.jsp which is the welcome page that should be displayed after succesful login, Jboss will take me to the index.jsp (which is the login page) and then if I login from there then it works!! but I still got false when I try to print the result of request.isUserInRole("AuthorisedUser"). Is this the right behaviour? and what JBoss version are you guys using? I'm using JBOSS 3.0.2 that comes with jetty. Please help me guys!!!! I'm running out of options here.
              Please attach me with simple example also if you don't mind. Thank's

              jsp page:
              =======







              Username:
              Password:





              my new web.xml
              =============
              <?xml version="1.0"?>
              <!DOCTYPE web-app PUBLIC
              "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
              "http://java.sun.com/dtd/web-app_2_3.dtd">

              <web-app>
              <!--make sure to put the welcome-file-list before security-constraint tag-->
              <!--otherwise it will complain and does not work-->
              <!--if welcome-file contains : /secured/welcome.jsp then it will complain(but sometimes NOT)-->
              <!-- so you have to take / to be: secured/welcome.jsp so that it will not -->
              <!--complain again-->

              <welcome-file-list>
              <welcome-file>secured/welcome.jsp</welcome-file>
              </welcome-file-list>

              <security-constraint>
              <web-resource-collection>
              <web-resource-name>customer</web-resource-name>
              <!-- Define the context-relative URL(s) to be protected -->
              <url-pattern>/secured/*</url-pattern>
              <!-- If you list http methods, only those methods are protected -->
              <http-method>DELETE</http-method>
              <http-method>GET</http-method>
              <http-method>POST</http-method>
              <http-method>PUT</http-method>
              </web-resource-collection>

              <auth-constraint>
              <!-- Anyone with one of the listed roles may access this area -->
              <!--<role-name>customer</role-name>-->
              <!--<role-name>manager</role-name>-->
              <role-name>*</role-name>
              </auth-constraint>
              <user-data-constraint>
              <transport-guarantee>NONE</transport-guarantee>
              </user-data-constraint>
              </security-constraint>


              <!-- Default login configuration uses form-based authentication -->
              <login-config>
              <auth-method>FORM</auth-method>
              <realm-name>testDB</realm-name>
              <form-login-config>
              <form-login-page>/index.jsp</form-login-page>
              <form-error-page>/error.jsp</form-error-page>
              </form-login-config>
              </login-config>


              <security-role>
              <role-name>customer</role-name>
              </security-role>
              </web-app>

              • 4. Re: Need help with FORM-based authentication (Jboss Develope
                chgrimm

                index.jsp is your login page, you should never navigate directly to this page! see it just as a replacement for the browsers popup window in basic login.
                don't include it in your application's document flow, the container does for you if a login is necessary!!!

                best pratice is to name it login_somewhat.jsp because the name index.jsp one normally uses for a default page that is displayed if the user uses a directory link rather than a file link.

                btw: my personal approach to test web-apps with secured areas is to work with basic authentication until erverything else works and as the last step i then switch to form based login.

                • 5. Re: Need help with FORM-based authentication (Jboss Develope
                  kenryu

                  hi;
                  Thank's for replying. If you don't mind then can you attached complete working example ? I really appreciate it if you do since I've been struggling to make this work for weeks. Please reply . thank you very much before


                  ^_^

                  • 6. Re: Need help with FORM-based authentication (Jboss Develope
                    chgrimm

                    attachment is not there
                    pls. send me an email instead

                    • 7. Re: Need help with FORM-based authentication (Jboss Develope
                      kenryu

                      hi;
                      I have send you an email, please check if you have received it.

                      Thank's!
                      ^_^

                      • 8. Re: Need help with FORM-based authentication (Jboss Develope
                        chgrimm

                        here's the example
                        put the .properties file in your server's conf directory

                        • 9. Re: Need help with FORM-based authentication (Jboss Develope
                          kenryu

                          hi;
                          Thank's I'll try it. Can you also send me the FORM authentication using DatabaseServerLoginModule example please? I actually need that more than other example. Anyway thank you very much before I appreciate it!.


                          ^_^

                          • 10. Re: Need help with FORM-based authentication (Jboss Develope
                            kenryu

                            hi;
                            Thank's I'll try it. Can you also send me the FORM authentication using DatabaseServerLoginModule example please? I actually need that more than other example. Anyway thank you very much before I appreciate it!.


                            ^_^

                            • 11. Re: Need help with FORM-based authentication (Jboss Develope
                              kenryu

                              hi;
                              Thank's I'll try it. Can you also send me the FORM authentication using DatabaseServerLoginModule example please? I actually need that more than other example. Anyway thank you very much before I appreciate it!.


                              ^_^

                              • 12. Re: Need help with FORM-based authentication (Jboss Develope
                                kenryu

                                hi;
                                Thank's I'll try it. Can you also send me the FORM authentication using DatabaseServerLoginModule example please? I actually need that more than other example. Anyway thank you very much before I appreciate it!.


                                ^_^

                                • 13. Re: Need help with FORM-based authentication (Jboss Develope
                                  kenryu

                                  hi;
                                  Thank's I'll try it. Can you also send me the FORM authentication using DatabaseServerLoginModule example please? I actually need that more than other example. Anyway thank you very much before I appreciate it!.


                                  ^_^

                                  • 14. Re: Need help with FORM-based authentication (Jboss Develope
                                    kenryu

                                    hi;
                                    Sorry if my message got posted many times. I don't know why it happens like this.

                                    ^_^

                                    1 2 Previous Next