Create a simple authorization policy from OES and invoke
authorization decision using Standard API from a Java application to allow or deny the access.
- Create New Application (go to Authorization management > Application > click new Application)
- Create New Security Module (go to System Configuration > Security Module > click New) And add Newly Created Application to it.
- Create New Resource Type (go to Newly Created Application > Resource Types > Click new)
- Create New Resource (go to Newly Created Application > Default Policy Domain > Resources Catalog > Resources > Create New)
- Create New Permit Authorization Policy (go to Newly Created Application > Default Policy Domain > Application Policies > Create New)
- 6. Create New Deny Authorization Policy (go to Newly Created Application > Default Policy Domain > Application Policies > Create New)
1. Edit the following file: OES_CLIENT_HOME/oessm/SMConfigTool/smconfig.java.controlled.prp
oracle.security.jps.runtime.pd.client.sm_name=SM_WB_JAVANOTE: same name as created using OES Admin Console# Policy dustribution mode is controlled-pushoracle.security.jps.runtime.pd.client.policyDistributionMode=controlled-push# -------- Policy Distributor connectivity information - required for controlled-push distribution modeoracle.security.jps.runtime.pd.client.RegistrationServerHost=localhostoracle.security.jps.runtime.pd.client.RegistrationServerPort=7002Note- SSL Port of OES Server# >>>>>>>>>>>>OPTIONAL PARAMETERS<<<<<<<<<<<<<<<<<# ------------ Only for Java SM, WS SM, and RMI SM in controlled-push mode --------------------# port to listen for policy distribution. Picked automatically by SM config tool if not specifiedoracle.security.jps.runtime.pd.client.DistributionServicePort=oracle.security.jps.runtime.pd.client.sm_type=java8. Run the config.sh (OES_CLIENT_HOME/oessm/bin)config.sh –smConfigId <SM_NAME_AS _IN_PRP_FILE> -prpFileNameOES_CLIENT_HOME/oessm/SMConfigTool/smconfig.java.controlled.prp9. This will create a directory in OES_CLIENT_HOME /oes_sm_instances/< SM_NAME_AS _IN_PRP_FILE >10. Create a sample application to validate the authorization request. Code Snippet is as follows-
1. public class HelloWBworld {2.3. public static void main(String[] args) {4.5. // user initiating Authorization request6. Principal p = new WLSUserImpl("weblogic_wc");7. System.out.println("HelloWBworld :: principal :: "+p);8. Subject user = new Subject();9. System.out.println("HelloWBworld :: Subject :: "+user);10.11. user.getPrincipals().add(p);12. System.out.println("HelloWBworld :: Subject after add :: "+user);13.14. // Resource being accessed AppName/ResourceType/ResouceName15. String resourceString = "HelloWBWorld/MyWBResourceType/MyWBResource";16. System.out.println("HelloWBworld :: resourceString :: "+resourceString);17.18. // Action initiated by the user19. String action = "write";20. System.out.println("HelloWBworld :: action :: "+action);21. // Environmental/Context attributes22.23. while (true)24. {25. System.out.println("HelloWBworld :: while start ");26. try {27. // get Authorization response from OES28. PepResponse response =29. PepRequestFactoryImpl.getPepRequestFactory()30. .newPepRequest(31. user,32. action,33. resourceString,34. null).decide();35.36. System.out.println("Request: {" + user + " " + action + " " + resourceString37. + "} \nResult: " + response.allowed());38.39. // } catch (PepException e) {40. } catch (PepException e) {41.42. System.out.println("***** Caught exception: "43. + e.getMessage());44. e.printStackTrace();45. System.exit(1);46. }47. }48. };49. };11. Run the program to check that it is authorizing the user initiating the resource request.
Comments
Post a Comment