/** Validate the stateful bean is not clustered by having failover not work */
  public void testStatefulBean() throws Exception {
    // Connect to the server0 JNDI
    InitialContext ctx = getInitialContext(0);

    DisableClusteredAnnotationRemote stateful = null;
    try {
      stateful =
          (DisableClusteredAnnotationRemote)
              ctx.lookup("DisableClusteredAnnotationStateful/remote");
    } catch (NameNotFoundException nnfe) {
      fail(nnfe.getMessage());
    }

    NodeAnswer node1 = stateful.getNodeState();
    getLog().debug("Node 1 ID: " + node1);

    // Now we switch to the other node, simulating a failure on node 1
    //
    stateful.setUpFailover("once");
    try {
      stateful.getNodeState();
      fail("GenericClusteringException did not propagate");
    } catch (Exception good) {
    }
  }
Example #2
0
  @Override
  public void execute() throws Exception {
    final PrintWriter err = getError().getPrintWriter();
    final File file = argFile.getValue();

    Shell shell = null;
    try {
      shell = ShellUtils.getShellManager().getCurrentShell();
    } catch (NameNotFoundException e) {
      e.printStackTrace(err);
      exit(2);
    }

    if (shell == null) {
      err.println(err_null);
      exit(2);
    }

    String[] args = argArgs.getValues();

    int rc = shell.runCommandFile(file, null, args);
    if (rc != 0) {
      exit(rc);
    }
  }
  /** Test stateless bean by demonstrating no load balancing */
  public void testStatelessBean() throws Exception {
    InitialContext ctx = getInitialContext(0);

    DisableClusteredAnnotationRemote stateless = null;

    try {
      stateless =
          (DisableClusteredAnnotationRemote)
              ctx.lookup("DisableClusteredAnnotationStateless/remote");
    } catch (NameNotFoundException nnfe) {
      fail(nnfe.getMessage());
    }

    NodeAnswer node1 = stateless.getNodeState();
    assertNotNull(node1);
    getLog().debug("Node 1 ID: " + node1);

    for (int i = 0; i < 20; i++) {
      assertEquals(node1, stateless.getNodeState());
    }
  }
  public boolean canConnect() throws ValidationException {

    try {
      // now try to connect
      String dnName =
          ldapAccess.dnSearch(
              this.dirProperties, this.baseDN, this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=*");

      if (dnName == null) {

        return false;
      }

      return true;

    } catch (NameNotFoundException nnfe) {
      // sessionCtx.setRollbackOnly();
      ValidationException vf =
          new ValidationException(
              ReasonEnum.LDAP_BASE_DN_INVALID, null, new Object[] {this.baseDN});
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_ACCESS_FAILED,
          nnfe.getMessage());
      throw vf;
    } catch (NamingException e1) {
      // sessionCtx.setRollbackOnly();
      Object[] params =
          new Object[] {this.dirProperties.get(Context.PROVIDER_URL), e1.getMessage()};
      ValidationException vf =
          new ValidationException(ReasonEnum.LDAP_CONNECTION_REFUSED, null, params);
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_SYSTEM_CONNECTION_REFUSED,
          "LDAPuser");
      throw vf;
    }
  }
  /**
   * Validate the LDAP properties by performing a search request.
   *
   * @param baseDN the baseDN
   * @return the read attribute
   * @throws ValidationException Thrown in case the LDAP access failed or no record was found
   */
  public VOUserDetails validateLdapProperties(VOUserDetails user) throws ValidationException {

    LdapVOUserDetailsMapper mapper = new LdapVOUserDetailsMapper(user, this.attrMap);
    VOUserDetails tmpUser = new VOUserDetails();
    tmpUser.setAdditionalName(user.getAdditionalName());
    tmpUser.setEMail(user.getEMail());
    tmpUser.setFirstName(user.getFirstName());
    tmpUser.setLastName(user.getLastName());
    tmpUser.setLocale(user.getLocale());

    try {

      String dnName =
          ldapAccess.dnSearch(
              this.dirProperties,
              this.baseDN,
              this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=" + user.getUserId());

      if (dnName == null) {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_FOUND, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_LDAP_SEARCH_OF_USER_FAILED,
            user.getUserId());
        throw vf;
      }

      List<VOUserDetails> result =
          ldapAccess.search(
              this.dirProperties,
              this.baseDN,
              this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=" + user.getUserId(),
              mapper,
              true);
      int size = result.size();
      if (size == 1) {
        user = result.get(0);
        if (user.getLocale() != null
            && !user.getLocale().isEmpty()
            && user.getLocale().length() > LOCAL_LENGTH) {
          user.setLocale(user.getLocale().substring(0, LOCAL_LENGTH));
        }
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_ADDITIONAL_NAME,
            tmpUser.getAdditionalName(),
            user.getAdditionalName());
        validateLdapPropertyValue(
            this.attrMap, SettingType.LDAP_ATTR_EMAIL, tmpUser.getEMail(), user.getEMail());
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_FIRST_NAME,
            tmpUser.getFirstName(),
            user.getFirstName());
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_LAST_NAME,
            tmpUser.getLastName(),
            user.getLastName());
        validateLdapPropertyValue(
            this.attrMap, SettingType.LDAP_ATTR_LOCALE, tmpUser.getLocale(), user.getLocale());

        return result.get(0);
      } else if (size == 0) {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_FOUND, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_VALIDATION_PARAMETER_LDAP_FOUND_ERROR,
            "LDAP User");
        throw vf;
      } else {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_UNIQUE, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_VALIDATION_PARAMETER_LDAP_FOUND_ERROR,
            "LDAP User");
        throw vf;
      }
    } catch (NameNotFoundException nnfe) {
      // sessionCtx.setRollbackOnly();
      ValidationException vf =
          new ValidationException(
              ReasonEnum.LDAP_BASE_DN_INVALID, null, new Object[] {this.baseDN});
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_ACCESS_FAILED,
          nnfe.getMessage());
      throw vf;
    } catch (NamingException e1) {
      // sessionCtx.setRollbackOnly();
      Object[] params = new Object[] {dirProperties.get(Context.PROVIDER_URL), e1.getMessage()};
      ValidationException vf =
          new ValidationException(ReasonEnum.LDAP_CONNECTION_REFUSED, null, params);
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_SYSTEM_CONNECTION_REFUSED,
          "LDAPuser");
      throw vf;
    }
  }
