You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 29 Members of 4506 |
| Forum: Seam Users |
23. Apr 2008, 11:49 CET | Link |
Hello,
im a new user of the seam framework and it works fine.
Now I wonna add different sites for different roles. But i dont know how i read out this roles from my database.
I ve a table with id, username, password and role. I ve 4 different roles: admin, lender, borrower and caretaker.
The aim is to get out the role for each member of my site and set restrictions p e.
I use the AthenticatorAction class from the seam booking example. Its possible to compare username and pasword from login and password.
code:
package test.session;
import static org.jboss.seam.ScopeType.SESSION;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import de.uni_leipzig.wifa.iwi.handapparat.entity.User;
@Stateless
@Name("authenticator")
public class AuthenticatorAction implements Authenticator
{
@PersistenceContext
private EntityManager em;
@Out(required=false, scope = SESSION)
private User user;
public boolean authenticate()
{
List results = em.createQuery("select u from User u where u.username=#{identity.username} and u.password=#{identity.password}")
.getResultList();
if ( results.size()==0 )
{
return false;
}
else
{
user = (User) results.get(0);
return true;
}
}
}
If there were help, i would be happy. THX Kevin
fetch the user roles from the db and use identity.addRole()
If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Thx, but I dont come to a solution. Do u have an code snippet or an example to solve this easily?
hi !
you got your user if the password is correct!
now you can call the attributes you like from this object by using the getters...
cu
something like
List<String> roles = em.createQuery("select r from Roles where r.username=#{identity.username}").getResultList(); for (String role : roles) { identity.addRole(role); }if you can't get it work from there, you are in a world of trouble anyways ;-)
If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Aah, you have only one role. Follow FRG:s advice...
If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Thx 4 help, it works. i used that:
but i had to change the user roles, this were enumerations.
Or use .name() on the Enum object :-)
OK thx, i'll try it.
Next goal is to set multiple rules. That means an user can claim more than one user roles.
Theres a class User and a class UserRoles with an enumeration class which consists of 4 roles. I hope its the right way to establish the role concept.
Advices are desired. 8)