Search in sources :

Example 1 with PrivilegeIndexStore

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

the class PolicyIndexTest method storeAndRetrieve.

@Test
public void storeAndRetrieve() throws SSOException, PolicyException, EntitlementException, Exception {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    PolicyManager pm = new PolicyManager(adminToken, "/");
    Set<String> hostIndexes = new HashSet<String>();
    Set<String> pathIndexes = new HashSet<String>();
    Set<String> parentPathIndexes = new HashSet<String>();
    hostIndexes.add("http://www.sun.com");
    pathIndexes.add("/private");
    parentPathIndexes.add("/");
    ResourceSearchIndexes indexes = new ResourceSearchIndexes(hostIndexes, pathIndexes, parentPathIndexes);
    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSubject(adminToken), "/");
    for (Iterator<IPrivilege> i = pis.search("/", indexes, Collections.EMPTY_SET, false); i.hasNext(); ) {
        IPrivilege eval = i.next();
        if (!(eval instanceof Privilege)) {
            throw new Exception("incorrect deserialized policy, wrong type");
        }
        Privilege p = (Privilege) eval;
        if (!p.getEntitlement().getResourceName().equals(URL_RESOURCE)) {
            throw new Exception("incorrect deserialized policy");
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) IPrivilege(com.sun.identity.entitlement.IPrivilege) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with PrivilegeIndexStore

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

the class OpenSSOPolicyDataStore method addPolicy.

public void addPolicy(Subject subject, String realm, Privilege privilege) throws EntitlementException {
    // Delegation to applications is currently not configurable, passing super admin (see AME-4959)
    ApplicationPrivilegeManager applPrivilegeMgr = ApplicationPrivilegeManager.getInstance(realm, PrivilegeManager.superAdminSubject);
    if (!applPrivilegeMgr.hasPrivilege(privilege, ApplicationPrivilege.Action.MODIFY)) {
        throw new EntitlementException(326);
    }
    String name = "";
    try {
        Object policy = PrivilegeUtils.privilegeToPolicyObject(realm, privilege);
        name = PrivilegeUtils.getPolicyName(policy);
        if (policy instanceof Policy || policy instanceof com.sun.identity.entitlement.xacml3.core.Policy) {
            String dn = getPolicyDistinguishedName(realm, name);
            if (SMSEntry.checkIfEntryExists(dn, dsameUserToken)) {
                throw new EntitlementException(EntitlementException.POLICY_ALREADY_EXISTS);
            }
            createParentNode(dsameUserToken, realm);
            SMSEntry s = new SMSEntry(dsameUserToken, dn);
            Map<String, Set<String>> map = new HashMap<String, Set<String>>();
            Set<String> setServiceID = new HashSet<String>(2);
            map.put(SMSEntry.ATTR_SERVICE_ID, setServiceID);
            setServiceID.add("NamedPolicy");
            Set<String> setObjectClass = new HashSet<String>(4);
            map.put(SMSEntry.ATTR_OBJECTCLASS, setObjectClass);
            setObjectClass.add(SMSEntry.OC_TOP);
            setObjectClass.add(SMSEntry.OC_SERVICE_COMP);
            Set<String> setValue = new HashSet<String>(2);
            map.put(SMSEntry.ATTR_KEYVAL, setValue);
            setValue.add(POLICY_XML + "=" + PrivilegeUtils.policyToXML(policy));
            s.setAttributes(map);
            String[] logParams = { DNMapper.orgNameToRealmName(realm), name };
            OpenSSOLogger.log(OpenSSOLogger.LogLevel.MESSAGE, Level.INFO, "ATTEMPT_ADD_PRIVILEGE", logParams, subject);
            s.save();
            OpenSSOLogger.log(OpenSSOLogger.LogLevel.MESSAGE, Level.INFO, "SUCCEEDED_ADD_PRIVILEGE", logParams, subject);
            PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(dsameUserSubject, realm);
            Set<IPrivilege> privileges = new HashSet<IPrivilege>();
            privileges.add(privilege);
            pis.add(privileges);
        } else {
            PrivilegeManager.debug.error("OpenSSOPolicyDataStore.addPolicy: unknown class " + policy.getClass().getName());
        }
    } catch (PolicyException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_PRIVILEGE", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(202, params, e);
    } catch (SSOException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_PRIVILEGE", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(202, params, e);
    } catch (SMSException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_PRIVILEGE", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(202, params, e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) HashSet(java.util.HashSet) Set(java.util.Set) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) EntitlementException(com.sun.identity.entitlement.EntitlementException) PolicyException(com.sun.identity.policy.PolicyException) IPrivilege(com.sun.identity.entitlement.IPrivilege) SMSEntry(com.sun.identity.sm.SMSEntry) HashSet(java.util.HashSet)

Example 3 with PrivilegeIndexStore

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

the class OpenSSOPolicyDataStore method addReferral.

public void addReferral(Subject subject, String realm, ReferralPrivilege referral) throws EntitlementException {
    String name = referral.getName();
    String dn = getPolicyDistinguishedName(realm, name);
    SSOToken adminToken = SubjectUtils.getSSOToken(subject);
    if (adminToken == null) {
        Object[] params = { name };
        throw new EntitlementException(260, params);
    }
    // Delegation to applications is currently not configurable, passing super admin (see AME-4959)
    ApplicationPrivilegeManager applPrivilegeMgr = ApplicationPrivilegeManager.getInstance(realm, PrivilegeManager.superAdminSubject);
    if (!applPrivilegeMgr.hasPrivilege(referral, ApplicationPrivilege.Action.MODIFY)) {
        throw new EntitlementException(326);
    }
    try {
        createParentNode(dsameUserToken, realm);
        SMSEntry s = new SMSEntry(dsameUserToken, dn);
        Map<String, Set<String>> map = new HashMap<String, Set<String>>();
        Set<String> setServiceID = new HashSet<String>(2);
        map.put(SMSEntry.ATTR_SERVICE_ID, setServiceID);
        setServiceID.add("NamedPolicy");
        Set<String> setObjectClass = new HashSet<String>(4);
        map.put(SMSEntry.ATTR_OBJECTCLASS, setObjectClass);
        setObjectClass.add(SMSEntry.OC_TOP);
        setObjectClass.add(SMSEntry.OC_SERVICE_COMP);
        Set<String> setValue = new HashSet<String>(2);
        map.put(SMSEntry.ATTR_KEYVAL, setValue);
        Policy p = PrivilegeUtils.referralPrivilegeToPolicy(realm, referral);
        setValue.add(POLICY_XML + "=" + p.toXML());
        s.setAttributes(map);
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.MESSAGE, Level.INFO, "ATTEMPT_ADD_REFERRAL", logParams, subject);
        s.save();
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.MESSAGE, Level.INFO, "SUCCEEDED_ADD_REFERRAL", logParams, subject);
        PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(dsameUserSubject, realm);
        Set<IPrivilege> tmp = new HashSet<IPrivilege>();
        tmp.add(referral);
        pis.add(tmp);
    } catch (PolicyException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_REFERRAL", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(261, params, e);
    } catch (SSOException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_REFERRAL", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(261, params, e);
    } catch (SMSException e) {
        String[] logParams = { DNMapper.orgNameToRealmName(realm), name, e.getMessage() };
        OpenSSOLogger.log(OpenSSOLogger.LogLevel.ERROR, Level.INFO, "FAILED_ADD_REFERRAL", logParams, subject);
        Object[] params = { name };
        throw new EntitlementException(261, params, e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ApplicationPrivilegeManager(com.sun.identity.entitlement.ApplicationPrivilegeManager) EntitlementException(com.sun.identity.entitlement.EntitlementException) PolicyException(com.sun.identity.policy.PolicyException) IPrivilege(com.sun.identity.entitlement.IPrivilege) SMSEntry(com.sun.identity.sm.SMSEntry) HashSet(java.util.HashSet)

Example 4 with PrivilegeIndexStore

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

the class NotificationServlet method handleReferralPrivilegeDeleted.

private void handleReferralPrivilegeDeleted(HttpServletRequest req) {
    String referralName = req.getParameter(ATTR_NAME);
    String realm = req.getParameter(ATTR_REALM_NAME);
    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(PolicyConstants.SUPER_ADMIN_SUBJECT, realm);
    try {
        pis.deleteReferral(referralName, false);
    } catch (EntitlementException e) {
    //ignore
    }
    // Get an instance as required otherwise it can cause issues on container restart.
    DataStore.getInstance().clearIndexCount(realm, true);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore)

Example 5 with PrivilegeIndexStore

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

the class NotificationServlet method handlePrivilegeDeleted.

private void handlePrivilegeDeleted(HttpServletRequest req) {
    String privilegeName = req.getParameter(ATTR_NAME);
    String realm = req.getParameter(ATTR_REALM_NAME);
    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(PolicyConstants.SUPER_ADMIN_SUBJECT, realm);
    try {
        pis.delete(privilegeName, false);
    } catch (EntitlementException e) {
    //ignore
    }
    // Get an instance as required otherwise it can cause issues on container restart.
    DataStore.getInstance().clearIndexCount(realm, false);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore)

Aggregations

EntitlementException (com.sun.identity.entitlement.EntitlementException)11 PrivilegeIndexStore (com.sun.identity.entitlement.PrivilegeIndexStore)11 SMSException (com.sun.identity.sm.SMSException)7 SSOException (com.iplanet.sso.SSOException)6 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)5 IPrivilege (com.sun.identity.entitlement.IPrivilege)5 HashSet (java.util.HashSet)5 SSOToken (com.iplanet.sso.SSOToken)4 SMSEntry (com.sun.identity.sm.SMSEntry)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 Policy (com.sun.identity.policy.Policy)3 PolicyException (com.sun.identity.policy.PolicyException)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 Privilege (com.sun.identity.entitlement.Privilege)2 Date (java.util.Date)2 Map (java.util.Map)2 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)1 ResourceSearchIndexes (com.sun.identity.entitlement.ResourceSearchIndexes)1 ServiceAlreadyExistsException (com.sun.identity.sm.ServiceAlreadyExistsException)1