@Handler( id = "addDefaultProviderInfo", input = { @HandlerInput(name = "providerList", type = List.class, required = true), @HandlerInput(name = "configName", type = String.class, required = true), @HandlerInput(name = "msgSecurityName", type = String.class, required = true) }) public static void addDefaultProviderInfo(HandlerContext handlerCtx) { List<HashMap> providerList = (ArrayList<HashMap>) handlerCtx.getInputValue("providerList"); String configName = (String) handlerCtx.getInputValue("configName"); String msgSecurityName = (String) handlerCtx.getInputValue("msgSecurityName"); String endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/security-service/message-security-config/" + msgSecurityName; Map<String, Object> valueMap = (Map<String, Object>) RestUtil.getEntityAttrs(endpoint, "entity"); String defaultProvider = (String) valueMap.get("defaultProvider"); String defaultClientProvider = (String) valueMap.get("defaultClientProvider"); String trueStr = GuiUtil.getMessage("common.true"); String falseStr = GuiUtil.getMessage("common.false"); for (Map oneRow : providerList) { if (oneRow.get("name").equals(defaultProvider) || oneRow.get("name").equals(defaultClientProvider)) { oneRow.put("default", trueStr); } else { oneRow.put("default", falseStr); } } }
/** * This handler returns the a Map for storing the attributes for editing a realm. This can be used * by either the node agent realm or the realm in configuration-Security-realm * * @param handlerCtx The HandlerContext. */ @Handler( id = "getRealmAttrForEdit", input = {@HandlerInput(name = "endpoint", type = String.class)}, output = { @HandlerOutput(name = "attrMap", type = Map.class), @HandlerOutput(name = "classnameOption", type = String.class), @HandlerOutput(name = "realmClasses", type = List.class), @HandlerOutput(name = "properties", type = List.class) }) public static void getRealmAttrForEdit(HandlerContext handlerCtx) { String endpoint = (String) handlerCtx.getInputValue("endpoint"); HashMap<String, Object> realmMap = (HashMap<String, Object>) RestUtil.getEntityAttrs(endpoint, "entity"); HashMap<String, Object> responseMap = (HashMap<String, Object>) RestUtil.restRequest(endpoint + "/property.json", null, "GET", null, false); HashMap propsMap = (HashMap) ((Map<String, Object>) responseMap.get("data")).get("extraProperties"); ArrayList<HashMap> propList = (ArrayList<HashMap>) propsMap.get("properties"); HashMap origProps = new HashMap(); for (HashMap prop : propList) { origProps.put(prop.get("name"), prop.get("value")); } Map attrMap = new HashMap(); attrMap.put("Name", (String) realmMap.get("name")); attrMap.put("fileJaax", "fileRealm"); attrMap.put("ldapJaax", "ldapRealm"); attrMap.put("solarisJaax", "solarisRealm"); attrMap.put("jdbcJaax", "jdbcRealm"); String classname = (String) realmMap.get("classname"); if (realmClassList.contains(classname)) { handlerCtx.setOutputValue("classnameOption", "predefine"); attrMap.put("predefinedClassname", Boolean.TRUE); attrMap.put("classname", classname); List props = getChildrenMapForTableList(propList, "property", skipRealmPropsList); handlerCtx.setOutputValue("properties", props); if (classname.indexOf("FileRealm") != -1) { attrMap.put("file", origProps.get("file")); attrMap.put("fileJaax", origProps.get("jaas-context")); attrMap.put("fileAsGroups", origProps.get("assign-groups")); } else if (classname.indexOf("LDAPRealm") != -1) { attrMap.put("ldapJaax", origProps.get("jaas-context")); attrMap.put("ldapAsGroups", origProps.get("assign-groups")); attrMap.put("directory", origProps.get("directory")); attrMap.put("baseDn", origProps.get("base-dn")); } else if (classname.indexOf("SolarisRealm") != -1) { attrMap.put("solarisJaax", origProps.get("jaas-context")); attrMap.put("solarisAsGroups", origProps.get("assign-groups")); } else if (classname.indexOf("PamRealm") != -1) { attrMap.put("pamJaax", origProps.get("jaas-context")); } else if (classname.indexOf("JDBCRealm") != -1) { attrMap.put("jdbcJaax", origProps.get("jaas-context")); attrMap.put("jdbcAsGroups", origProps.get("assign-groups")); attrMap.put("datasourceJndi", origProps.get("datasource-jndi")); attrMap.put("userTable", origProps.get("user-table")); attrMap.put("userNameColumn", origProps.get("user-name-column")); attrMap.put("passwordColumn", origProps.get("password-column")); attrMap.put("groupTable", origProps.get("group-table")); attrMap.put("groupTableUserName", origProps.get("group-table-user-name-column")); attrMap.put("groupNameColumn", origProps.get("group-name-column")); attrMap.put("dbUser", origProps.get("db-user")); attrMap.put("dbPassword", origProps.get("db-password")); attrMap.put("digestAlgorithm", origProps.get("digest-algorithm")); attrMap.put("pswdEncAlgorithm", origProps.get("digestrealm-password-enc-algorithm")); attrMap.put("encoding", origProps.get("encoding")); attrMap.put("charset", origProps.get("charset")); } else if (classname.indexOf("CertificateRealm") != -1) { attrMap.put("certAsGroups", origProps.get("assign-groups")); } } else { // Custom realm class handlerCtx.setOutputValue("classnameOption", "input"); attrMap.put("predefinedClassname", Boolean.FALSE); attrMap.put("classnameInput", classname); attrMap.put("classname", classname); List props = getChildrenMapForTableList(propList, "property", null); handlerCtx.setOutputValue("properties", props); } handlerCtx.setOutputValue("attrMap", attrMap); handlerCtx.setOutputValue("realmClasses", realmClassList); }
@Handler( id = "saveMsgProviderInfo", input = { @HandlerInput(name = "attrMap", type = Map.class, required = true), @HandlerInput(name = "configName", type = String.class, required = true), @HandlerInput(name = "edit", type = String.class, required = true) }) public static void saveMsgProviderInfo(HandlerContext handlerCtx) { Map<String, String> attrMap = (Map<String, String>) handlerCtx.getInputValue("attrMap"); String edit = (String) handlerCtx.getInputValue("edit"); String msgSecurityName = attrMap.get("msgSecurityName"); String configName = (String) handlerCtx.getInputValue("configName"); try { String providerName = URLEncoder.encode((String) attrMap.get("Name"), "UTF-8"); String providerEndpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/security-service/message-security-config/" + msgSecurityName + "/provider-config/" + providerName; if (edit.equals("true")) { boolean providerExist = RestUtil.get(providerEndpoint).isSuccess(); if (!providerExist) { GuiUtil.handleError( handlerCtx, GuiUtil.getMessage( COMMON_BUNDLE, "msg.error.noSuchProvider")); // normally won't happen. return; } else { Map<String, Object> providerMap = (Map<String, Object>) RestUtil.getEntityAttrs(providerEndpoint, "entity"); providerMap.put("className", attrMap.get("ClassName")); providerMap.put("providerType", attrMap.get("ProviderType")); RestUtil.restRequest(providerEndpoint, providerMap, "POST", null, false); Map attrs = new HashMap(); String endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/security-service/message-security-config/" + attrMap.get("msgSecurityName"); attrs.put("authLayer", attrMap.get("msgSecurityName")); if (attrMap.get("defaultProvider") != null && attrMap.get("defaultProvider").equals("true")) { if (providerMap.get("providerType").equals("client")) { attrs.put("defaultClientProvider", providerName); } else if (providerMap.get("providerType").equals("server")) { attrs.put("defaultProvider", providerName); } else if (providerMap.get("providerType").equals("client-server")) { attrs.put("defaultProvider", providerName); attrs.put("defaultClientProvider", providerName); } } if (attrMap.get("defaultProvider") == null) { if (providerMap.get("providerType").equals("client") && providerName.equals(attrMap.get("defaultClientProvider"))) { attrs.put("defaultClientProvider", ""); } else if (providerMap.get("providerType").equals("server") && providerName.equals(attrMap.get("defaultProvider"))) { attrs.put("defaultProvider", ""); } else if (providerMap.get("providerType").equals("client-server")) { if (providerName.equals(attrMap.get("defaultServerProvider")) && providerName.equals(attrMap.get("defaultClientProvider"))) { attrs.put("defaultProvider", ""); attrs.put("defaultClientProvider", ""); } } } RestUtil.sendUpdateRequest(endpoint, attrs, null, null, null); } } else { String endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/security-service/message-security-config"; Map attrs = new HashMap(); if (attrMap.get("defaultProvider") == null) { attrMap.put("defaultProvider", "false"); } attrs.put("isdefaultprovider", attrMap.get("defaultProvider")); attrs.put("id", attrMap.get("Name")); attrs.put("classname", attrMap.get("ClassName")); attrs.put("providertype", attrMap.get("ProviderType")); attrs.put("layer", attrMap.get("msgSecurityName")); attrs.put("target", configName); RestUtil.restRequest(endpoint, attrs, "POST", null, false); } // if we pass in "", backend will throw bean violation, since it only accepts certain values. String[] attrList = new String[] { "Request-AuthSource", "Request-AuthRecipient", "Response-AuthSource", "Response-AuthRecipient" }; for (int i = 0; i < attrList.length; i++) { if ("".equals(attrMap.get(attrList[i]))) { attrMap.put(attrList[i], null); } } Map reqPolicyMap = new HashMap(); reqPolicyMap.put("authSource", attrMap.get("Request-AuthSource")); reqPolicyMap.put("authRecipient", attrMap.get("Request-AuthRecipient")); String reqPolicyEP = providerEndpoint + "/request-policy"; RestUtil.restRequest(reqPolicyEP, reqPolicyMap, "POST", null, false); Map respPolicyMap = new HashMap(); respPolicyMap.put("authSource", attrMap.get("Response-AuthSource")); respPolicyMap.put("authRecipient", attrMap.get("Response-AuthRecipient")); String respPolicyEP = providerEndpoint + "/response-policy"; RestUtil.restRequest(respPolicyEP, respPolicyMap, "POST", null, false); } catch (Exception ex) { GuiUtil.handleException(handlerCtx, ex); } }