简体   繁体   English

使用Java解析和检索Policy Server响应的有效方法

[英]Effective way to parse & retrieve Policy Server response using Java

I have a Policy Server where I'm creating resources & roles. 我有一个Policy Server,用于创建资源和角色。 The resources are guided by policies which is defined based on the roles. 资源由基于角色定义的策略指导。 For ex. 对于前。 assume we have the following resources button1, button2, Submit, table2 & Roles like Google:NA:Admin, Yahoo:CHN:Admin, Google:CHN:User, Alphabet:EU:Admin , etc.. The user will be registering for a role by logging into the Policy Server site by providing username and password. 假设我们拥有以下资源button1,button2,Submit,table2和Roles(例如Google:NA:Admin,Yahoo:CHN:Admin,Google:CHN:User,Alphabet:EU:Admin等)。用户将注册一个通过提供用户名和密码登录到Policy Server站点。 I'm getting authorized resource list for each user from a server. 我正在从服务器获取每个用户的授权资源列表。 The response from the server will be like the following for a username "greenUser" (the only parameter sent as part of the POST request to Policy Server API). 对于用户名“ greenUser”(作为POST请求的一部分发送到Policy Server API的唯一参数),服务器的响应将类似于以下内容。

 {"permit":[ "button1", "table2", "Role:Google:NA:Admin", "Submit" ] } 

The requirement is to determine the Role of the user, Region, Company & the list of resources he has access. 要求是确定用户的角色,地区,公司以及他有权访问的资源列表。 So, I created a resource on the same name of the "Role" and restricted the access in Policy Server for that particular Role. 因此,我以“角色”的相同名称创建了资源,并限制了该特定角色在Policy Server中的访问。 eg: I created a role "Google:NA:Admin" and created a policy to restrict the access to only role "Role:Google:NA:Admin" . 例如:我创建了一个角色“ Google:NA:Admin”并创建了一个策略,以限制仅对角色“ Role:Google:NA:Admin”的访问 The intention is to find this resource as part of the response and to determine the Role the user is having. 目的是找到该资源作为响应的一部分,并确定用户所具有的角色。 There is a possibility that a user can having multiple roles. 用户可能具有多个角色。 eg. 例如。 He can be an admin for Google (NA region) & Alphabet (EU region). 他可以是Google(北美地区)和Alphabet(欧盟地区)的管理员。

To determine the Region and Company from the roles. 从角色中确定地区和公司。 I created a JSON like the following: 我创建了如下的JSON:

 { "Roles" : [{ "Google" : [{ "NA" : ["Role:Google:NA:Admin", "Role:Google:NA:User"]},{ "CHN" : ["Role:Google:CHN:Admin", "Role:Google:CHN:User"]} ] }, { "Alphabet" : [{ "NA" : ["Role:Alphabet:NA:Admin", "Role:Alphabet:NA:User"]},{ "CHN" : ["Role:Alphabet:CHN:Admin", "Role:Alphabet:CHN:User"]} ] } } 

I have created a method using Java which parses the entire JSON and if the value matches to the particular "Role" resource returned, then I'm capturing the Key (eg: CHN) as the Region & the key of the outer JSON Element as "Company". 我使用Java创建了一种方法,该方法可以解析整个JSON,如果值与返回的特定“角色”资源匹配,那么我将捕获Key(例如:CHN)作为Region,将外部JSON元素的密钥捕获为“公司”。

I want to check if there is a better way to determine the Role, Region & Company of the user. 我想检查是否有更好的方法来确定用户的角色,地区和公司。 The above mentioned JSON is my idea. 上面提到的JSON是我的想法。 I would love to hear if there is a better design or approach other than the JSON. 我想听听是否有比JSON更好的设计或方法。 Example Code snippets are appreciated. 示例代码段不胜感激。

Sorry for the long post. 抱歉,很长的帖子。 I tried my best to capture the complete requirement. 我尽力抓住了完整的要求。 Thanks in advance. 提前致谢。

If the policyserver has an API to getRoles for a given User I would use that or create one instead (if possible). 如果该策略服务器具有给定用户的getRoles的API,我将使用该API或创建一个API(如果可能)。 Adding roles as resource will be my last plan if all doors are closed. 如果关闭所有门,将角色添加为资源将是我的最后计划。

Not clear about which system generates the company-country-roles JSON. 不清楚哪个系统生成company-country-roles JSON。 Is it policy server or your application ? 是策略服务器还是您的应用程序? If it is policy server I would return array of policyNames (getRoles API). 如果是策略服务器,我将返回policyNames数组(getRoles API)。 If your application is going to return this JSON I would discuss it with the consumer of the application service and decide if it meets their expectations. 如果您的应用程序要返回此JSON,我将与应用程序服务的使用者进行讨论,并确定其是否符合他们的期望。 If there is no consumer I would just return array of Role Names to keep it simple 如果没有使用者,我将只返回角色名称数组以使其简单

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

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