All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.bonita.facade.AutoDetectSecurityContext Maven / Gradle / Ivy

package org.ow2.bonita.facade;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.ow2.bonita.util.BonitaRuntimeException;

public class AutoDetectSecurityContext implements BonitaSecurityContext {

  private static final Logger LOG = Logger.getLogger(AutoDetectSecurityContext.class.getName());

  public String getUser() {
    if (LOG.isLoggable(Level.FINEST)) {
      LOG.finest("Using AutoDetectSecurityContext to get the current logged user.");
    }
    String user = getUser(new EJB3SecurityContext());
    if (user == null) {
      user = getUser(new EJB2SecurityContext());
    }
    if (user == null) {
      user = getUser(new StandardSecurityContext());
    }
    if (user == null) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("No user found from " + AutoDetectSecurityContext.class);
      }
      throw new BonitaRuntimeException("No user found from AutoDetectSecurityContext. "
          + "Please configure environment to define which securityContext must be used");
    }
    return user;
  }
  
  private String getUser(BonitaSecurityContext securityContext) {
    try {
      return securityContext.getUser();
    } catch (Throwable t) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("No user found from " + securityContext.getClass());
      }
      return null;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy