Search in sources :

Example 11 with PwPolicy

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

the class PswdPolicyMgrImplTest method add.

/**
 * @param msg
 * @param pArray
 */
public static void add(String msg, String[][] pArray, boolean nofail) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = getManagedPswdMgr();
        for (String[] plcy : pArray) {
            PwPolicy policy = PolicyTestData.getPolicy(plcy);
            policyMgr.add(policy);
            LOG.debug("add name [" + policy.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        if (!nofail) {
            LOG.error("add 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 12 with PwPolicy

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

the class PswdPolicyMgrImplTest method read.

/**
 * @param msg
 * @param pArray
 */
public void read(String msg, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = PwPolicyMgrFactory.createInstance(TestUtils.getContext());
        for (String[] plcy : pArray) {
            PwPolicy entity = policyMgr.read(PolicyTestData.getName(plcy));
            PolicyTestData.assertEquals(entity, plcy);
        }
    } catch (SecurityException ex) {
        LOG.error("read 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 13 with PwPolicy

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

the class PswdPolicyMgrImplTest method delete.

/**
 * @param msg
 * @param pArray
 */
public void delete(String msg, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        PwPolicyMgr policyMgr = getManagedPswdMgr();
        for (String[] plcy : pArray) {
            PwPolicy policy = PolicyTestData.getPolicy(plcy);
            policyMgr.delete(policy);
            LOG.debug("deleteRecursive name [" + PolicyTestData.getName(plcy) + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("deleteRecursive 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 14 with PwPolicy

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

the class PolicyMgrConsole method add.

void add() {
    PwPolicy policy = new PwPolicy();
    try {
        /*
             *  public class PwPolicy
             *  {
                    private String name;
                    private String attribute;
                    private Integer minAge;
                    private Integer maxAge;
                    private Short inHistory;
                    private Short checkQuality;
                    private Short minLength;
                    private Integer expireWarning;
                    private Short graceLoginLimit;
                    private Boolean lockout;
                    private Integer lockoutDuration;
                    private Short maxFailure;
                    private Short failureCountInterval;
                    private Boolean mustChange;
                    private Boolean allowUserChange;
                    private Boolean safeModify;
             *  }
             */
        ReaderUtil.clearScreen();
        System.out.println("ADD PASSWORD POLICY");
        System.out.println("Enter name:");
        policy.setName(ReaderUtil.readLn());
        System.out.println(PWDCHECKQUALITY);
        System.out.println("Enter checkQuality:");
        policy.setCheckQuality(new Short(ReaderUtil.readLn()));
        System.out.println(PWDMAXAGE);
        System.out.println("Enter maxAge:");
        policy.setMaxAge(new Long(ReaderUtil.readLn()));
        System.out.println(PWDMINAGE);
        System.out.println("Enter minAge:");
        policy.setMinAge(new Integer(ReaderUtil.readLn()));
        System.out.println(PWDMINLENGTH);
        System.out.println("Enter minLength:");
        policy.setMinLength(new Short(ReaderUtil.readLn()));
        System.out.println(PWDFAILURECOUNTINTERVAL);
        System.out.println("Enter failureCountInterval:");
        policy.setFailureCountInterval(new Short(ReaderUtil.readLn()));
        System.out.println(PWDMAXFAILURE);
        System.out.println("Enter maxFailure:");
        policy.setMaxFailure(new Short(ReaderUtil.readLn()));
        System.out.println(PWDSAFEMODIFY);
        System.out.println("Enter safeModify:");
        policy.setSafeModify(Boolean.valueOf(ReaderUtil.readLn()));
        System.out.println(PWDMUSTCHANGE);
        System.out.println("Enter mustChange:");
        policy.setMustChange(Boolean.valueOf(ReaderUtil.readLn()));
        System.out.println(PWDINHISTORY);
        System.out.println("Enter inHistory:");
        policy.setInHistory(new Short(ReaderUtil.readLn()));
        System.out.println(PWDGRACELOGINLIMIT);
        System.out.println("Enter graceLoginLimit:");
        policy.setGraceLoginLimit(new Short(ReaderUtil.readLn()));
        System.out.println(PWDLOCKOUT);
        System.out.println("Enter lockout:");
        policy.setLockout(Boolean.valueOf(ReaderUtil.readLn()));
        System.out.println(PWDLOCKOUTDURATION);
        System.out.println("Enter lockoutDuration:");
        policy.setLockoutDuration(new Integer(ReaderUtil.readLn()));
        System.out.println(PWDALLOWUSERCHANGE);
        System.out.println("Enter allowUserChange:");
        policy.setAllowUserChange(Boolean.valueOf(ReaderUtil.readLn()));
        System.out.println(PWDEXPIREWARNING);
        System.out.println("Enter expireWarning:");
        policy.setExpireWarning(new Long(ReaderUtil.readLn()));
        pm.add(policy);
        System.out.print("policy name [" + policy.getName() + "]");
        System.out.println(" has been added");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("add caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : PwPolicy(org.apache.directory.fortress.core.model.PwPolicy)

Example 15 with PwPolicy

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

the class PolicyDAO method findPolicy.

/**
 * @param policy
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<PwPolicy> findPolicy(PwPolicy policy) throws FinderException {
    List<PwPolicy> policyArrayList = new ArrayList<>();
    LdapConnection ld = null;
    String policyRoot = getPolicyRoot(policy.getContextId());
    String searchVal = null;
    try {
        searchVal = encodeSafeText(policy.getName(), GlobalIds.PWPOLICY_NAME_LEN);
        String szFilter = GlobalIds.FILTER_PREFIX + PW_POLICY_CLASS + ")(" + PW_PWD_ID + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, policyRoot, SearchScope.ONELEVEL, szFilter, PASSWORD_POLICY_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            policyArrayList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "findPolicy name [" + searchVal + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPolicy name [" + searchVal + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return policyArrayList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

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