Search in sources :

Example 21 with SearchFilter

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

the class DelegationPrivilegeTest method testModify.

@Test(dependsOnMethods = { "testAdd" })
public void testModify() throws Exception {
    SSOToken userSSOToken = AuthUtils.authenticate("/", testParams.get("DELEGATED_USER"), testParams.get("DELEGATED_USER"));
    ApplicationPrivilegeManager mgr = ApplicationPrivilegeManager.getInstance(realm, SubjectUtils.createSubject(userSSOToken));
    Set<SearchFilter> filters = new HashSet<SearchFilter>();
    String privilegeName = testParams.get("DELEGATE_PRIVILEGE_NAME");
    filters.add(new SearchFilter(Privilege.NAME_SEARCH_ATTRIBUTE, privilegeName));
    Set<String> names = mgr.search(filters);
    if ((names == null) || names.isEmpty()) {
        throw new Exception("DelegationPrivilegeTest.testModify: search failed");
    }
    ApplicationPrivilege ap = mgr.getPrivilege(privilegeName);
    Set<String> appRes = ap.getResourceNames(ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
    appRes.add(testParams.get("DELEGATED_SUB_RESOURCE"));
    mgr.replacePrivilege(ap);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 22 with SearchFilter

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

the class DelegationPrivilegeTest method testModifyNegative.

@Test(dependsOnMethods = { "testModify" })
public void testModifyNegative() throws Exception {
    SSOToken userSSOToken = AuthUtils.authenticate("/", testParams.get("NON_DELEGATED_USER"), testParams.get("NON_DELEGATED_USER"));
    ApplicationPrivilegeManager mgr = ApplicationPrivilegeManager.getInstance(realm, SubjectUtils.createSubject(userSSOToken));
    Set<SearchFilter> filters = new HashSet<SearchFilter>();
    String privilegeName = testParams.get("DELEGATE_PRIVILEGE_NAME");
    filters.add(new SearchFilter(Privilege.NAME_SEARCH_ATTRIBUTE, privilegeName));
    Set<String> privilegeNames = mgr.search(filters);
    if ((privilegeNames != null) && !privilegeNames.isEmpty()) {
        throw new Exception("DelegationPrivilegeTest.testModifyNegative" + "privilegeNames should be empty");
    }
    try {
        ApplicationPrivilege ap = mgr.getPrivilege(testParams.get("DELEGATE_PRIVILEGE_NAME"));
    } catch (EntitlementException e) {
        if (e.getErrorCode() != 325) {
            throw e;
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 23 with SearchFilter

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

the class ApplicationDelegationTest method test.

@Test(dependsOnMethods = { "negativeTest" })
public void test() throws Exception {
    Application appl = ApplicationManager.getApplication(testUserSubject, "/", APPL_NAME);
    // Test disabled, unable to fix model change.
    // Set<String> resources = appl.getResources();
    // if ((resources.size() != 1) &&
    //     !resources.contains(DELEGATED_RESOURCE)) {
    //     throw new Exception("ApplicationDelegationTest.test: " +
    //         "incorrect resource in application object");
    // }
    Set<SearchFilter> filter = new HashSet<SearchFilter>();
    filter.add(new SearchFilter(Privilege.NAME_SEARCH_ATTRIBUTE, PRIVILEGE_NAME + "*"));
    PrivilegeManager pm = PrivilegeManager.getInstance("/", testUserSubject);
    Set<String> names = pm.searchNames(filter);
    // that is delegated to him
    if (names.size() != 1) {
        throw new Exception("ApplicationDelegationTest.test: " + "privilege manager is not returning the correct search privilege name");
    }
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 24 with SearchFilter

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

the class ApplicationMetaData method test.

@Test
public void test() throws Exception {
    if (!migrated) {
        return;
    }
    Application appl = ApplicationManager.getApplication(adminSubject, "/", APPL_NAME);
    String createdBy = appl.getCreatedBy();
    long creationTime = appl.getCreationDate();
    long modifiedTime = appl.getLastModifiedDate();
    if (creationTime != modifiedTime) {
        throw new Exception("ApplicationMetaData.test: modified and creation time diff");
    }
    ApplicationManager.saveApplication(adminSubject, "/", appl);
    creationTime = appl.getCreationDate();
    modifiedTime = appl.getLastModifiedDate();
    if (creationTime == modifiedTime) {
        throw new Exception("ApplicationMetaData.test: modified and creation time unchanged");
    }
    if (!createdBy.equals(appl.getLastModifiedBy())) {
        throw new Exception("ApplicationMetaData.test: createdBy and modifiedBy should be the same");
    }
    Set<SearchFilter> filters = new HashSet<SearchFilter>();
    filters.add(new SearchFilter(Application.NAME_SEARCH_ATTRIBUTE, APPL_NAME));
    Set<String> results = ApplicationManager.search(adminSubject, "/", filters);
    if (!results.contains(APPL_NAME)) {
        throw new Exception("ApplicationMetaData.test: search fails");
    }
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter) SMSException(com.sun.identity.sm.SMSException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 25 with SearchFilter

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

the class MetaDataTest method test.

private void test(PrivilegeManager privilegMgr, SearchFilter.Operator operator, long value, String desc, boolean containCheckOnly) throws Exception {
    Set<SearchFilter> filter = new HashSet<SearchFilter>();
    filter.add(new SearchFilter(Privilege.CREATION_DATE_SEARCH_ATTRIBUTE, value, operator));
    Set<String> privilegeNames = privilegMgr.searchNames(filter);
    if (!containCheckOnly) {
        if ((privilegeNames == null) || (privilegeNames.size() != 1)) {
            throw new Exception("MetaDataTest.test: (" + desc + ") search privilege names failed");
        }
    }
    if (!privilegeNames.contains(POLICY_NAME)) {
        throw new Exception("MetaDataTest.test: (" + desc + ") search privilege names failed, Got the wrong privilege");
    }
}
Also used : SearchFilter(com.sun.identity.entitlement.util.SearchFilter) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Aggregations

SearchFilter (com.sun.identity.entitlement.util.SearchFilter)26 Test (org.testng.annotations.Test)18 QueryRequest (org.forgerock.json.resource.QueryRequest)9 HashSet (java.util.HashSet)8 JsonPointer (org.forgerock.json.JsonPointer)8 SSOException (com.iplanet.sso.SSOException)7 IdRepoException (com.sun.identity.idm.IdRepoException)7 Subject (javax.security.auth.Subject)6 EntitlementException (com.sun.identity.entitlement.EntitlementException)4 SearchAttribute (com.sun.identity.entitlement.util.SearchAttribute)4 SMSException (com.sun.identity.sm.SMSException)4 SSOToken (com.iplanet.sso.SSOToken)3 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)2 Date (java.util.Date)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 CLIException (com.sun.identity.cli.CLIException)1 IPrivilege (com.sun.identity.entitlement.IPrivilege)1 IPrivilegeManager (com.sun.identity.entitlement.IPrivilegeManager)1