Search in sources :

Example 71 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class RestletRealmRouterTest method shouldRouteToRealm.

@Test(dataProvider = "realmRoutingDataProvider")
public void shouldRouteToRealm(String realmLocation, boolean isRealmAlias) throws Exception {
    //Given
    SSOToken adminToken = mock(SSOToken.class);
    Restlet next = mock(Restlet.class);
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    Request request = setUpRequest(httpRequest, adminToken);
    Response response = mock(Response.class);
    String realm;
    if (!isRealmAlias) {
        realm = "REALM";
    } else {
        realm = "REALM_ALIAS";
    }
    if ("dns".equalsIgnoreCase(realmLocation)) {
        //set up server name
        setUpServerName(request, adminToken, realm);
    }
    if ("query".equalsIgnoreCase(realmLocation)) {
        //set up query string
        setUpServerName(request, adminToken, "/");
        setUpQueryString(request, realm);
    }
    if ("uri".equalsIgnoreCase(realmLocation)) {
        //set up uri
        setUpServerName(request, adminToken, "/");
        setUpUri(request, realm);
    }
    //set up validate realm
    setUpRealmValidator(realm, isRealmAlias, adminToken);
    //When
    router.doHandle(next, request, response);
    //Then
    assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
    verify(httpRequest).setAttribute("realm", "/REALM");
    assertThat(request.getAttributes()).containsEntry("realmUrl", "The base url");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 72 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class DataStore method hasPrivilgesWithApplication.

public boolean hasPrivilgesWithApplication(Subject adminSubject, String realm, String applName) throws EntitlementException {
    SSOToken token = getSSOToken(adminSubject);
    //Search privilege
    String filter = "(ou=" + Privilege.APPLICATION_ATTRIBUTE + "=" + applName + ")";
    String baseDN = getSearchBaseDN(realm, null);
    if (hasEntries(token, baseDN, filter)) {
        return true;
    }
    //Search referral privilege
    baseDN = getSearchBaseDN(realm, REFERRAL_STORE);
    if (hasEntries(token, baseDN, filter)) {
        return true;
    }
    //Search delegation privilege
    baseDN = getSearchBaseDN(getHiddenRealmDN(), null);
    if (hasEntries(token, baseDN, filter)) {
        return true;
    }
    return false;
}
Also used : SSOToken(com.iplanet.sso.SSOToken)

Example 73 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class DataStore method searchPrivileges.

private Set<IPrivilege> searchPrivileges(String realm, BufferedIterator iterator, ResourceSearchIndexes indexes, Set<String> subjectIndexes, boolean bSubTree, Set<String> excludeDNs) throws EntitlementException {
    Set<IPrivilege> results = new HashSet<IPrivilege>();
    String filter = getFilter(indexes, subjectIndexes, bSubTree);
    String baseDN = getSearchBaseDN(realm, null);
    if (PolicyConstants.DEBUG.messageEnabled()) {
        PolicyConstants.DEBUG.message("[PolicyEval] DataStore.searchPrivileges");
        PolicyConstants.DEBUG.message("[PolicyEval] search filter: " + filter);
        PolicyConstants.DEBUG.message("[PolicyEval] search DN: " + baseDN);
    }
    if (filter != null) {
        SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        long start = DB_MONITOR_PRIVILEGE.start();
        if (SMSEntry.checkIfEntryExists(baseDN, token)) {
            try {
                Iterator i = SMSEntry.search(token, baseDN, filter, NO_LIMIT, NO_LIMIT, NOT_SORTED, NOT_SORTED, excludeDNs);
                while (i.hasNext()) {
                    SMSDataEntry e = (SMSDataEntry) i.next();
                    Privilege privilege = Privilege.getInstance(new JSONObject(e.getAttributeValue(SERIALIZABLE_INDEX_KEY)));
                    iterator.add(privilege);
                    results.add(privilege);
                }
            } catch (JSONException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            } catch (SMSException e) {
                Object[] arg = { baseDN };
                throw new EntitlementException(52, arg, e);
            }
        }
        DB_MONITOR_PRIVILEGE.end(start);
    }
    return results;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSException(com.sun.identity.sm.SMSException) JSONException(org.json.JSONException) EntitlementException(com.sun.identity.entitlement.EntitlementException) JSONObject(org.json.JSONObject) IPrivilege(com.sun.identity.entitlement.IPrivilege) BufferedIterator(com.sun.identity.shared.BufferedIterator) Iterator(java.util.Iterator) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) HashSet(java.util.HashSet)

Example 74 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class DataStore method remove.

/**
     * Removes privilege.
     *
     * @param adminSubject Admin Subject who has the rights to write to
     *        datastore.
     * @param realm Realm name.
     * @param name Privilege name.
     * @throws com.sun.identity.entitlement.EntitlementException if privilege
     * cannot be removed.
     */
public void remove(Subject adminSubject, String realm, String name) throws EntitlementException {
    SSOToken token = getSSOToken(adminSubject);
    if (token == null) {
        Object[] arg = { name };
        throw new EntitlementException(55, arg);
    }
    String dn = null;
    try {
        dn = getPrivilegeDistinguishedName(name, realm, null);
        if (SMSEntry.checkIfEntryExists(dn, token)) {
            SMSEntry s = new SMSEntry(token, dn);
            s.delete();
            updateIndexCount(realm, -1, false);
            Map<String, String> params = new HashMap<String, String>();
            params.put(NotificationServlet.ATTR_NAME, name);
            params.put(NotificationServlet.ATTR_REALM_NAME, realm);
            Notifier.submit(NotificationServlet.PRIVILEGE_DELETED, params);
        }
    } catch (SMSException e) {
        Object[] arg = { dn };
        throw new EntitlementException(51, arg, e);
    } catch (SSOException e) {
        throw new EntitlementException(10, null, e);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) JSONObject(org.json.JSONObject) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

Example 75 with SSOToken

use of com.iplanet.sso.SSOToken in project OpenAM by OpenRock.

the class EntitlementService method addApplicationAction.

/**
     * Adds a new action.
     *
     * @param appName application name.
     * @param name Action name.
     * @param defVal Default value.
     * @throws EntitlementException if action cannot be added.
     */
public void addApplicationAction(String appName, String name, Boolean defVal) throws EntitlementException {
    try {
        SSOToken token = SubjectUtils.getSSOToken(getAdminSubject());
        if (token == null) {
            throw new EntitlementException(226);
        }
        ServiceConfig applConf = getApplicationSubConfig(token, realm, appName);
        if (applConf != null) {
            Map<String, Set<String>> data = applConf.getAttributes();
            Map<String, Set<String>> result = addAction(data, name, defVal);
            if (result != null) {
                applConf.setAttributes(result);
            }
        }
    } catch (SMSException ex) {
        throw new EntitlementException(221, ex);
    } catch (SSOException ex) {
        throw new EntitlementException(221, ex);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Aggregations

SSOToken (com.iplanet.sso.SSOToken)776 SSOException (com.iplanet.sso.SSOException)390 Set (java.util.Set)226 SMSException (com.sun.identity.sm.SMSException)218 HashSet (java.util.HashSet)179 IdRepoException (com.sun.identity.idm.IdRepoException)144 HashMap (java.util.HashMap)130 Test (org.testng.annotations.Test)130 CLIException (com.sun.identity.cli.CLIException)117 Iterator (java.util.Iterator)115 AMIdentity (com.sun.identity.idm.AMIdentity)113 Map (java.util.Map)113 IOutput (com.sun.identity.cli.IOutput)99 IOException (java.io.IOException)68 List (java.util.List)57 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)56 IdType (com.sun.identity.idm.IdType)54 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)53 EntitlementException (com.sun.identity.entitlement.EntitlementException)52 ServiceConfig (com.sun.identity.sm.ServiceConfig)52