[JBoss Seam] - identity.isLoggedIn() question
by asookazian
in the API doc for org.jboss.seam.security.Identity, isLoggedIn() has the following description: If there is a principal set, then the user is logged in.
How/when does the principal get set? I'm assuming after the successful execution of identity.setUsername(). In the following code, identity.isLoggedIn() is returning false but is evaluating to true later in an xhtml file. Other test cases (with the same NTLM username) identity.isLoggedIn() returns true. Any ideas why? identity instance is being depency injected earlier in the class...
| public boolean authenticate() {
|
| try {
| identity.setUsername(((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getUsername());
|
| Query q = em.createQuery("SELECT r FROM Users r WHERE r.networkLogin = :username");
| q.setParameter("username", identity.getUsername());
| Users user = (Users) q.getSingleResult();
|
| Set<UserRoles> myRoles = user.getUserRoleses();
|
| if (user.getUserRoleses() != null) {
| for (UserRoles ur : user.getUserRoleses()) {
|
| identity.addRole(ur.getRoles().getSecRoleRoleName());
| }
| }
|
| log.debug("isLoggedin = " + identity.isLoggedIn());
|
| return true;
| }
|
| catch(NoResultException ex) {
| ex.printStackTrace();
| FacesMessages.instance().add("Invalid username/password");
| return false;
| }
| }
home.xhtml:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:rich="http://richfaces.ajax4jsf.org/rich"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message"/>
|
| <rich:panel>
| <!-- <f:facet name="header">Welcome!</f:facet> -->
| <h:outputText value="test" />
| <h:outputText value="Welcome, #{identity.username}" rendered="#{identity.loggedIn}"/>
| <p>This empty shell application includes:</p>
| <ul>
| <li>Ant build script</li>
| <li>Deployment to JBoss AS</li>
| <li>Integration testing using TestNG and JBoss Embeddable EJB3</li>
| <li>EJB 3.0 Seam components</li>
| <li>Templated Facelets views</li>
| <li>HSQL (or MySQL) Datasource</li>
| <li>Default CSS stylesheet</li>
| <li>Internationalization support</li>
| </ul>
| </rich:panel>
|
| </ui:define>
| </ui:composition>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4076540#4076540
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4076540
18Â years, 10Â months
[JBoss Seam] - Re: Starting up Asynchronous Method at startup
by gbcï¼ gmx.de
Works like this:
In components.xml:
| <?xml version="1.0" encoding="UTF-8"?>
| <components xmlns="http://jboss.com/products/seam/components"
| ...
| xmlns:async="http://jboss.com/products/seam/async"
| ...>
|
| <async:quartz-dispatcher/>
| ...
|
Startup class:
| @Startup
| @Stateful
| @Scope(ScopeType.APPLICATION)
| @Name("startupManager")
| public class StartupManager implements StartupManagerLocal{ // create Interface
|
| @Logger
| private Log log;
|
| @In(create = true)
| private ProcessingActionLocal processingAction;
|
| private QuartzTriggerHandle handle = null;
|
| @Create
| public void create() {
| log.info("create(): called");
| // init
| int delay = 20; // in seconds
| long interval = 1000 * delay;
| Calendar cal = Calendar.getInstance();
| cal.setTime(new Date());
| cal.add(Calendar.SECOND, delay);
| // create Processing
| long processingId = processingAction.createProcessing("serverJob");
| // schedule job and save handler
| this.handle = processingAction.doServerJob(processingId, cal.getTime(), interval);
| log.info("create(): id: #0", processingId);
| }
|
| public QuartzTriggerHandle getHandle() {
| return this.handle ;
| }
|
| @Remove
| public void destroy() {
| }
| }
|
The ProcessingAction (The ProcessingBean is not shown here):
| @Stateful
| @Name("processingAction")
| public class ProcessingAction implements ProcessingActionLocal { // create Interface
|
| @Logger
| private Log log;
|
| @In
| private EntityManager entityManager;
|
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| public long createProcessing(String string) {
| // create Processing
| ProcessingBean processing = new ProcessingBean();
| // managed context
| entityManager.persist(processing);
| processing.setName("serverJob");
| // return id
| return processing.getId();
| }
|
| @Asynchronous
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| public QuartzTriggerHandle doServerJob(long processingId, @Expiration Date date, @IntervalDuration Long interval) {
| log.info("doServerJob(): called");
| // get bean
| ProcessingBean processing = entityManager.find(ProcessingBean.class, processingId);
| // if exists remove
| if (processing != null) {
| entityManager.remove(processing);
| log.info("doServerJob(): removed: id: #0", processingId);
| } else {
| // else stop server job
| try {
| startupManager.getHandle().cancel();
| } catch (Exception e) {
| log.error("", e);
| }
| log.info("doServerJob(): stopped: id: #0", processingId);
| }
| // return new handle
| return new QuartzTriggerHandle("serverJob");
| }
|
| @Remove
| public void destroy() {
| }
| }
|
Let me know if it worked out...
Greetz GHad
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4076537#4076537
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4076537
18Â years, 10Â months