[jboss-user] [JBoss Seam] - Access to EntityManager in authenticator?
dustismo
do-not-reply at jboss.com
Thu Feb 1 13:32:45 EST 2007
I am trying to add the new security features to my app, and am getting stuck trying to authenticate.
Here is my class (almost exactly the same as the docs)
| @Name("authenticator")
| public class Authenticator {
|
| @In
| private EntityManager entityManager;
|
| @Logger Log log;
| public boolean authenticate(String username, String password, Set<String> roles)
| {
| log.info("Authenticating user " + username);
| log.info("em " + entityManager);
| try
| {
| User user = (User) entityManager.createQuery(
| "from User where name = :username and password = :password")
| .setParameter("username", username)
| .setParameter("password", password)
| .getSingleResult();
| return true;
| }
| catch (NoResultException ex)
| {
| FacesMessages.instance().add("Invalid username/password");
| return false;
| }
| catch (Exception ex)
| {
| log.error("Caught", ex);
| FacesMessages.instance().add("Could not log in.. Please contact admin");
| return false;
| }
| }
| }
|
It throws an exception saying:
org.jboss.seam.RequiredException: In attribute requires value for component: authenticator.entityManager
but if I change
@In
| private EntityManager entityManager;
to
@PersistenceContext
| private EntityManager entityManager;
I get a null pointer exception..
Am I missing something, am I supposed to be outjecting the EntityManager somewhere?
thanks,
Dustin
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009605#4009605
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009605
More information about the jboss-user
mailing list