[JBoss Seam] - Re: login & logout options
by rmemoria
Hi Caye,
This is my authenticator bean:
@Name("authenticator")
| @Stateless
| public class AuthenticatorBean implements Authenticator {
|
| @In(required=false) @Out(required=false)
| UserLogin userLogin;
|
| @In Identity identity;
|
| @In(create=true) FacesMessages facesMessages;
|
| @PersistenceContext EntityManager entityManager;
|
|
| public boolean authenticate()
| {
| String pwd = Passwords.hashPassword(identity.getPassword());
|
| try {
| User user = (User)entityManager.createQuery("from User u where u.login = :login " +
| "and upper(u.password) = :pwd")
| .setParameter("login", identity.getUsername().toUpperCase())
| .setParameter("pwd", pwd.toUpperCase())
| .getSingleResult();
|
| if (user.getRoles().size() == 0) {
| facesMessages.addFromResourceBundle("login.norole");
| return false;
| }
|
|
| // saves login info
| FacesContext facesContext = FacesContext.getCurrentInstance();
| HttpServletRequest req = (HttpServletRequest) facesContext.getExternalContext().getRequest();
| String ipAddr = req.getRemoteAddr();
| String app = req.getHeader("User-Agent");
|
| userLogin = new UserLogin();
| userLogin.setUser(user);
| userLogin.setLoginDate(new java.util.Date());
| if (app.length() > 80)
| app = app.substring(0, 80);
| userLogin.setApplication(app);
| userLogin.setIpAddress(ipAddr);
| entityManager.persist(userLogin);
|
| for (UserRole r: userLogin.getUser().getRoles()) {
| identity.addRole(r.getName());
| }
|
| return true;
| }
| catch (NoResultException e) {
| e.printStackTrace();
| return false;
| }
| }
|
|
| public void logout() {
| if ((userLogin != null)&&(userLogin.getLogoutDate() == null)) {
| userLogin = entityManager.merge(userLogin);
| userLogin.setLogoutDate(new java.util.Date());
|
| entityManager.persist(userLogin);
|
| System.out.println("Logout de " + userLogin.getUser().getLogin());
| }
| }
| }
Check that I had to create it as a Stateless bean because of the EntityManager.
Regards,
Ricardo
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4068954#4068954
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4068954
18Â years, 8Â months
[JBoss Seam] - Re: SeamTest breaks on drools 4.0
by dmitriy.lapko
I had the same problem and went by second way proposed ellenzhao (thank you :) )
Just add to /resources/META-INF file drools.default.packagebuilder.conf
with next contents:
drools.dialect.default = java
| drools.dialect.java = org.drools.rule.builder.dialect.java.JavaDialectConfiguration
| drools.dialect.java.compiler = JANINO
|
| drools.dialect.mvel = org.drools.rule.builder.dialect.mvel.MVELDialectConfiguration
| drools.dialect.mvel.strict = true
|
| drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulateFunction
| drools.accumulate.function.max = org.drools.base.accumulators.MaxAccumulateFunction
| drools.accumulate.function.min = org.drools.base.accumulators.MinAccumulateFunction
| drools.accumulate.function.count = org.drools.base.accumulators.CountAccumulateFunction
| drools.accumulate.function.sum = org.drools.base.accumulators.SumAccumulateFunction
and add janino-2.5.7.jar into classpath.
Next problem I experienced in tests was NoCacheProviderException, I fixed it by adding
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
into persistence.xml.
Also after some manipulation tests successfully worked (I have both component and integration tests).
Some experienced problems:
1) I compiled seam under JDK 1.6 but tests failed to start in JRE 1.6 because jboss-embedded-all.jar is build under JDK 1.5 and can not be started in 1.6 (the problem with Class.forName and loadClass methods), so I rebuilt seam under JDK 1.5 and start it in JRE 1.5.
2) Output dir in Eclipse project should contain only one *-ds.xml, so just exclude other from class path to prevent error with already added datasource
And when I managed to start my tests, they work so slowly!!! I think, it is awful... How can I practice TDD with SEAM??? Everything is bound to its environment, and for tests I have to start so many stuff... I'm in despair... Someone, give me a hope!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4068940#4068940
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4068940
18Â years, 8Â months