Search in sources :

Example 1 with SubjectImplementation

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

the class RemoveApplicationPrivilegeSubjects 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);
    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();
        origSubjects.removeAll(newSubjects);
        if (origSubjects.isEmpty()) {
            throw new CLIException(getResourceString("remove-application-privilege-subjects-emptied-subjects"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        appPrivilege.setSubject(origSubjects);
        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 2 with SubjectImplementation

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

the class CreateApplicationPrivilege 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 };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_CREATE_APPLICATION_PRIVILEGE", params);
    String description = getStringOptionValue(PARAM_DESCRIPTION);
    ApplicationPrivilege.PossibleAction actions = getActions();
    Set<SubjectImplementation> subjects = getSubjects(rc);
    try {
        Map<String, Set<String>> mapAppToResources = getApplicationResourcesMap(rc, realm);
        Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
        ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
        ApplicationPrivilege appPrivilege = new ApplicationPrivilege(name);
        appPrivilege.setDescription(description);
        appPrivilege.setActionValues(actions);
        appPrivilege.setApplicationResources(mapAppToResources);
        appPrivilege.setSubject(subjects);
        apm.addPrivilege(appPrivilege);
        Object[] msgParam = { name };
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-application-privilege-succeeded"), msgParam));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_CREATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_PRIVILEGE", paramExs);
        throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (CLIException ex) {
        String[] paramExs = { realm, name, ex.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_CREATE_APPLICATION_PRIVILEGE", paramExs);
        throw ex;
    }
}
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) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation)

Example 3 with SubjectImplementation

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

the class ApplicationPrivilegeBase method getSubjects.

protected Map<String, Set<String>> getSubjects(ApplicationPrivilege appPrivilege) {
    Map<String, Set<String>> results = new HashMap<String, Set<String>>();
    Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
    for (SubjectImplementation subject : subjects) {
        String type = null;
        String uuid = null;
        if (subject instanceof OpenSSOUserSubject) {
            type = PARAM_SUBJECT_USER;
            uuid = ((OpenSSOUserSubject) subject).getID();
        } else if (subject instanceof OpenSSOGroupSubject) {
            type = PARAM_SUBJECT_GROUP;
            uuid = ((OpenSSOGroupSubject) subject).getID();
        }
        if (type != null) {
            Set<String> set = results.get(type);
            if (set == null) {
                set = new HashSet<String>();
                results.put(type, set);
            }
            set.add(uuid);
        }
    }
    return results;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) OpenSSOGroupSubject(com.sun.identity.entitlement.opensso.OpenSSOGroupSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation)

Example 4 with SubjectImplementation

use of com.sun.identity.entitlement.SubjectImplementation 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 5 with SubjectImplementation

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

the class ApplicationPrivilegeBase method getSubjects.

protected Set<SubjectImplementation> getSubjects(RequestContext rc) throws CLIException {
    Set<SubjectImplementation> eSubjects = new HashSet<SubjectImplementation>();
    boolean bUser = isUserSubject();
    IdType idType = (bUser) ? IdType.USER : IdType.GROUP;
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List<String> subjects = rc.getOption(PARAM_SUBJECTS);
    for (String s : subjects) {
        // create AMIdentity just to get the uuid.
        AMIdentity amid = new AMIdentity(null, s, idType, realm, null);
        String universalId = amid.getUniversalId();
        SubjectImplementation sbj = (bUser) ? new OpenSSOUserSubject(universalId) : new OpenSSOGroupSubject(universalId);
        eSubjects.add(sbj);
    }
    return eSubjects;
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) OpenSSOGroupSubject(com.sun.identity.entitlement.opensso.OpenSSOGroupSubject) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) HashSet(java.util.HashSet) IdType(com.sun.identity.idm.IdType)

Aggregations

SubjectImplementation (com.sun.identity.entitlement.SubjectImplementation)9 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)5 HashSet (java.util.HashSet)5 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)4 Set (java.util.Set)4 CLIException (com.sun.identity.cli.CLIException)3 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)3 Subject (javax.security.auth.Subject)3 Entitlement (com.sun.identity.entitlement.Entitlement)2 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 OrSubject (com.sun.identity.entitlement.OrSubject)2 OpenSSOGroupSubject (com.sun.identity.entitlement.opensso.OpenSSOGroupSubject)2 AMIdentity (com.sun.identity.idm.AMIdentity)2 HashMap (java.util.HashMap)2 SSOException (com.iplanet.sso.SSOException)1 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)1 IPrivilege (com.sun.identity.entitlement.IPrivilege)1 Privilege (com.sun.identity.entitlement.Privilege)1 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)1