13 Replies Latest reply on Dec 29, 2006 4:37 AM by waheed.murad

    how to force Logging for page access ??

    waheed.murad

      What i want is that whenever a user access a page by typing a direct url in the browser e.g "http://localhost:8080/myproject/mypage.jsp" , the page should only be opened if user is loggedin else it should go to some other page. how ?????

      i have written the interceptor as given in booking example (LoggedIn) and used it on the corrosponding sessionbean class but its not working fine.......
      it goes well when user is loggedin but in other case exception etc......

        • 1. Re: how to force Logging for page access ??
          vincecallagan

          May be you can put some security-contraints in your web.xml ?

          • 2. Re: how to force Logging for page access ??

            I find that page actions in pages.xml work much better for that type of control than interceptors. See the DVD Store for an examples.

            • 3. Re: how to force Logging for page access ??
              waheed.murad

              thanks norman richards for help
              i have tried the same thing as told by u but it has some problem

              This is my entry in the page.xml
              <page view-id="/secretquestions.jsp" action="#{SecretQuestionsAction.checkLoggedIn}" />

              here is my checkLoggedIn function...

              public String checkLoggedIn(){
              boolean isLoggedIn = sessionContext.get("loggedIn")!=null;

              if (isLoggedIn){
              return null; // Go to secretquestions.jsp.
              }else{
              return "loginpage"; // go to login page.
              }
              }

              when it returns null it does not open secretquestions.jsp it opens the login page.

              • 4. Re: how to force Logging for page access ??

                Are you hitting /secretquestions.seam directly? Make sure you are returning the value you think you are, and check that you don't have some other actions or navigation rules interfering. The basic mechanism works exactly as shown above.

                • 5. Re: how to force Logging for page access ??

                  Here's a trivial example I just test. I generated a stub seam-gen app and add two pages: private.xhtml and nope.xhtml. I attached a page action to private.xhtml: (this is equivalent to adding the action to pages.xml)

                  private.page.xhtml

                  <!DOCTYPE page PUBLIC
                   "-//JBoss/Seam Pages Configuration DTD 1.1//EN"
                   "http://jboss.com/products/seam/pages-1.1.dtd">
                  
                  <page action="#{check.check}" />
                  


                  Check.java:
                  package example;
                  
                  import org.jboss.seam.annotations.*;
                  
                  @Name("check")
                  public class Check {
                   @RequestParameter
                   String secret;
                  
                   public String check() {
                   return secret==null ? "/nope.xhtml" : null;
                   }
                  
                  }


                  "/private.seam" shows the content of the nope page and "/private/seam?secret=" shows the content of the private page.


                  Hope that helps in your debugging effort.

                  • 6. Re: how to force Logging for page access ??
                    waheed.murad

                    i cannot understood hitting page directly . if you mean that i am accessing by typing URL in the browser then it works fine it goes to login page(as i am not logged in) but when a login and goes to admin page given below and try to access the sceretquestion.jsp it still goes to login page.

                    i have cleared all the navigations from faces-config.xml and i only have one action as told before in my pages.xml

                    here is my jsf page:

                    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
                    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
                    <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s" %>




                    Administrator Console






                    <f:view>
                    <h:form>

                    <h:commandButton id="secquestion" value="Secret Question" action="/secretquestions.jsp"/> <h:commandButton id="pricingops" value="Pricing Options" action="/pricingoptions.jsp"/>
                    <h:commandButton id="organization" value="Organizations" action="/customerorganizations.jsp"/>
                    <h:commandButton id="categories" value="Categories" action=""/>
                    <h:commandButton id="role" value="Roles" action="/roles.jsp"/>
                    <h:commandButton id="privileges" value="Privileges" action="/privileges.jsp"/>
                    <h:commandButton id="paymodes" value="Payment Modes" action=""/>
                    <h:commandButton id="currencies" value="Currencies" action=""/>

                    </h:form>
                    </f:view>




                    • 7. Re: how to force Logging for page access ??

                      I do not believe that you are clicking on that link and returning null and somehow landing on a third (login) page. Either you are not actually returning null from the login check or you something else besides what you are showing that is interfering.

                      • 8. Re: how to force Logging for page access ??
                        waheed.murad

                        i shall be trying to debug by making some dummy application and the proceeding to my application hopefully reaching to the problem. But however thanks again for your help norman richards.

                        • 9. Re: how to force Logging for page access ??
                          waheed.murad


                          if (isLoggedIn){
                          System.out.println(" Returing null");
                          return null; // Go to secretquestions.jsp.
                          }else{
                          return "loginpage"; // go to login page.
                          }

                          well i have "Returing null" String displayed on my console so i its abvious that it is returning null output. i think i have do start from dummy application.... to debug it whats your suggestion

                          • 10. Re: how to force Logging for page access ??

                            Are you sure you don't have some other navigation rule or action involved here?

                            • 11. Re: how to force Logging for page access ??
                              waheed.murad

                              Ya i am sure because i have tried with no navigation rule in my faces-config.xml and only one page action in my pages.xml so i think there should be no other interfernces and i do not think that there is any other file that is part of this process......

                              • 12. Re: how to force Logging for page access ??

                                Wow - ok. I'm at a loss. Please post an EAR file and I'll take a look.

                                • 13. Re: how to force Logging for page access ??
                                  waheed.murad

                                  well i have solved the problem. i was reducing the code to send you , and i came to know that conflict was between the JSTL library and the seam pages.xml action...

                                  thanks a lot for your help......