Seam security - identity login never gets invoked
infinity2heaven Jun 3, 2008 1:50 AMI've followed Seam Security Reference (also Seam in Action), step by step, however I'm stuck with this rather bizzare problem the whole day. the action #{identity.login} never gets invoked from the login page. However changing it to #{authenticator.authenticat} works.
login.xhtml
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib">
<h:form id="login">
<h:panelGrid columns="2">
<h:outputLabel for="username">Username</h:outputLabel>
<h:inputText id="username" value="#{identity.username}"/>
<h:outputLabel for="password">Password</h:outputLabel>
<h:inputSecret id="password" value="#{identity.password}"/>
</h:panelGrid>
<div>
<h:commandButton value="Login" action="#{identity.login}"/>
</div>
</h:form>
</html>
Authenticator
@Name("authenticator")
public class AuthenticatorAction
{
@In
private EntityManager entityManager;
public boolean authenticate()
{
try {
entityManager.createQuery("from User where username = :username ")
.setParameter("username", Identity.instance().getUsername()).getSingleResult();
}
catch (NoResultException ex) {
return false;
}
return true;
}
}
pages.xml
<?xml version="1.0" encoding="UTF-8"?> <pages xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd" login-view-id="/login.xhtml"> <page view-id="/*" login-required="true"/> <!-- other navigations --> <exception class="org.jboss.seam.security.NotLoggedInException"> <redirect view-id="/login.xhtml"> <message severity="INFO">You must be logged in to perform this action</message> </redirect> </exception> </pages>
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:web="http://jboss.com/products/seam/web"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:framework="http://jboss.com/products/seam/framework"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.0.xsd">
<core:init jndi-pattern="evg-asr-1.0/#{ejbName}/local" debug="true"
transaction-management-enabled="true"/>
<core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />
<persistence:managed-persistence-context name="entityManager" auto-create="true"
persistence-unit-jndi-name="java:/EntityManagerFactories/asrDatasource" />
<component name="org.jboss.seam.ui.EntityConverter"/>
<security:identity authenticate-method="#{authenticator.authenticate}"/>
<event type="org.jboss.seam.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>
</event>
<event type="org.jboss.seam.security.postAuthenticate">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
<framework:entity-query name="fofsQuery" ejbql="from Fof" />
<framework:entity-home name="fofHome" entity-class="com.evergreen.asr.entity.Fof" />
<factory name="fof" value="#{fofHome.instance}" />
</components>
It says, Seam security should work out of the box, well not in my case. Pl suggest if I'm missing something trivial ...