Here is the sample code to search and retrieve "Role Management" type Authorization Policy Data:
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import oracle.iam.authzpolicydefn.api.Action;
import oracle.iam.authzpolicydefn.api.AuthzPolicyConstants.AuthzPolicyAttributes;
import oracle.iam.authzpolicydefn.api.Feature;
import oracle.iam.authzpolicydefn.api.PolicyDefinitionService;
import oracle.iam.authzpolicydefn.vo.AuthzPolicy;
import oracle.iam.authzpolicydefn.vo.RoleDataConstraint;
import oracle.iam.identity.vo.Identity;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
public void getPolicyDetails(String policyName) {
try {
PolicyDefinitionService policyService = oimClient.getService(PolicyDefinitionService.class);
SearchCriteria criteria = new SearchCriteria(AuthzPolicyAttributes.NAME.getId(),policyName,SearchCriteria.Operator.EQUAL);
List policies = policyService.search(criteria);
for (AuthzPolicy policy : policies) {
// Returns Display Name of Policy
System.out.println(" Policy Name : " + policy.getDisplayName());
//Returns Description of the Policy
System.out.println(" Description : " + policy.getDescription());
//Returns the Enabled Permissions
List actions = policy.getActions();
for(Action action: actions) {
System.out.println(action.getDisplayName());
}
//Returns Type of Policy i.e., Role Management
Feature features = policy.getFeature();
System.out.println(" Entity Name : " + features.getDisplayName());
//Returns the Assignment i.e., roles that are added to the Policy
ArrayList userList = policy.getRoleAssignees();
for(Identity id: userList) {
System.out.println(" Assign by Role : " + id.getAttribute("Role Name"));
}
// Data Constraints i.e., Returns the Role Name attached with Policy
RoleDataConstraint rDataConstraint = (RoleDataConstraint) policy.getDataSecurity();
ArrayList roles = rDataConstraint.getRoles();
for(Identity role: roles) {
System.out.println(role.getAttribute("Role Name"));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Note: The APIs used above are not documented by Oracle.
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import oracle.iam.authzpolicydefn.api.Action;
import oracle.iam.authzpolicydefn.api.AuthzPolicyConstants.AuthzPolicyAttributes;
import oracle.iam.authzpolicydefn.api.Feature;
import oracle.iam.authzpolicydefn.api.PolicyDefinitionService;
import oracle.iam.authzpolicydefn.vo.AuthzPolicy;
import oracle.iam.authzpolicydefn.vo.RoleDataConstraint;
import oracle.iam.identity.vo.Identity;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
public void getPolicyDetails(String policyName) {
try {
PolicyDefinitionService policyService = oimClient.getService(PolicyDefinitionService.class);
SearchCriteria criteria = new SearchCriteria(AuthzPolicyAttributes.NAME.getId(),policyName,SearchCriteria.Operator.EQUAL);
List
for (AuthzPolicy policy : policies) {
System.out.println(" Policy Name : " + policy.getDisplayName());
System.out.println(" Description : " + policy.getDescription());
List
for(Action action: actions) {
System.out.println(action.getDisplayName());
}
//Returns Type of Policy i.e., Role Management
Feature features = policy.getFeature();
System.out.println(" Entity Name : " + features.getDisplayName());
//Returns the Assignment i.e., roles that are added to the Policy
ArrayList
for(Identity id: userList) {
System.out.println(" Assign by Role : " + id.getAttribute("Role Name"));
}
// Data Constraints i.e., Returns the Role Name attached with Policy
RoleDataConstraint rDataConstraint = (RoleDataConstraint) policy.getDataSecurity();
ArrayList
for(Identity role: roles) {
System.out.println(role.getAttribute("Role Name"));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Note: The APIs used above are not documented by Oracle.
No comments:
Post a Comment