示例#1
0
  private Message handleSecurityMessage(CommandMessage message) {
    GraniteConfig config = GraniteContext.getCurrentInstance().getGraniteConfig();

    Message response = null;

    if (!config.hasSecurityService())
      log.warn(
          "Ignored security operation (no security settings in granite-config.xml): %s", message);
    else if (!config.getSecurityService().acceptsContext())
      log.info(
          "Ignored security operation (security service does not handle this kind of granite context)",
          message);
    else {
      SecurityService securityService = config.getSecurityService();
      try {
        if (message.isLoginOperation())
          securityService.login(
              message.getBody(), (String) message.getHeader(Message.CREDENTIALS_CHARSET_HEADER));
        else securityService.logout();
      } catch (Exception e) {
        if (e instanceof SecurityServiceException)
          log.debug(e, "Could not process security operation: %s", message);
        else log.error(e, "Could not process security operation: %s", message);
        response = new ErrorMessage(message, e, true);
      }
    }

    if (response == null) {
      response = new AcknowledgeMessage(message, true);
      // For SDK 2.0.1_Hotfix2.
      if (message.isSecurityOperation()) response.setBody("success");
    }

    return response;
  }
示例#2
0
  private void loadCustomSecurity(XMap element, boolean custom) {
    XMap security = element.getOne("security");
    if (security != null) {
      String type = security.get("@type");
      try {
        securityService = (SecurityService) TypeUtil.newInstance(type);
      } catch (Exception e) {
        throw new GraniteConfigException("Could not instantiate SecurityService: " + type, e);
      }

      Map<String, String> params = new HashMap<String, String>();
      for (XMap param : security.getAll("param")) {
        String name = param.get("@name");
        String value = param.get("@value");
        params.put(name, value);
      }
      try {
        securityService.configure(params);
      } catch (Exception e) {
        throw new GraniteConfigException(
            "Could not configure SecurityService " + type + " with: " + params, e);
      }
    }
  }