Search in sources :

Example 11 with ApplicationPrivilege

use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.

the class OpenSSOApplicationPrivilegeManager method replacePrivilege.

public void replacePrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
    if (delegatables.hasPrivilege(appPrivilege.getName())) {
        validatePrivilege(appPrivilege);
        Privilege[] privileges = toPrivilege(appPrivilege);
        PrivilegeManager pm = PrivilegeManager.getInstance(getHiddenRealmDN(), dsameUserSubject);
        pm.modify(privileges[0]);
        cachePrivilege(privileges[0]);
        pm.modify(privileges[1]);
        cachePrivilege(privileges[1]);
    } else {
        throw new EntitlementException(326);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege)

Example 12 with ApplicationPrivilege

use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.

the class OpenSSOApplicationPrivilegeManager method toPrivilege.

/**
     * Creates two privileges here
     */
private Privilege[] toPrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
    Privilege[] results = new Privilege[2];
    try {
        Privilege actualP = Privilege.getNewInstance();
        actualP.setName(appPrivilege.getName());
        actualP.setDescription(appPrivilege.getDescription());
        Set<String> res = createDelegationResources(appPrivilege);
        Entitlement entitlement = new Entitlement(APPL_NAME, res, getActionValues(appPrivilege.getActionValues()));
        actualP.setEntitlement(entitlement);
        Privilege ghostP = Privilege.getNewInstance();
        ghostP.setName(GHOST_PRIVILEGE_NAME_PREFIX + appPrivilege.getName());
        Set<String> ghostRes = new HashSet<String>();
        String currentOrgDN = DNMapper.orgNameToDN(realm);
        Object[] param = { currentOrgDN };
        ghostRes.add(MessageFormat.format(SUN_AM_REALM_RESOURCE, param));
        ghostRes.add(MessageFormat.format(SUN_IDREPO_RESOURCE, param));
        entitlement = new Entitlement(APPL_NAME, ghostRes, getActionValues(ApplicationPrivilege.PossibleAction.READ));
        ghostP.setEntitlement(entitlement);
        Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
        Set<EntitlementSubject> eSubjects = new HashSet<EntitlementSubject>();
        for (SubjectImplementation i : subjects) {
            eSubjects.add((EntitlementSubject) i);
        }
        OrSubject orSubject = new OrSubject(eSubjects);
        actualP.setSubject(orSubject);
        actualP.setCondition(appPrivilege.getCondition());
        ghostP.setSubject(orSubject);
        ghostP.setCondition(appPrivilege.getCondition());
        Set<String> applIndexes = new HashSet<String>();
        applIndexes.addAll(appPrivilege.getApplicationNames());
        actualP.setApplicationIndexes(applIndexes);
        results[0] = actualP;
        results[1] = ghostP;
    } catch (UnsupportedEncodingException ex) {
        String[] params = {};
        throw new EntitlementException(324, params);
    }
    return results;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OrSubject(com.sun.identity.entitlement.OrSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) EntitlementException(com.sun.identity.entitlement.EntitlementException) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Example 13 with ApplicationPrivilege

use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.

the class SetApplicationPrivilegeSubjects method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = { realm, name };
    Set<SubjectImplementation> newSubjects = getSubjects(rc);
    boolean bAdd = isOptionSet(PARAM_ADD);
    Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
    ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
    try {
        ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
        Set<SubjectImplementation> origSubjects = appPrivilege.getSubjects();
        Set<SubjectImplementation> subjects = (bAdd) ? mergeSubjects(origSubjects, newSubjects) : newSubjects;
        appPrivilege.setSubject(subjects);
        apm.replacePrivilege(appPrivilege);
        Object[] msgParam = { name };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("update-application-privilege-succeeded"), msgParam));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
        throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) CLIException(com.sun.identity.cli.CLIException) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) Subject(javax.security.auth.Subject)

Example 14 with ApplicationPrivilege

use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.

the class ShowApplicationPrivilege method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = { realm, name };
    Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
    ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_APPLICATION_PRIVILEGE", params);
    try {
        ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
        outputInfo("show-application-privilege-output-name", name);
        String description = appPrivilege.getDescription();
        if (description == null) {
            description = "";
        }
        outputInfo("show-application-privilege-output-description", description);
        outputInfo("show-application-privilege-output-actions", getDisplayAction(appPrivilege));
        outputInfo("show-application-privilege-output-subjects", getSubjects(appPrivilege));
        outputInfo("show-application-privilege-output-resources", getApplicationToResources(appPrivilege));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_SHOW_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_SHOW_APPLICATION_PRIVILEGE", paramExs);
        throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) CLIException(com.sun.identity.cli.CLIException) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) Subject(javax.security.auth.Subject)

Example 15 with ApplicationPrivilege

use of com.sun.identity.entitlement.ApplicationPrivilege in project OpenAM by OpenRock.

the class SetApplicationPrivilegeResources method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = { realm, name };
    try {
        Map<String, Set<String>> mapAppToResources = getApplicationResourcesMap(rc, realm);
        boolean bAdd = isOptionSet(PARAM_ADD);
        Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
        ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
        ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
        Map<String, Set<String>> origAppToResources = getApplicationToResources(appPrivilege);
        Map map = (bAdd) ? mergeMap(origAppToResources, mapAppToResources) : mapAppToResources;
        appPrivilege.setApplicationResources(map);
        apm.replacePrivilege(appPrivilege);
        Object[] msgParam = { name };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("update-application-privilege-succeeded"), msgParam));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
        throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : Set(java.util.Set) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) Subject(javax.security.auth.Subject) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) CLIException(com.sun.identity.cli.CLIException) Map(java.util.Map)

Aggregations

ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)21 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)19 EntitlementException (com.sun.identity.entitlement.EntitlementException)12 HashSet (java.util.HashSet)10 CLIRequest (com.sun.identity.cli.CLIRequest)9 Test (org.testng.annotations.Test)9 CLIException (com.sun.identity.cli.CLIException)7 Subject (javax.security.auth.Subject)7 SubjectImplementation (com.sun.identity.entitlement.SubjectImplementation)6 Set (java.util.Set)5 AMIdentity (com.sun.identity.idm.AMIdentity)4 SSOException (com.iplanet.sso.SSOException)3 IPrivilege (com.sun.identity.entitlement.IPrivilege)3 Privilege (com.sun.identity.entitlement.Privilege)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 IdRepoException (com.sun.identity.idm.IdRepoException)3 Entitlement (com.sun.identity.entitlement.Entitlement)2 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)2