@Test
  public void test() throws Exception {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    PolicyManager pm = new PolicyManager(adminToken, "/");
    Policy policy = new Policy("IdentityGroupToEntitlementGroupTest", "desc", false);
    policy.addRule(createRule());
    policy.addSubject("subject", createSubject(pm));

    Set<IPrivilege> privileges = PrivilegeUtils.policyObjectToPrivileges(policy);
    if ((privileges == null) || privileges.isEmpty()) {
      throw new Exception("IdentityGroupToEntitlementGroupTest, set is empty");
    }

    Privilege p = (Privilege) privileges.iterator().next();
    // uncomment after the groupsubject mapping is done
    /*        EntitlementSubject subject = p.getSubject();
    if (!(subject instanceof OrSubject)) {
        throw new Exception(
            "IdentityGroupToEntitlementGroupTest, orSubject not found");
    }

    OrSubject orSubject = (OrSubject)subject;
    Set<EntitlementSubject> subjects = orSubject.getESubjects();
    if ((subjects == null) || (subjects.size() != 2)) {
        throw new Exception(
            "IdentityGroupToEntitlementGroupTest, subjects collection is incorrect");
    }

    for (EntitlementSubject s : subjects) {
        if (!(s instanceof GroupSubject)) {
            throw new Exception(
                "IdentityGroupToEntitlementGroupTest, no group subject");
        }
    }*/
  }
Exemplo n.º 2
0
  protected Set getDefaultValues() {
    Set values = null;
    try {
      CachedPolicy cachedPolicy = getCachedPolicy();
      Policy policy = cachedPolicy.getPolicy();
      String referralName = (String) getPageSessionAttribute(PG_SESSION_REFERRAL_NAME);

      Referral referral = policy.getReferral(referralName);
      values = referral.getValues();
    } catch (NameNotFoundException e) {
      debug.warning("ReferralEditViewBean.getDefaultValues", e);
    } catch (AMConsoleException e) {
      debug.warning("ReferralEditViewBean.getDefaultValues", e);
    }
    return values;
  }
Exemplo n.º 3
0
  private void handleButton1Request(CachedPolicy cachedPolicy) throws ModelControlException {
    Referral deleted = null;
    String origName = (String) getPageSessionAttribute(EDIT_REFERRAL_NAME);
    Policy policy = cachedPolicy.getPolicy();

    try {
      Referral referral = createReferral();
      if (referral != null) {
        String name = (String) propertySheetModel.getValue(REFERRAL_NAME);

        if (origName.equals(name)) {
          policy.replaceReferral(name, referral);
        } else {
          deleted = policy.removeReferral(origName);
          policy.addReferral(name, referral);
        }

        deleted = null;
        setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information", "policy.referral.updated");
        cachedPolicy.setPolicyModified(true);
      }
    } catch (NameAlreadyExistsException e) {
      setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (InvalidNameException e) {
      setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (NameNotFoundException e) {
      setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (AMConsoleException e) {
      setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
    } finally {
      if (deleted != null) {
        try {
          policy.addReferral(origName, deleted);
        } catch (NameAlreadyExistsException e) {
          debug.warning("ReferralEditViewBean.handleButton1Request", e);
        } catch (InvalidNameException e) {
          debug.warning("ReferralEditViewBean.handleButton1Request", e);
        }
      }
    }
    forwardTo();
  }