Search in sources :

Example 26 with UserAdminRole

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

the class ReviewMgrConsole method findUsersByOrg.

/**
 */
void findUsersByOrg() {
    String szOu;
    ReaderUtil.clearScreen();
    try {
        System.out.println("Enter OrgUnit name");
        szOu = ReaderUtil.readLn();
        OrgUnit ou = new OrgUnit(szOu);
        ou.setType(OrgUnit.Type.USER);
        List<User> list = rm.findUsers(ou);
        int ctr = 0;
        for (User ue : list) {
            System.out.println("USER[" + ++ctr + "]");
            System.out.println("    userId      [" + ue.getUserId() + "]");
            System.out.println("    internalId  [" + ue.getInternalId() + "]");
            System.out.println("    description [" + ue.getDescription() + "]");
            System.out.println("    common name [" + ue.getCn() + "]");
            System.out.println("    surname     [" + ue.getSn() + "]");
            System.out.println("    orgUnitId   [" + ue.getOu() + "]");
            System.out.println("    pwpolicy    [" + ue.getPwPolicy() + "]");
            printTemporal(ue, "USER");
            printAddress(ue.getAddress(), "ADDRESS");
            printPhone(ue.getPhones(), "PHONES");
            printPhone(ue.getMobiles(), "MOBILES");
            if (ue.getRoles() != null) {
                for (UserRole ur : ue.getRoles()) {
                    printTemporal(ur, "RBACROLE");
                }
            }
            if (ue.getAdminRoles() != null) {
                for (UserAdminRole ur : ue.getAdminRoles()) {
                    printAdminRole(ur);
                    printTemporal(ur, "ADMINROLE");
                }
            }
            if (ue.getProperties() != null && ue.getProperties().size() > 0) {
                int pctr = 0;
                for (Enumeration e = ue.getProperties().propertyNames(); e.hasMoreElements(); ) {
                    String key = (String) e.nextElement();
                    String val = ue.getProperty(key);
                    System.out.println("prop key[" + pctr + "]=" + key);
                    System.out.println("prop value[" + pctr++ + "]=" + val);
                }
            }
            System.out.println();
        }
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("findUsersByOrg caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) User(org.apache.directory.fortress.core.model.User) Enumeration(java.util.Enumeration) UserRole(org.apache.directory.fortress.core.model.UserRole) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) Constraint(org.apache.directory.fortress.core.model.Constraint)

Example 27 with UserAdminRole

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

the class ReviewMgrConsole method getUser.

void getUser() {
    String userVal;
    ReaderUtil.clearScreen();
    try {
        System.out.println("Enter Internal id for user:");
        userVal = ReaderUtil.readLn();
        User ue = new User();
        ue.setInternalId(userVal);
        ArrayList list = (ArrayList) rm.findUsers(ue);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            ue = (User) list.get(i);
            System.out.println("USER[" + i + "]");
            System.out.println("    userId      [" + ue.getUserId() + "]");
            System.out.println("    internalId  [" + ue.getInternalId() + "]");
            System.out.println("    description [" + ue.getDescription() + "]");
            System.out.println("    common name [" + ue.getCn() + "]");
            System.out.println("    surname     [" + ue.getSn() + "]");
            System.out.println("    orgUnitId   [" + ue.getOu() + "]");
            System.out.println("    pwpolicy    [" + ue.getPwPolicy() + "]");
            printTemporal(ue, "USER");
            printPosixAccount(ue, "POSIX");
            printAddress(ue.getAddress(), "ADDRESS");
            printPhone(ue.getPhones(), "PHONES");
            printPhone(ue.getMobiles(), "MOBILES");
            if (ue.getRoles() != null) {
                for (UserRole ur : ue.getRoles()) {
                    printTemporal(ur, "RBACROLE");
                }
            }
            if (ue.getAdminRoles() != null) {
                for (UserAdminRole ur : ue.getAdminRoles()) {
                    printAdminRole(ur);
                    printTemporal(ur, "ADMINROLE");
                }
            }
            if (ue.getProperties() != null && ue.getProperties().size() > 0) {
                int ctr = 0;
                for (Enumeration e = ue.getProperties().propertyNames(); e.hasMoreElements(); ) {
                    String key = (String) e.nextElement();
                    String val = ue.getProperty(key);
                    System.out.println("prop key[" + ctr + "]=" + key);
                    System.out.println("prop value[" + ctr++ + "]=" + val);
                }
            }
            System.out.println();
        }
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("getUser caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : User(org.apache.directory.fortress.core.model.User) Enumeration(java.util.Enumeration) UserRole(org.apache.directory.fortress.core.model.UserRole) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) ArrayList(java.util.ArrayList) Constraint(org.apache.directory.fortress.core.model.Constraint)

Example 28 with UserAdminRole

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

the class UserDAO method getUserAdminRoles.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<UserAdminRole> getUserAdminRoles(User user) throws FinderException {
    List<UserAdminRole> roles = null;
    LdapConnection ld = null;
    String userDn = getDn(user.getUserId(), user.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, userDn, AROLE_ATR);
        roles = unloadUserAdminRoles(findEntry, user.getUserId(), user.getContextId());
    } catch (LdapNoSuchObjectException e) {
        String warning = "getUserAdminRoles COULD NOT FIND ENTRY for user [" + user.getUserId() + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getUserAdminRoles [" + userDn + "]= caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roles;
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 29 with UserAdminRole

use of org.apache.directory.fortress.core.model.UserAdminRole 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 30 with UserAdminRole

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

the class UserDAO method loadUserAdminRoles.

/**
 * Given a collection of ARBAC roles, {@link UserAdminRole}, convert to raw data format and load into ldap
 * modification set in preparation for ldap modify.
 *
 * @param list contains List of type {@link UserAdminRole} targeted for updating to ldap.
 * @param mods contains ldap modification set containing ARBAC role assignments in raw ldap format to be updated.
 * @throws LdapInvalidAttributeValueException
 */
private void loadUserAdminRoles(List<UserAdminRole> list, List<Modification> mods) throws LdapInvalidAttributeValueException {
    Attribute userAdminRoleData = new DefaultAttribute(GlobalIds.USER_ADMINROLE_DATA);
    Attribute userAdminRoleAssign = new DefaultAttribute(GlobalIds.USER_ADMINROLE_ASSIGN);
    if (list != null) {
        boolean nameSeen = false;
        for (UserAdminRole userRole : list) {
            userAdminRoleData.add(userRole.getRawData());
            if (!nameSeen) {
                userAdminRoleAssign.add(userRole.getName());
                nameSeen = true;
            }
        }
        if (userAdminRoleData.size() != 0) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, userAdminRoleData));
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, userAdminRoleAssign));
        }
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Aggregations

UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)34 User (org.apache.directory.fortress.core.model.User)16 SecurityException (org.apache.directory.fortress.core.SecurityException)12 UserRole (org.apache.directory.fortress.core.model.UserRole)10 AdminRole (org.apache.directory.fortress.core.model.AdminRole)8 Constraint (org.apache.directory.fortress.core.model.Constraint)6 Enumeration (java.util.Enumeration)5 DelAdminMgr (org.apache.directory.fortress.core.DelAdminMgr)5 ArrayList (java.util.ArrayList)4 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)4 Role (org.apache.directory.fortress.core.model.Role)4 Session (org.apache.directory.fortress.core.model.Session)4 TreeSet (java.util.TreeSet)3 AccessMgr (org.apache.directory.fortress.core.AccessMgr)3 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)3 PermObj (org.apache.directory.fortress.core.model.PermObj)3 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)2 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)2 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2