Example #6
0
  /**
   * Lookup a binding by name
   *
   * @param name name of bound object
   * @exception NamingException if an error occurs
   */
  public Object lookup(Name name) throws NamingException {
    if (__log.isDebugEnabled()) __log.debug("Looking up name=\"" + name + "\"");
    Name cname = toCanonicalName(name);

    if ((cname == null) || (cname.size() == 0)) {
      __log.debug("Null or empty name, returning copy of this context");
      NamingContext ctx = new NamingContext(_env, _name, _parent, _parser);
      ctx._bindings = _bindings;
      return ctx;
    }

    if (cname.size() == 1) {
      Binding binding = getBinding(cname);
      if (binding == null) {
        NameNotFoundException nnfe = new NameNotFoundException();
        nnfe.setRemainingName(cname);
        throw nnfe;
      }

      Object o = binding.getObject();

      // handle links by looking up the link
      if (o instanceof LinkRef) {
        // if link name starts with ./ it is relative to current context
        String linkName = ((LinkRef) o).getLinkName();
        if (linkName.startsWith("./")) return this.lookup(linkName.substring(2));
        else {
          // link name is absolute
          InitialContext ictx = new InitialContext();
          return ictx.lookup(linkName);
        }
      } else if (o instanceof Reference) {
        // deference the object
        try {
          return NamingManager.getObjectInstance(o, cname, this, _env);
        } catch (NamingException e) {
          throw e;
        } catch (Exception e) {
          __log.warn("", e);
          throw new NamingException(e.getMessage());
        }
      } else return o;
    }

    // it is a multipart name, recurse to the first subcontext

    String firstComponent = cname.get(0);
    Object ctx = null;

    if (firstComponent.equals("")) ctx = this;
    else {

      Binding binding = getBinding(firstComponent);
      if (binding == null) {
        NameNotFoundException nnfe = new NameNotFoundException();
        nnfe.setRemainingName(cname);
        throw nnfe;
      }

      // as we have bound a reference to an object factory
      // for the component specific contexts
      // at "comp" we need to resolve the reference
      ctx = binding.getObject();

      if (ctx instanceof Reference) {
        // deference the object
        try {
          ctx =
              NamingManager.getObjectInstance(
                  ctx, getNameParser("").parse(firstComponent), this, _env);
        } catch (NamingException e) {
          throw e;
        } catch (Exception e) {
          __log.warn("", e);
          throw new NamingException(e.getMessage());
        }
      }
    }
    if (!(ctx instanceof Context)) throw new NotContextException();

    return ((Context) ctx).lookup(cname.getSuffix(1));
  }