-
1. Re: How to use Seam Identity?
gavin.king Feb 27, 2007 8:10 PM (in response to tonylmai)@Name("org.jboss.seam.core.identity") public class MyIdentity extends RuleBasedIdentity {//or Identity, if no drools public String login() { String outcome = super.login(); //do whatever you like } }
-
2. Re: How to use Seam Identity?
tonylmai Feb 27, 2007 8:25 PM (in response to tonylmai)Hi Gavin,
I am using Seam 1.1.6, not 1.2 and I received the following error when I copied the Authenticator example code (http://docs.jboss.com/seam/1.2.0.GA/reference/en/html/security.html#d0e6073)
---- Server log -------
Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: authenticator.entityManager
---------------------
Note that in the example code, entityManager is injected as:
@In EntityManager entityManager;
whereas in the booking example, LoginAction has it declared as:
@PersistenceContext private EntityManager em;
Neither works for me when I started using Authenticator. Can you help?
Do I need to upgrade to Seam 1.2?
Thanks -
3. Re: How to use Seam Identity?
gavin.king Feb 27, 2007 8:29 PM (in response to tonylmai)If you want to use @PersistenceContext, you need to make your Authenticator a session bean. Otherwise, you need to config a seam-managed PC.
-
4. Re: How to use Seam Identity?
tonylmai Feb 27, 2007 9:21 PM (in response to tonylmai)I am using Seam-managed PC. But it's throwing me the above error. Here is a snippet of stacktrace:
18:07:03,015 INFO [Lifecycle] starting up: org.jboss.seam.security.identity 18:07:03,562 INFO [Pages] reading pages.xml 18:07:03,625 ERROR [SeamLoginModule] Error invoking login method javax.faces.el.EvaluationException: org.jboss.seam.RequiredException: In attribute requires value for component: authenticator.entityManager at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91) .... Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: authenticator.entityManager at org.jboss.seam.Component.getInstanceToInject(Component.java:1920) .....
I followed the example and coded the Authenticator as followed:package com.judots.webclient.session; import * (skipped) @Name("authenticator") public class Authenticator { @In EntityManager entityManager; public boolean authenticate() { String usrName = Identity.instance().getUsername(); System.out.println("Verify login for " + usrName); User dbUsr = null; try { dbUsr = (User) entityManager .createQuery( "from login_user where loginId = :username and password = :password") .setParameter("username", Identity.instance().getUsername()) .setParameter("password", Identity.instance().getPassword()) .getSingleResult(); assert (dbUsr != null) : "No result from db. Should have thrown NoResultException"; Seam.invalidateSession(); // String err = Messages.getString(ELNames.APP_BUNDLE_ELNAME, // "login.invalidIdPwd.msg", new Object[] {}); // FacesMessages.instance().add(err); return false; } } catch (NoResultException ex) { System.out.println("User " + usrName + " not found."); Seam.invalidateSession(); // String err = Messages.getString(ELNames.APP_BUNDLE_ELNAME, // "login.invalidIdPwd.msg", new Object[] {}); // FacesMessages.instance().add(err); return false; } return true; } }
I am not sure if I understand what it means by 'In attribute requires value for component'. Can you help?
Thanks -
5. Re: How to use Seam Identity?
gavin.king Feb 27, 2007 10:07 PM (in response to tonylmai)Probably you need auto-create=true in components.xml, or @In(create=true) in the Java.
-
6. Re: How to use Seam Identity?
tonylmai Feb 28, 2007 1:28 AM (in response to tonylmai)With the (created=true) flag, I now got this:
21:54:46,578 INFO [Lifecycle] starting up: org.jboss.seam.security.identity 21:54:46,734 INFO [Pages] reading pages.xml 21:54:46,843 INFO [STDOUT] Verify login for tony 21:54:46,843 ERROR [SeamLoginModule] Error invoking login method javax.faces.el.EvaluationException: org.hibernate.hql.ast.QuerySyntaxException: login_user is not mapped [select u from login_user u where u.loginId=:username and u.password=:password]
Note that this same select statement worked with LoginAction which was a session bean.
I will try to upgrade to 1.2 tomorrow and see if that would make a difference.
Thanks -
7. Re: How to use Seam Identity?
tonylmai Feb 28, 2007 2:04 AM (in response to tonylmai)1.2 did not solve the problem. I am still running into the error:
23:02:21,453 INFO [Lifecycle] starting up: org.jboss.seam.security.identity 23:02:22,625 INFO [Pages] reading pages.xml 23:02:23,546 INFO [STDOUT] Verify login for tony 23:02:23,718 ERROR [SeamLoginModule] Error invoking login method javax.faces.el.EvaluationException: org.hibernate.hql.ast.QuerySyntaxException: login_user is not mapped [select u from login_user u where u.username=:username and u.password=:password]
Gavin, can you help?
Thanks -
8. Re: How to use Seam Identity?
gavin.king Feb 28, 2007 2:08 AM (in response to tonylmai)I highly doubt that you have a class called "login_user", so I'm sure this query never worked in any version of Hibernate.
-
9. Re: How to use Seam Identity?
tonylmai Feb 28, 2007 12:41 PM (in response to tonylmai)I got it now. If entityManager was injected as @In then it would use Hibernate query. In earlier code I injected with @PersistenceContext and that was why I was able to use SQL select statement against the database table.
Back to overriding the RuleBasedIdentity, the login method allows me to return a viewId to redirect user to a specific page. Yet the logout does not. How would I go about redirecting user to a different page after they have logged out?
Thanks. -
10. Re: How to use Seam Identity?
shane.bryzak Feb 28, 2007 2:55 PM (in response to tonylmai)"tonylmai" wrote:
Back to overriding the RuleBasedIdentity, the login method allows me to return a viewId to redirect user to a specific page. Yet the logout does not. How would I go about redirecting user to a different page after they have logged out?
Here's an example of redirect on logout in pages.xml:<page view-id="*"> <navigation from-action="#{identity.logout}"> <redirect view-id="/home.xhtml"/> </navigation> </page>
-
11. Re: How to use Seam Identity?
tonylmai Feb 28, 2007 6:37 PM (in response to tonylmai)Got it. Thanks.