繁体   English   中英

wso2 身份服务器自定义处理程序从属性文件读取

[英]wso2 identity server custom handler reading from properties file

 public class UserRegistrationCustomEventHandler extends AbstractEventHandler { JSONObject jsonObject = null; private static final Log log = LogFactory.getLog(UserRegistrationCustomEventHandler.class); @Override public String getName() { return "customClaimUpdate"; } if (IdentityEventConstants.Event.POST_SET_USER_CLAIMS.equals(event.getEventName())) { String tenantDomain = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.TENANT_DOMAIN); String userName = (String) event.getEventProperties().get(IdentityEventConstants.EventProperty.USER_NAME); Map<String, Object> eventProperties = event.getEventProperties(); String eventName = event.getEventName(); UserStoreManager userStoreManager = (UserStoreManager) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER); // String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration()); @SuppressWarnings("unchecked") Map<String, String> claimValues = (Map<String, String>) eventProperties.get(IdentityEventConstants.EventProperty.USER_CLAIMS); String emailId = claimValues.get("http://wso2.org/claims/emailaddress"); userName = "USERS/"+userName; JSONObject json = new JSONObject(); json.put("userName",userName ); json.put("emailId",emailId ); log.info("JSON:::::::"+json); // Sample API //String apiValue = "http://192.168.1.X:8080/SomeService/user/updateUserEmail?email=sujith@gmail.com&userName=USERS/sujith"; try { URL url = new URL(cityAppUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setConnectTimeout(5000); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); con.setDoOutput(true); con.setDoInput(true); con.setRequestMethod("POST"); log.info("CONN:::::::::::::"+con); OutputStream os = con.getOutputStream(); os.write(cityAppUrl.toString().getBytes("UTF-8")); os.close(); InputStream in = new BufferedInputStream(con.getInputStream()); String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8"); jsonObject = new JSONObject(result); log.info("JSON OBJECT:::::::::"+jsonObject); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void init(InitConfig configuration) throws IdentityRuntimeException { super.init(configuration); } @Override public int getPriority(MessageContext messageContext) { return 250; } }

我正在使用 wso2 身份服务器 5.10.0 并且必须将更新的声明值推送到 API 所以我使用自定义处理程序并订阅了 POST_SET_USER_CLAIMS,我必须从 jave 代码中的 deployment.toml 文件中读取 API 值自定义处理程序。 所以任何人都可以在这里帮忙从部署文件中读取值

我可以在日志中获取更新后的声明值,但我无法获取 API 值。 所以任何人都可以在这里帮助我从部署文件中读取值。

由于自定义事件处理程序中需要 API 路径,因此我们将 API 路径值定义为事件处理程序的属性之一。

添加 deployment.toml 配置如下。

[[event_handler]]
name= "UserRegistrationCustomEventHandler"
subscriptions =["POST_SET_USER_CLAIMS"]
properties.apiPath = "http://192.168.1.X:8080/SomeService/user/updateUserEmail"

重新启动服务器后, identity-event.properties文件将填充给定的配置。

在您的自定义事件处理程序 java 中,代码需要从identity-event.properties文件中读取配置。 文件读取在服务器启动时完成,每个配置都加载到 memory。

通过将此添加到您的 java 代码,您可以加载到属性中的配置值。

configs.getModuleProperties().getProperty("UserRegistrationCustomEventHandler.apiPath")

注意:属性名称需要定义为<event_handler_name>.<property_name>

这是对此类事件处理器的属性加载代码片段的引用 https://github.com/wso2-extensions/identity-governance/blob/68e3f2d5e246b6a75f48e314ee1019230c662b55/components/org.wso2.carbon.identity.srcword/main/policy/ java/org/wso2/carbon/identity/password/policy/handler/PasswordPolicyValidationHandler.java#L128-L133

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM