public void addPrivilege(SSOToken token,String orgName,DelegationPrivilege privilege) throws SSOException, DelegationException {
  if (privilege != null) {
    try {
      if (hasDelegationPermissionsForRealm(token,orgName)) {
        token=(SSOToken)AccessController.doPrivileged(AdminTokenAction.getInstance());
      }
      PolicyManager pm=new PolicyManager(token,POLICY_REPOSITORY_REALM);
      Policy p=privilegeToPolicy(pm,privilege,orgName);
      if (p != null) {
        Set existingPolicies=pm.getPolicyNames();
        if (existingPolicies.contains(p.getName())) {
          Set<String> subjectNames=p.getSubjectNames();
          if ((subjectNames == null) || subjectNames.isEmpty()) {
            pm.removePolicy(p.getName());
          }
 else {
            pm.replacePolicy(p);
          }
        }
 else {
          Set<String> subjectNames=p.getSubjectNames();
          if ((subjectNames != null) && !subjectNames.isEmpty()) {
            pm.addPolicy(p);
          }
        }
      }
 else {
        throw new DelegationException(ResBundleUtils.rbName,"invalid_delegation_privilege",null,null);
      }
    }
 catch (    Exception e) {
      throw new DelegationException(e);
    }
  }
}

public void addPrivilege ( SSOToken token , String orgName , DelegationPrivilege privilege ) throws SSOException , DelegationException { if ( privilege != null ) { try { if ( hasDelegationPermissionsForRealm ( token , orgName ) ) { token = ( SSOToken ) AccessController . doPrivileged ( AdminTokenAction . getInstance ( ) ) ; } PolicyManager pm = new PolicyManager ( token , POLICY_REPOSITORY_REALM ) ; Policy p = privilegeToPolicy ( pm , privilege , orgName ) ; if ( p != null ) { Set existingPolicies = pm . getPolicyNames ( ) ; if ( existingPolicies . contains ( p . getName ( ) ) ) { Set < String > subjectNames = p . getSubjectNames ( ) ; if ( ( subjectNames == null ) || subjectNames . isEmpty ( ) ) { pm . removePolicy ( p . getName ( ) ) ; } else { pm . replacePolicy ( p ) ; } } else { Set < String > subjectNames = p . getSubjectNames ( ) ; if ( ( subjectNames != null ) && ! subjectNames . isEmpty ( ) ) { pm . addPolicy ( p ) ; } } } else { throw new DelegationException ( ResBundleUtils . rbName , "invalid_delegation_privilege" , null , null ) ; } } catch ( Exception e ) { throw new DelegationException ( e ) ; } } }
adds a delegation privilege to a specific realm . the permission will be added to the existing privilege in the event that this method is trying to add to an existing privilege .
