0

i'm trying to implement a User-Auth. App... I need to verify, if an user is already in my DB so he can login and operate some operations.

I use Wildfly as App. Server and JSF. I've got the H2 DB local installed. Hier my authentification code:

@SuppressWarnings("javadoc")
// @Stateless
@SessionScoped
@ManagedBean
@WebServlet(description = "Authentification", urlPatterns = { "/Authentification" })
public class Authentification extends HttpServlet implements Serializable {

    private static final long serialVersionUID = 1L;

    private String username;
    private String password;
    private String originalURL;

    @Inject
    private EntityService<Employee> userService;

    @Override
    public void init() throws ServletException {

    }

    @Override
    protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException {
        if (this.username != null && this.password != null) {
            final List<Employee> employees = userService.loadAll(Employee.FINDALL, Employee.class);

            for (final Employee employee : employees) {
                if (employee.getLastName() == this.username) {
                    System.out.println(this.username + " found!");
                    response.sendRedirect("index.xhtml");
                } else {
                    System.out.println(this.username + " not found!");
                }
            }
        }
    }

    public void lotout() {
        final FacesContext context = FacesContext.getCurrentInstance();
        final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        try {
            // TODO: Abmelden
            request.logout();
        } catch (final ServletException e) {
            // TODO: Exceptionsbehandlung
            context.addMessage(null, new FacesMessage("Logout failed."));
        }
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(final String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(final String password) {
        this.password = password;
    }

    public String getOriginalURL() {
        return originalURL;
    }

    public void setOriginalURL(final String originalURL) {
        this.originalURL = originalURL;
    }
}

And now my xhtml-page:

<!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://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:form>
        <h:outputLabel for="username" value="Username" />
        <h:inputText id="username" value="#{Authentification.username}" 
        maxsize="20" required="true" />
        <br />
        <h:outputLabel for="password" value="Password" />
        <h:inputSecret id="password" value="#{Authentification.password}" 
        maxsize="10" required="true" />
        <br />
        <h:commandButton value="Login"
                    action="#{Authentification.doPost}" />
    </h:form>
</html>

Once i start the App. i got this Error from Wildfly:

16:41:31,760 ERROR [io.undertow.request] (default task-30) UT005023: Exception handling request to /sep-gruppe-5/login.xhtml;jsessionid=sDqBv4bcos5dJznjwBhmQv2nXxPlWt9HVlsYwXXl.w1289: javax.servlet.ServletException: /login.xhtml @10,37 value="#{Authentification.username}": Target Unreachable, identifier 'Authentification' resolved to null
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:667)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

And the most important part i guess is:

Caused by: javax.el.PropertyNotFoundException: /login.xhtml @10,37 value="#{Authentification.username}": Target Unreachable, identifier 'Authentification' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)

I don't know what i'm missing now... the App. can't finde the Class Authentification... Why this? Please help.

Lycone
  • 561
  • 5
  • 16
  • Change `#{Authentification.property}` to `#{authentification.property}`. ManagedBean javadoc: `If the value of the name attribute is unspecified or is the empty String, the managed-bean-name is derived from taking the unqualified class name portion of the fully qualified class name and converting the first character to lower case.` – Mathieu Castets Oct 28 '15 at 16:08
  • and search stackoverflow for identical errors... lots posts about this with answers – Kukeltje Oct 28 '15 at 16:08
  • 2
    Apart from the exception which is already answered in the duplicate, you've there a design problem. You mixed Servlet and JSF APIs and seemingly assume that you end up with only one instance of the class. This is untrue. Servlet has its own application scoped instance and JSF has its own session scoped instance which do not in any way share data. You don't need the Servlet part at all. Head to http://stackoverflow.com/a/2207147 – BalusC Oct 28 '15 at 19:50

0 Answers0