[jboss-cvs] jboss-seam/examples/booking/view/exp ...
Shane Bryzak
sbryzak at redhat.com
Fri Feb 23 22:53:42 EST 2007
User: sbryzak2
Date: 07/02/23 22:53:42
Modified: examples/booking/view/exp loginExp.html
Log:
updated
Revision Changes Path
1.5 +51 -39 jboss-seam/examples/booking/view/exp/loginExp.html
(In the diff below, changes in quantity of whitespace are not shown.)
Index: loginExp.html
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/booking/view/exp/loginExp.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- loginExp.html 10 Nov 2006 19:07:54 -0000 1.4
+++ loginExp.html 24 Feb 2007 03:53:42 -0000 1.5
@@ -23,32 +23,31 @@
The login page is defined using pure XHTML with JSF controls.
The form uses JSF EL value binding and method binding
expressions to refer to Seam components. For example,
- <code>#{user.username}</code> refers to a property of the
- <code>User</code> entity bean and <code>#{login.login}</code>
- refers to a method of the <code>LoginAction</code> stateless
- session bean. Both beans are EJB 3.0 POJOs managed by Seam.
+ <code>#{identity.username}</code> refers to a property of the
+ <code>Identity</code> component and <code>#{identity.login}</code>
+ refers to a method of the <code>Identity</code> component.
</p>
<code class="block">
<div>
<h:outputLabel for="username">Login Name</h:outputLabel>
- <h:inputText id="username" value="#{user.username}" />
+ <h:inputText id="username" value="#{identity.username}" />
</div>
<div>
<h:outputLabel for="password">Password</h:outputLabel>
- <h:inputSecret id="password" value="#{user.password}" />
+ <h:inputSecret id="password" value="#{identity.password}" />
</div>
... ...
<div class="buttonBox">
- <h:commandButton action="#{login.login}"
+ <h:commandButton action="#{identity.login}"
value="Account Login" class="button" />
</div>
</code>
<p>
- The <code>User</code> enity bean is mapped to the Seam
+ After logging in, the <code>User</code> enity bean is mapped to the Seam
context variable named <code>user</code> bean via the
<code>@Name</code> annotation. <code>User</code> is
a session scoped bean, meaning that the <code>user</code>
@@ -90,53 +89,66 @@
</code>
<p>
- <code>LoginAction</code> is an EJB 3.0 session bean mapped
- to the Seam context variable named <code>login</code>. When
+ Seam comes with its own Security framework, based on JAAS. It allows you
+ to perform user authentication by configuring your own authentication method
+ in <code>components.xml</code>.
+ </p>
+
+<code class="block">
+ <security:identity authenticate-method="#{authenticator.authenticate}"/>
+</code>
+
+ <p>
+ <code>AuthenticatorAction</code> is an EJB 3.0 session bean mapped
+ to the Seam context variable named <code>authenticator</code>. When
the login button is clicked, the JSF method binding
- <code>#{login.login}</code> is evaluated, and the
- <code>login()</code> method is invoked upon <code>LoginAction</code>.
+ <code>#{identity.login}</code> is evaluated, and based upon the previous configuration, the
+ <code>authenticate()</code> method is invoked upon <code>AuthenticatorAction</code>.
</p>
<code class="block">
- at Stateless
- at Name("login")
-public class LoginAction implements Login
+ at Stateful
+ at Scope(EVENT)
+ at Name("authenticator")
+public class AuthenticatorAction implements Authenticator
{
+ @In Identity identity;
- @In @Out
- private User user;
+ @PersistenceContext EntityManager em;
- @PersistenceContext
- private EntityManager em;
+ @Out(required=false, scope = SESSION)
+ private User user;
- public String login()
+ public boolean authenticate()
{
- List<User> results = em.createQuery("from User where username=:username and password=:password")
- .setParameter("username", user.getUsername())
- .setParameter("password", user.getPassword())
+ List results = em.createQuery(
+ "select u from User u where u.username=:username " +
+ "and u.password=:password")
+ .setParameter("username", identity.getUsername())
+ .setParameter("password", identity.getPassword())
.getResultList();
if ( results.size()==0 )
{
- FacesMessages.instance().add("Invalid login");
- return "login";
+ return false;
}
else
{
- user = results.get(0);
- Contexts.getSessionContext().set("loggedIn", true);
- return "main";
+ user = (User) results.get(0);
+ return true;
}
-
}
+ @Remove @Destroy
+ public void destroy() {}
}
</code>
<p>
- The <code>@In</code> annotation tells Seam to inject a <code>User</code>
- when any method of <code>LoginAction</code> is invoked. The <code>@Out</code>
- annotation indicates the <code>LoginAction</code> bean can change the
+ The <code>@In</code> annotation tells Seam to inject an <code>Identity</code>
+ (a built-in Seam component that provides security functionality)
+ when any method of <code>AuthenticatorAction</code> is invoked. The <code>@Out</code>
+ annotation indicates the <code>AuthenticatorAction</code> bean can change the
value of the <code>user</code> context variable and make the new instance
available to other session beans and JSF pages.
</p>
More information about the jboss-cvs-commits
mailing list