Search in sources :

Example 11 with ObjectFactory

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

the class SdDAO method unloadLdapEntry.

/**
 * @param le
 * @return
 * @throws LdapInvalidAttributeValueException
 * @throws LdapException
 */
private SDSet unloadLdapEntry(Entry le, long sequence) throws LdapInvalidAttributeValueException {
    SDSet entity = new ObjectFactory().createSDset();
    entity.setSequenceId(sequence);
    entity.setId(getAttribute(le, GlobalIds.FT_IID));
    entity.setName(getAttribute(le, SD_SET_NM));
    entity.setDescription(getAttribute(le, SchemaConstants.DESCRIPTION_AT));
    entity.setMembers(getAttributeSet(le, ROLES));
    String szCard = getAttribute(le, SD_SET_CARDINALITY);
    entity.setCardinality(Integer.valueOf(szCard));
    return entity;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

Example 12 with ObjectFactory

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

the class UserDAO method unloadUserAdminRoles.

/**
 * Given an ldap entry containing ARBAC roles assigned to user, retrieve the raw data and convert to a collection
 * of {@link UserAdminRole}
 * including {@link org.apache.directory.fortress.core.model.Constraint}.
 *
 * @param entry     contains ldap entry to retrieve admin roles from.
 * @param userId    attribute maps to {@link UserAdminRole#userId}.
 * @param contextId
 * @return List of type {@link UserAdminRole} containing admin roles assigned to a particular user.
 */
private List<UserAdminRole> unloadUserAdminRoles(Entry entry, String userId, String contextId) {
    List<UserAdminRole> uRoles = null;
    List<String> roles = getAttributes(entry, GlobalIds.USER_ADMINROLE_DATA);
    if (roles != null) {
        long sequence = 0;
        uRoles = new ArrayList<>();
        for (String raw : roles) {
            UserAdminRole ure = new ObjectFactory().createUserAdminRole();
            ure.load(raw, contextId, RoleUtil.getInstance());
            ure.setSequenceId(sequence++);
            ure.setUserId(userId);
            uRoles.add(ure);
        }
    }
    return uRoles;
}
Also used : ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole)

Example 13 with ObjectFactory

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

the class UserDAO method unloadLdapEntry.

/**
 * @param entry
 * @return
 * @throws LdapInvalidAttributeValueException
 */
private User unloadLdapEntry(Entry entry, long sequence, String contextId) throws LdapInvalidAttributeValueException {
    User entity = new ObjectFactory().createUser();
    entity.setSequenceId(sequence);
    entity.setInternalId(getAttribute(entry, GlobalIds.FT_IID));
    entity.setDescription(getAttribute(entry, SchemaConstants.DESCRIPTION_AT));
    entity.setUserId(getAttribute(entry, SchemaConstants.UID_AT));
    entity.setCn(getAttribute(entry, SchemaConstants.CN_AT));
    entity.setName(entity.getCn());
    entity.setSn(getAttribute(entry, SchemaConstants.SN_AT));
    entity.setOu(getAttribute(entry, SchemaConstants.OU_AT));
    entity.setDn(entry.getDn().getName());
    entity.setTitle(getAttribute(entry, SchemaConstants.TITLE_AT));
    entity.setEmployeeType(getAttribute(entry, EMPLOYEE_TYPE));
    unloadTemporal(entry, entity);
    entity.setRoles(unloadUserRoles(entry, entity.getUserId(), contextId, null));
    entity.setAdminRoles(unloadUserAdminRoles(entry, entity.getUserId(), contextId));
    entity.setAddress(unloadAddress(entry));
    entity.setPhones(getAttributes(entry, SchemaConstants.TELEPHONE_NUMBER_AT));
    entity.setMobiles(getAttributes(entry, MOBILE));
    entity.setEmails(getAttributes(entry, SchemaConstants.MAIL_AT));
    String szBoolean = getAttribute(entry, SYSTEM_USER);
    if (szBoolean != null) {
        entity.setSystem(Boolean.valueOf(szBoolean));
    }
    /*
                TODO: Add for RFC2307BIS
                entity.setUidNumber( getAttribute( entry, UID_NUMBER ) );
                entity.setGidNumber( getAttribute( entry, GID_NUMBER ) );
                entity.setHomeDirectory( getAttribute( entry, HOME_DIRECTORY ) );
                entity.setLoginShell( getAttribute( entry, LOGIN_SHELL ) );
                entity.setGecos( getAttribute( entry, GECOS ) );
        */
    entity.addProperties(PropUtil.getProperties(getAttributes(entry, GlobalIds.PROPS)));
    if (Config.getInstance().isOpenldap() || Config.getInstance().isApacheds()) {
        szBoolean = getAttribute(entry, OPENLDAP_PW_RESET);
        if (szBoolean != null && szBoolean.equalsIgnoreCase("true")) {
            entity.setReset(true);
        }
        String szPolicy = getAttribute(entry, OPENLDAP_POLICY_SUBENTRY);
        if (StringUtils.isNotEmpty(szPolicy)) {
            entity.setPwPolicy(getRdn(szPolicy));
        }
        szBoolean = getAttribute(entry, OPENLDAP_PW_LOCKED_TIME);
        if (szBoolean != null && szBoolean.equals(LOCK_VALUE)) {
            entity.setLocked(true);
        }
    }
    entity.setJpegPhoto(getPhoto(entry, JPEGPHOTO));
    return entity;
}
Also used : User(org.apache.directory.fortress.core.model.User) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

