Forum Stats

  • 3,781,648 Users
  • 2,254,533 Discussions
  • 7,879,774 Comments

Discussions

how to set role to a resource (portal, portlet..)

713996
713996 Member Posts: 3
edited Jul 27, 2009 9:06PM in WebLogic Portal
Hi everybody,

I have a resource's name and I want to set an role entitlement to a resource (portal, portlet, book...) but I don't know how to do this by programming.

Please help me. Thanks

Best Answer

  • stefans - moderator - oracle
    stefans - moderator - oracle Member Posts: 15
    Accepted Answer
    The code snippet below should help:

    ...
    ArrayList roles = new ArrayList();
    roles.add("MyRole");

    SecurityPolicyItem spi = new SecurityPolicyItem();
    spi.setEntAppName(appName);
    spi.setWebAppName(webappName);
    spi.setResourceId("com_bea_p13n\tPortlet\tportlet2");
    spi.setRoleList(roles);
    spi.setCapability(PortalEntitlementConstants.VIEW);

    //then use SecurityPolicyManager to create the security policy
    SecurityPolicyManager.createSecurityPolicy(spi);
    ...

    Regards, Stefan

Answers

  • Piyanai
    Piyanai Member Posts: 11
    I think it can't set an role entitlement to a resource by programming.

    It should be to set in portal administrator console.
  • 713996
    713996 Member Posts: 3
    edited Jul 27, 2009 3:11AM
    I can get all the roles entitled to a resource by programming as follows:
    String delimiter = EntitlementConstants.RESOURCE_ID_DELIMITER;
    String resourceID = "com_bea_p13n"+ delimiter +
    "Portlet"+ delimiter
    +"showProfile";
    String[] roles = RolePolicyManager.listRolesForResource(ApplicationHelper.getNonVersionedAppName(), ApplicationHelper.getWebAppName(getRequest()), resourceID);

    This code will return all the roles entitled to the portlet 'showProfile'.

    So I think, it is possible to set a role to a resource by programming, but I don't know how to do this.
    Anyone have an answer?

    Edited by: user11732508 on Jul 27, 2009 12:11 AM
  • stefans - moderator - oracle
    stefans - moderator - oracle Member Posts: 15
    Accepted Answer
    The code snippet below should help:

    ...
    ArrayList roles = new ArrayList();
    roles.add("MyRole");

    SecurityPolicyItem spi = new SecurityPolicyItem();
    spi.setEntAppName(appName);
    spi.setWebAppName(webappName);
    spi.setResourceId("com_bea_p13n\tPortlet\tportlet2");
    spi.setRoleList(roles);
    spi.setCapability(PortalEntitlementConstants.VIEW);

    //then use SecurityPolicyManager to create the security policy
    SecurityPolicyManager.createSecurityPolicy(spi);
    ...

    Regards, Stefan
  • 713996
    713996 Member Posts: 3
    Thank StefanS. It really work fine. Thank you so much.
This discussion has been closed.