Results 1 to 13 of 13
  1. #1
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default JSF, Glassfish and logging out

    Hello,
    I am having a problem trying to create a JavaBean for JSF that will log a user out from a basic login from Glassfish. Here is partial code from my bean:

    Java Code:
    public void setLogOut()
        this.userName = request.getRemoteuser(); //For debugging
        request.getSession().invalidate();  //request is HttpServletRequest
        try{
            request.logout();
            FacesContext.getCurrentInstance().getExternalContext().redirect("../../")
            //Rest is just debugging and error handling
    The code acts like it works as I get sent beck to my home page, but user stays logged in even though I clearly see the bean running in the Netbeans debugger. Am I missing something here?

  2. #2
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    I just realized that I don't need to Invalidate and use the logout. However, this still isn't working.

  3. #3
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    So now that I have been looking though some more forms, I can't logout the user because Glassfish basic auth method stores the session on the server. I need to use a form method. I'll try that out and see where that gets me. If anyone knows how to force the user session on the server without exiting the browser, let

  4. #4
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Ok....So I got it working in the form method. But I can only use HTML. Does anyone know how to make this work in xHTML? Every time I program the web.xml to point at the login.xhtml file, the browser tries and download the next page instead of giving me the login page.

  5. #5
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Can anyone tell me why the template here wont load and why it dumps me to the file default.css. I'm trying to use xhtml for my login screen and this part isn't working right

    login.xhtml
    Java Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html">
    
        <body>
    
            <ui:composition template="./maintemplate.xhtml">
    
                <ui:define name="top">
                    
                        
                </ui:define>
    
                <ui:define name="left">
                    left
                </ui:define>
    
                <ui:define name="content">
                    <p>You have to log in to access this page</p>
                    <form action="j_security_check" method="POST">
                        Username:<input type="text" name="j_username"></input>
                        Password:<input type="password" name="j_password"></input>
                        <input type="submit" value="Login"></input>
                    </form>
                </ui:define>
    
                <ui:define name="bottom">
                    bottom
                </ui:define>
    
            </ui:composition>
    
        </body>
    </html>
    maintemplate.xhtml
    Java Code:
    <?xml version='1.0' encoding='UTF-8' ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
          xmlns:h="http://xmlns.jcp.org/jsf/html">
    
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
            <link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
            <title>Facelets Template</title>
        </h:head>
    
        <h:body>
    
            <div id="top">
                <ui:insert name="top">Top</ui:insert>
            </div>
            <div>
                <div id="left">
                    <ui:insert name="left">Left</ui:insert>
                </div>
                <div id="content" class="left_content">
                    <ui:insert name="content">Content</ui:insert>
                </div>
            </div>
            <div id="bottom">
                <ui:insert name="bottom">Bottom</ui:insert>
            </div>
    
        </h:body>
    
    </html>

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: JSF, Glassfish and logging out

    Congratulations, you have managed to cause something I have never seen before, nor would I have a single idea how you would cause that to happen in any way.

    I don't see anything particularly wrong with the XHTML files, other than your odd tendency to start relative paths with "./". Don't do that, it is highly unnecessary and error-prone. Just use relative paths like "resources/css/default.css". Post your web.xml file, just to be sure there is nothing odd in there.

    EDIT: wait, the namespaces are also quite odd to me. Regular JSF namespaces would be:

    Java Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets">
    Last edited by gimbal2; 10-23-2013 at 09:13 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Thanks Gimbal for the reply. Here is the odd thing. These files are self generated by Netbeans. It's putting the ./ there. I just never bothered to remove it. Also the namespace is auto generated. I'm using JSF 2.1 if that makes a difference. here is my Web.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>faces/index.xhtml</welcome-file>
        </welcome-file-list>
        <security-constraint>
            <display-name>AdminConstraint</display-name>
            <web-resource-collection>
                <web-resource-name>Admin</web-resource-name>
                <description/>
                <url-pattern>/faces/secureAdmin/*</url-pattern>
            </web-resource-collection>
            <auth-constraint>
                <description/>
                <role-name>AdminRole</role-name>
            </auth-constraint>
        </security-constraint>
        <security-constraint>
            <display-name>UserConstraint</display-name>
            <web-resource-collection>
                <web-resource-name>User</web-resource-name>
                <description/>
                <url-pattern>/faces/secureUser/*</url-pattern>
            </web-resource-collection>
            <auth-constraint>
                <description/>
                <role-name>UserRole</role-name>
            </auth-constraint>
        </security-constraint>
        <login-config>
            <auth-method>FORM</auth-method>
            <realm-name>file</realm-name>
            <form-login-config>
                <form-login-page>/faces/login.xhtml</form-login-page>
                <form-error-page>/faces/loginError.xhtml</form-error-page>
            </form-login-config>
        </login-config>
        <security-role>
            <description/>
            <role-name>AdminRole</role-name>
        </security-role>
        <security-role>
            <description/>
            <role-name>UserRole</role-name>
        </security-role>
    </web-app>
    Another thing that is confusing me is the template is also generating an extra HTML and BODY tag. Here is the source I get from this generation:

    Java Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    
        <body><html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt3">
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link href="resources/css/default.css" rel="stylesheet" type="text/css" />
            <link href="resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
            <title>Facelets Template</title></head><body>
    
            <div id="top">
                    <form action="j_security_check" method="POST">
                        Username:<input type="text" name="j_username" />
                        Password:<input type="password" name="j_password" />
                        <input type="submit" value="Login" />
                    </form>
            </div>
            <div>
                <div id="left">
                    left
                
                </div>
                <div id="content" class="left_content">
                    content
                
                </div>
            </div>
            <div id="bottom">
                    bottom
                
            </div></body>
    
    </html>
    
        </body>
    </html>
    (Sorry for the format. Chrome is being dumb)

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: JSF, Glassfish and logging out

    These files are self generated by Netbeans.
    Only if you use wizards - don't do that when you are don't have the expertise yet. Create all files by hand when you're learning. Which means you'll have to learn how to do all that, which is actually a required effort on your part. Your best bet is to get a good book on JSF and not rely on Netbeans.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Thanks Gimbal. I don't always rely on the wizard. JSF is still pretty new to me and I learn quicker if I see how its done. I'm more of a hands on and books don't do me too much justice. The wizard is just giving me an idea of what is going on. That being said, I do like to use quick guides (books).

  10. #10
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: JSF, Glassfish and logging out

    If that were true, this thread wouldn't exist. Fact of the matter is: you don't know what to do. And the wizard isn't going to tell you what to do or WHY it does what it does. It just does something, it doesn't work and now you're stuck and need to go to a forum to even make hello world work. Sorry but that to me isn't a learning process - that's the opposite of it.

    A (good) book on the other hand is written to actually make you UNDERSTAND how it works in stead of only showing you where to click and will so fill that knowledge gap making you capable to actually be productive quicker. I hope some day you realize that - making the effort to read and study ultimately saves you lots of time.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Do you have any suggestions for a book? This is a school project so I don't have a lot of time as my due date is soon and I have to use some type of MVC. Otherwise I would have figured this out myself and wouldn't be asking on the forms. Maybe I should go back to Ruby on Rails but I want a project done in Java since my college courses were in Java. Trust me, I will be going back and actually learning this in more depth, but for now, it is what it is. I just don't have time to learn JSF like I would like to.

    I have a JSF page working when I don't use login security. What I don't understand is why when I through the page to login screen, it seems breaks the framework. It seems that Glassfish is the problem. It's not that I don't know what to do. This thread exist because the problem I'm having just doesn't make sense. I know what your saying.
    A (good) book on the other hand is written to actually make you UNDERSTAND
    Just please understand I have a short timeline. I'm not asking for a free handout, just some help from some fellow programmers.

  12. #12
    will71110 is offline Member
    Join Date
    Oct 2013
    Posts
    14
    Rep Power
    0

    Default Re: JSF, Glassfish and logging out

    Maybe I'll come back to this later. I am going to just use HTML site as my login as it works with no issues this way.

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: JSF, Glassfish and logging out

    Quote Originally Posted by will71110 View Post
    Thanks Gimbal for the reply. Here is the odd thing. These files are self generated by Netbeans.
    Bit of a necro, but I need to correct my own failure here: I have since learned that the namespace that was generated by Netbeans is actually because in JEE7 / JSF 2.2, the namespaces have changed again (thanks JSF devs!). Luckily the old namespaces that I posted for JSF 2.0/2.1 still work in JSF 2.2, so I didn't spread falsehood that breaks anything.

    And its all the more proof that it is vitally important that you are specific about which platform you're developing for. That will be all, class dismissed.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. JNI, C DLL and glassfish
    By qin__23 in forum Advanced Java
    Replies: 13
    Last Post: 04-30-2012, 05:01 PM
  2. Glassfish v3 Problem
    By jaikumar in forum Java Servlet
    Replies: 0
    Last Post: 02-19-2012, 02:01 PM
  3. GlassFish v3
    By ashin in forum NetBeans
    Replies: 2
    Last Post: 07-19-2011, 09:55 AM
  4. glassfish problem
    By ondra in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-21-2010, 01:20 AM
  5. Glassfish
    By ronguilmet in forum New To Java
    Replies: 0
    Last Post: 11-15-2009, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •