9 Replies Latest reply on Jan 18, 2010 6:27 AM by Sylvio Galdino

    Seam Authenticator

    Sylvio Galdino Newbie
      I did a seam project and I started him in the tomcat6 without problem but when I try make login(username: admin, password:"blank") the system show the message "Login failed". I tried put a break point for debug in the method 'authenticate' of the class 'Authenticator' but I think that it never is called because break point and System.out.println() don't work. Could someone help me?

      Authenticator.java
      ----------------------------
      package org.domain.siso.session;

      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Credentials;
      import org.jboss.seam.security.Identity;

      @Name("authenticator")
      public class Authenticator
      {
          @Logger private Log log;

          @In Identity identity;
          @In Credentials credentials;
        
         
          public boolean authenticate()
          {
              log.info("authenticating {0}", credentials.getUsername());
              //write your authentication logic here,
              //return true if the authentication was
              //successful, false otherwise
              if ("admin".equals(credentials.getUsername()))
              {
                  identity.addRole("admin");
                  return true;
              }
              return false;
          }

      }
      ----------------------------

      components.xml
      ----------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:excel="http://jboss.com/products/seam/excel"
                  xmlns:document="http://jboss.com/products/seam/document"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:framework="http://jboss.com/products/seam/framework"
                  xmlns:async="http://jboss.com/products/seam/async"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                       http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.1.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                       http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd
                       http://jboss.com/products/seam/excel http://jboss.com/products/seam/excel-2.1.xsd
                       http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd">

         <core:manager concurrent-request-timeout="500"
                       conversation-timeout="120000"
                       conversation-id-parameter="cid"
                       parent-conversation-id-parameter="pid"/>
              
         <document:document-store use-extensions="true"></document:document-store>
        
         <transaction:entity-transaction entity-manager="#{entityManager}"/>

         <persistence:managed-persistence-context name="entityManager"
                                                      auto-create="true"
                                entity-manager-factory="#{Siso}"/>
                               
         <persistence:entity-manager-factory name="Siso"/>

         <security:identity authenticate-method="#{authenticator.authenticate}"/>
        
         <async:quartz-dispatcher/>

         <event type="org.jboss.seam.security.notLoggedIn">
            <action execute="#{redirect.captureCurrentView}"/>
         </event>
         <event type="org.jboss.seam.security.loginSuccessful">
            <action execute="#{redirect.returnToCapturedView}"/>
         </event>
      </components>
      ----------------------------

      login.xhtml
      ----------------------------
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          template="layout/template.xhtml">

      <ui:define name="body">

          <h:form id="loginForm">

              <rich:panel>
                  <f:facet name="header">Login</f:facet>

                  <p>Please login here</p>

                  <div class="dialog">
                      <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
                          <h:outputLabel for="username">Username</h:outputLabel>
                          <h:inputText id="username"
                                    value="#{credentials.username}"/>
                          <h:outputLabel for="password">Password</h:outputLabel>
                          <h:inputSecret id="password"
                                      value="#{credentials.password}"/>
                          <h:outputLabel for="rememberMe">Remember me</h:outputLabel>
                          <h:selectBooleanCheckbox id="rememberMe"
                                                value="#{rememberMe.enabled}"/>
                      </h:panelGrid>
                  </div>

                  <p>
                    <i>Note - </i> You may login with the username 'admin' and a blank password.
                  </p>

              </rich:panel>

              <div class="actionButtons">
                  <h:commandButton id="submit" value="Login" action="#{identity.login}"/>
              </div>

          </h:form>

      </ui:define>
      </ui:composition>
      ----------------------------