Example #1
0
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {

    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();

    boolean applyConfig = request.getAttributeBool(AdminConstants.A_APPLY_CONFIG, true);
    Set<String> reqAttrs = getReqAttrs(request, AttributeClass.server);

    Element d = request.getElement(AdminConstants.E_SERVER);
    String method = d.getAttribute(AdminConstants.A_BY);
    String name = d.getText();

    if (name == null || name.equals(""))
      throw ServiceException.INVALID_REQUEST("must specify a value for a server", null);

    Server server = prov.get(ServerBy.fromString(method), name);

    if (server == null) throw AccountServiceException.NO_SUCH_SERVER(name);

    AdminAccessControl aac = checkRight(zsc, context, server, AdminRight.PR_ALWAYS_ALLOW);

    // reload the server
    prov.reload(server);

    Element response = zsc.createElement(AdminConstants.GET_SERVER_RESPONSE);
    encodeServer(response, server, applyConfig, reqAttrs, aac.getAttrRightChecker(server));

    return response;
  }
Example #2
0
  /**
   * central place where a target should be loaded
   *
   * @param prov
   * @param targetType
   * @param targetBy
   * @param target
   * @return
   * @throws ServiceException
   */
  static Entry lookupTarget(
      Provisioning prov, TargetType targetType, TargetBy targetBy, String target, boolean mustFind)
      throws ServiceException {
    Entry targetEntry = null;

    switch (targetType) {
      case account:
        targetEntry = prov.get(AccountBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ACCOUNT(target);
        break;
      case calresource:
        targetEntry = prov.get(CalendarResourceBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_CALENDAR_RESOURCE(target);
        break;
      case dl:
        targetEntry = prov.getAclGroup(DistributionListBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(target);
        break;
      case domain:
        targetEntry = prov.get(DomainBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_DOMAIN(target);
        break;
      case cos:
        targetEntry = prov.get(CosBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_COS(target);
        break;
      case server:
        targetEntry = prov.get(ServerBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_SERVER(target);
        break;
      case xmppcomponent:
        targetEntry = prov.get(XMPPComponentBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(target);
        break;
      case zimlet:
        ZimletBy zimletBy = ZimletBy.fromString(targetBy.name());
        if (zimletBy != ZimletBy.name)
          throw ServiceException.INVALID_REQUEST("zimlet must be by name", null);
        targetEntry = prov.getZimlet(target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ZIMLET(target);
        break;
      case config:
        targetEntry = prov.getConfig();
        break;
      case global:
        targetEntry = prov.getGlobalGrant();
        break;
      default:
        ServiceException.INVALID_REQUEST(
            "invallid target type for lookupTarget:" + targetType.toString(), null);
    }

    return targetEntry;
  }