Search in sources :

Example 6 with PwPolicy

use of org.apache.directory.fortress.core.model.PwPolicy in project directory-fortress-core by apache.

the class PwPolicyMgrRestImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public PwPolicy read(String name) throws SecurityException {
    VUtil.assertNotNullOrEmpty(name, GlobalErrIds.PSWD_NAME_NULL, CLS_NM + ".read");
    PwPolicy retPolicy;
    FortRequest request = RestUtils.getRequest(this.contextId);
    request.setEntity(new PwPolicy(name));
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.PSWD_READ);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        retPolicy = (PwPolicy) response.getEntity();
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retPolicy;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Example 7 with PwPolicy

use of org.apache.directory.fortress.core.model.PwPolicy in project directory-fortress-core by apache.

the class PolicyTestData method getPolicy.

/**
 * @param plcy
 * @return
 */
public static PwPolicy getPolicy(String[] plcy) {
    PwPolicy policy = new PwPolicy();
    policy.setName(getName(plcy));
    // policy.setAttribute(getAttribute(plcy));
    policy.setMinAge(getMinAge(plcy));
    policy.setMaxAge(getMaxAge(plcy));
    policy.setInHistory(getInHistory(plcy));
    policy.setCheckQuality(getCheckQuality(plcy));
    policy.setMinLength(getMinLength(plcy));
    policy.setExpireWarning(getExpireWarning(plcy));
    policy.setGraceLoginLimit(getGraceLoginLimit(plcy));
    policy.setLockout(getLockout(plcy));
    policy.setLockoutDuration(getLockoutDuration(plcy));
    policy.setMaxFailure(getMaxFailure(plcy));
    policy.setFailureCountInterval(getFailureCountInterval(plcy));
    policy.setMustChange(getMustChange(plcy));
    policy.setAllowUserChange(getAllowUserChange(plcy));
    policy.setSafeModify(getSafeModify(plcy));
    return policy;
}
Also used : PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Example 8 with PwPolicy

use of org.apache.directory.fortress.core.model.PwPolicy in project directory-fortress-core by apache.

the class PswdPolicyMgrImplTest method search.

/**
 * @param msg
 * @param pArray
 */
public void search(String msg, String srchValue, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = PwPolicyMgrFactory.createInstance(TestUtils.getContext());
        List<PwPolicy> policies = policyMgr.search(srchValue);
        assertNotNull(policies);
        assertTrue(CLS_NM + "search list size check", pArray.length == policies.size());
        for (String[] plcy : pArray) {
            int indx = policies.indexOf(new PwPolicy(PolicyTestData.getName(plcy)));
            if (indx != -1) {
                PwPolicy entity = policies.get(indx);
                assertNotNull(entity);
                PolicyTestData.assertEquals(entity, plcy);
            } else {
                msg = "search srchValue [" + srchValue + "] failed list search";
                LogUtil.logIt(msg);
                fail(msg);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("search srchValue [" + srchValue + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : PwPolicyMgr(org.apache.directory.fortress.core.PwPolicyMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Example 9 with PwPolicy

use of org.apache.directory.fortress.core.model.PwPolicy in project directory-fortress-core by apache.

the class PswdPolicyMgrImplTest method update.

/**
 * @param msg
 * @param pArray
 */
public void update(String msg, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = getManagedPswdMgr();
        for (String[] plcy : pArray) {
            PwPolicy policy = PolicyTestData.getPolicy(plcy);
            policyMgr.update(policy);
            LOG.debug("update name [" + policy.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("update caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : PwPolicyMgr(org.apache.directory.fortress.core.PwPolicyMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Example 10 with PwPolicy

use of org.apache.directory.fortress.core.model.PwPolicy in project directory-fortress-core by apache.

the class PswdPolicyMgrImplTest method checkQuality.

/**
 * PT14
 * 5.2.5  pwdCheckQuality
 * <p>
 * This attribute indicates how the password quality will be verified
 * while being modified or added.  If this attribute is not present, or
 * if the value is '0', quality checking will not be enforced.  A value
 * of '1' indicates that the server will check the quality, and if the
 * server is unable to check it (due to a hashed password or other
 * reasons) it will be accepted.  A value of '2' indicates that the
 * server will check the quality, and if the server is unable to verify
 * it, it will return an error refusing the password.
 *
 * @param msg
 * @param pArray
 */
public void checkQuality(String msg, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = getManagedPswdMgr();
        for (String[] plcy : pArray) {
            PwPolicy policy = PolicyTestData.getPolicy(plcy);
            policyMgr.add(policy);
            LOG.debug("checkQuality name [" + policy.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("checkQuality caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : PwPolicyMgr(org.apache.directory.fortress.core.PwPolicyMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Aggregations

PwPolicy (org.apache.directory.fortress.core.model.PwPolicy)17 SecurityException (org.apache.directory.fortress.core.SecurityException)9 PwPolicyMgr (org.apache.directory.fortress.core.PwPolicyMgr)6 FortRequest (org.apache.directory.fortress.core.model.FortRequest)3 FortResponse (org.apache.directory.fortress.core.model.FortResponse)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)2 FinderException (org.apache.directory.fortress.core.FinderException)2 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)2 ArrayList (java.util.ArrayList)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)1 ValidationException (org.apache.directory.fortress.core.ValidationException)1 AdminRole (org.apache.directory.fortress.core.model.AdminRole)1 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)1 Role (org.apache.directory.fortress.core.model.Role)1