[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.