Example 14 with ObjectFactory

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

the class UserDAO method unloadAddress.

/**
 * Given an ldap entry containing organzationalPerson address information, convert to {@link Address}
 *
 * @param entry contains ldap entry to retrieve admin roles from.
 * @return entity of type {@link Address}.
 * @throws LdapInvalidAttributeValueException
 * @throws org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException in the event of ldap
 * client error.
 */
private Address unloadAddress(Entry entry) throws LdapInvalidAttributeValueException {
    Address addr = new ObjectFactory().createAddress();
    List<String> pAddrs = getAttributes(entry, SchemaConstants.POSTAL_ADDRESS_AT);
    if (pAddrs != null) {
        for (String pAddr : pAddrs) {
            addr.setAddress(pAddr);
        }
    }
    addr.setCity(getAttribute(entry, SchemaConstants.L_AT));
    addr.setState(getAttribute(entry, SchemaConstants.ST_AT));
    addr.setPostalCode(getAttribute(entry, SchemaConstants.POSTALCODE_AT));
    addr.setPostOfficeBox(getAttribute(entry, SchemaConstants.POSTOFFICEBOX_AT));
    addr.setBuilding(getAttribute(entry, SchemaConstants.PHYSICAL_DELIVERY_OFFICE_NAME_AT));
    addr.setDepartmentNumber(getAttribute(entry, DEPARTMENT_NUMBER));
    addr.setRoomNumber(getAttribute(entry, ROOM_NUMBER));
    return addr;
}
Also used : Address(org.apache.directory.fortress.core.model.Address) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

Example 15 with ObjectFactory

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

the class UserDAO method unloadUserRoles.

/**
 * Given an ldap entry containing RBAC roles assigned to user, retrieve the raw data and convert to a collection
 * of {@link UserRole}
 * including {@link org.apache.directory.fortress.core.model.Constraint}.
 *
 * @param entry     contains ldap entry to retrieve roles from.
 * @param userId    attribute maps to {@link UserRole#userId}.
 * @param contextId
 * @param roleNameFilter optional filter to only unload specified roles
 * @return List of type {@link UserRole} containing RBAC roles assigned to a particular user.
 */
private List<UserRole> unloadUserRoles(Entry entry, String userId, String contextId, String roleNameFilter) {
    Map<String, UserRole> uRoles = new HashMap<String, UserRole>();
    List<String> roles = getAttributes(entry, GlobalIds.USER_ROLE_DATA);
    if (roles != null) {
        long sequence = 0;
        for (String raw : roles) {
            // get role name
            String roleName = raw.substring(0, raw.indexOf(Config.getInstance().getDelimiter())).toUpperCase();
            // if role name filter provided, only unload role if it has that name
            if (roleNameFilter == null || roleNameFilter.toUpperCase().equals(roleName)) {
                // if already found, add to user role
                if (uRoles.containsKey(roleName)) {
                    UserRole ure = uRoles.get(roleName);
                    ure.load(raw, contextId, RoleUtil.getInstance());
                } else // else create new
                {
                    UserRole ure = new ObjectFactory().createUserRole();
                    ure.load(raw, contextId, RoleUtil.getInstance());
                    ure.setUserId(userId);
                    ure.setSequenceId(sequence++);
                    uRoles.put(roleName, ure);
                }
            }
        }
    }
    return new ArrayList<UserRole>(uRoles.values());
}
Also used : ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory) HashMap(java.util.HashMap) UserRole(org.apache.directory.fortress.core.model.UserRole) ArrayList(java.util.ArrayList)

Aggregations

ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)25 Role (org.apache.directory.fortress.core.model.Role)3 UserRole (org.apache.directory.fortress.core.model.UserRole)3 ArrayList (java.util.ArrayList)2 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 Constraint (org.apache.directory.fortress.core.model.Constraint)2 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)2 SDSet (org.apache.directory.fortress.core.model.SDSet)2 Session (org.apache.directory.fortress.core.model.Session)2 User (org.apache.directory.fortress.core.model.User)2 HashMap (java.util.HashMap)1 PasswordPolicy (org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)1 FinderException (org.apache.directory.fortress.core.FinderException)1 PasswordException (org.apache.directory.fortress.core.PasswordException)1 SecurityException (org.apache.directory.fortress.core.SecurityException)1 ValidationException (org.apache.directory.fortress.core.ValidationException)1 Address (org.apache.directory.fortress.core.model.Address)1