/** * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setUserData(org.opencms.file.CmsUser, org.opencms.workplace.list.CmsListItem) */ @Override protected void setUserData(CmsUser user, CmsListItem item) { super.setUserData(user, item); item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + user.getOuFqn()); }
/** * Returns true if the list of users has users of other organizational units.<p> * * @return <code>true</code> if the list of users has users of other organizational units */ public boolean hasUsersInOtherOus() { if (m_lazy) { // if we use database-side paging, we have to assume that there may be users from other OUs return true; } if (m_hasUsersInOtherOus == null) { // lazy initialization m_hasUsersInOtherOus = Boolean.FALSE; try { Iterator<CmsUser> itUsers = getUsers(true).iterator(); while (itUsers.hasNext()) { CmsUser user = itUsers.next(); if (!user.getOuFqn().equals(getParamOufqn())) { m_hasUsersInOtherOus = Boolean.TRUE; break; } } } catch (Exception e) { // ignore } } return m_hasUsersInOtherOus.booleanValue(); }
/** * Returns the simple name if the ou is the same as the current user's ou.<p> * * @param name the fully qualified name to check * * @return the simple name if the ou is the same as the current user's ou */ private String getCurrentOuRelativeName(String name) { if (m_request == null) { return CmsOrganizationalUnit.SEPARATOR + name; } String ou = CmsOrganizationalUnit.getParentFqn(name); if (ou.equals(m_request.getCurrentUser().getOuFqn())) { return CmsOrganizationalUnit.getSimpleName(name); } return CmsOrganizationalUnit.SEPARATOR + name; }
/** * Returns the simple name if the ou is the same as the current user's ou.<p> * * @param name the fully qualified name to check * * @return the simple name if the ou is the same as the current user's ou */ private String getCurrentOuRelativeName(String name) { if (m_request == null) { return CmsOrganizationalUnit.SEPARATOR + name; } String ou = CmsOrganizationalUnit.getParentFqn(name); if (ou.equals(m_request.currentUser().getOuFqn())) { return CmsOrganizationalUnit.getSimpleName(name); } return CmsOrganizationalUnit.SEPARATOR + name; }
/** * Returns if the list of principals has principals of other organizational units.<p> * * @return if the list of principals has principals of other organizational units */ public boolean hasPrincipalsInOtherOus() { if (m_hasPrincipalsInOtherOus == null) { // lazzy initialization m_hasPrincipalsInOtherOus = Boolean.FALSE; try { Iterator itPrincipals = getPrincipals(true).iterator(); while (itPrincipals.hasNext()) { CmsPrincipal principal = (CmsPrincipal)itPrincipals.next(); if (!principal.getOuFqn().equals(getCms().getRequestContext().currentUser().getOuFqn())) { m_hasPrincipalsInOtherOus = Boolean.TRUE; break; } } } catch (Exception e) { // ignore } } return m_hasPrincipalsInOtherOus.booleanValue(); }
/** * Returns if the list of principals has principals of other organizational units.<p> * * @return if the list of principals has principals of other organizational units */ public boolean hasPrincipalsInOtherOus() { if (m_hasPrincipalsInOtherOus == null) { // lazzy initialization m_hasPrincipalsInOtherOus = Boolean.FALSE; try { Iterator<CmsPrincipal> itPrincipals = getPrincipals(true).iterator(); while (itPrincipals.hasNext()) { CmsPrincipal principal = itPrincipals.next(); if (!principal.getOuFqn().equals(getCms().getRequestContext().getCurrentUser().getOuFqn())) { m_hasPrincipalsInOtherOus = Boolean.TRUE; break; } } } catch (Exception e) { // ignore } } return m_hasPrincipalsInOtherOus.booleanValue(); }
/** * Returns the simple name if the ou is the same as the current user's ou.<p> * * @param cms the CMS context * @param name the fully qualified name to check * * @return the simple name if the ou is the same as the current user's ou */ protected static String getOuAwareName(CmsObject cms, String name) { String ou = CmsOrganizationalUnit.getParentFqn(name); if (ou.equals(cms.getRequestContext().getCurrentUser().getOuFqn())) { return CmsOrganizationalUnit.getSimpleName(name); } return CmsOrganizationalUnit.SEPARATOR + name; }
/** * Returns the simple name if the ou is the same as the current user's ou.<p> * * @param cms the CMS context * @param name the fully qualified name to check * * @return the simple name if the ou is the same as the current user's ou */ protected static String getOuAwareName(CmsObject cms, String name) { String ou = CmsOrganizationalUnit.getParentFqn(name); if (ou.equals(cms.getRequestContext().getCurrentUser().getOuFqn())) { return CmsOrganizationalUnit.getSimpleName(name); } return CmsOrganizationalUnit.SEPARATOR + name; }
/** * Returns the simple name if the ou is the same as the current user's ou.<p> * * @param cms the CMS context * @param name the fully qualified name to check * * @return the simple name if the ou is the same as the current user's ou */ public static String getOuAwareName(CmsObject cms, String name) { String ou = CmsOrganizationalUnit.getParentFqn(name); if (ou.equals(cms.getRequestContext().getCurrentUser().getOuFqn())) { return CmsOrganizationalUnit.getSimpleName(name); } return CmsOrganizationalUnit.SEPARATOR + name; }
/** * Returns the right icon path for the given list item.<p> * * @param item the list item to get the icon path for * * @return the icon path for the given role */ public String getIconPath(CmsListItem item) { try { CmsUser user = getCms().readUser((String)item.get(LIST_COLUMN_LOGIN)); if (user.getOuFqn().equals(getParamOufqn())) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } else { return A_CmsUsersList.PATH_BUTTONS + "user_other_ou.png"; } } catch (CmsException e) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } }
/** * Returns the right icon path for the given list item.<p> * * @param item the list item to get the icon path for * * @return the icon path for the given role */ public String getIconPath(CmsListItem item) { try { CmsUser user = getCms().readUser((String)item.get(LIST_COLUMN_LOGIN)); if (user.getOuFqn().equals(getParamOufqn())) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } else { return A_CmsUsersList.PATH_BUTTONS + "user_other_ou.png"; } } catch (CmsException e) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } }
/** * Returns the description of the parent ou.<p> * * @return the description of the parent ou */ public String getAssignedOu() { try { return OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_user.getOuFqn()).getDisplayName( getLocale()); } catch (CmsException e) { return null; } }
/** * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getIconPath() */ @Override public String getIconPath() { try { CmsUser user = getCms().readUser((String)getItem().get(LIST_COLUMN_LOGIN)); if (user.getOuFqn().equals(((A_CmsRoleUsersList)getWp()).getParamOufqn())) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } else { return A_CmsUsersList.PATH_BUTTONS + "user_other_ou.png"; } } catch (CmsException e) { return A_CmsUsersList.PATH_BUTTONS + "user.png"; } } };
/** * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() */ @Override protected List<CmsListItem> getListItems() throws CmsException { List<CmsListItem> ret = new ArrayList<CmsListItem>(); // get content List<CmsUser> users = getUsers(); Iterator<CmsUser> itUsers = users.iterator(); while (itUsers.hasNext()) { CmsUser user = itUsers.next(); CmsListItem item = getList().newItem(user.getId().toString()); item.set(LIST_COLUMN_LOGIN, user.getName()); item.set(LIST_COLUMN_NAME, user.getSimpleName()); item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + user.getOuFqn()); item.set(LIST_COLUMN_FULLNAME, user.getFullName()); ret.add(item); } return ret; }
/** * Sets all needed data of the user into the list item object.<p> * * @param user the user to set the data for * @param item the list item object to set the data into */ protected void setUserData(CmsUser user, CmsListItem item) { item.set(LIST_COLUMN_LOGIN, user.getName()); item.set(LIST_COLUMN_NAME, user.getSimpleName()); item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + user.getOuFqn()); item.set(LIST_COLUMN_FULLNAME, user.getFullName()); }
/** * @see org.opencms.security.CmsPrincipal#getDisplayName(org.opencms.file.CmsObject, java.util.Locale) */ @Override public String getDisplayName(CmsObject cms, Locale locale) throws CmsException { if (OpenCms.getOrgUnitManager().getOrganizationalUnits(cms, "", true).size() > 0) { return org.opencms.security.Messages.get().getBundle(locale).key( org.opencms.security.Messages.GUI_PRINCIPAL_DISPLAY_NAME_2, getFullName(), OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, getOuFqn()).getDisplayName(locale)); } else { return getFullName(); } }
/** * @see org.opencms.security.CmsPrincipal#getDisplayName(org.opencms.file.CmsObject, java.util.Locale) */ @Override public String getDisplayName(CmsObject cms, Locale locale) throws CmsException { if (OpenCms.getOrgUnitManager().getOrganizationalUnits(cms, "", true).size() > 0) { return org.opencms.security.Messages.get().getBundle(locale).key( org.opencms.security.Messages.GUI_PRINCIPAL_DISPLAY_NAME_2, getFullName(), OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, getOuFqn()).getDisplayName(locale)); } else { return getFullName(); } }
/** * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters() */ @Override protected void validateParamaters() throws Exception { // test the needed parameters String ou = getCms().readUser(new CmsUUID(getParamUserid())).getOuFqn(); OpenCms.getRoleManager().checkRole(getCms(), CmsRole.ACCOUNT_MANAGER.forOrgUnit(ou)); }
/** * Logs a user with a given ip address into the Cms, if the password is correct.<p> * * @param username the name of the user * @param password the password of the user * @param remoteAddress the ip address * * @return the name of the logged in user * * @throws CmsException if the login was not successful */ public String loginUser(String username, String password, String remoteAddress) throws CmsException { // login the user CmsUser newUser = m_securityManager.loginUser(m_context, username, password, remoteAddress); // set the project back to the "Online" project CmsProject newProject = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID); // switch the cms context to the new user and project m_context.switchUser(newUser, newProject, newUser.getOuFqn()); // init this CmsObject with the new user init(m_securityManager, m_context); // fire a login event fireEvent(I_CmsEventListener.EVENT_LOGIN_USER, newUser); // return the users login name return newUser.getName(); }
/** * Makes a list item from a user.<p> * * @param user the user * * @return the list item */ protected CmsListItem makeUserItem(CmsUser user) { CmsListItem item = getList().newItem(user.getId().toString()); item.set(LIST_COLUMN_LOGIN, user.getName()); item.set(LIST_COLUMN_NAME, user.getSimpleName()); item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + user.getOuFqn()); item.set(LIST_COLUMN_FULLNAME, user.getFullName()); return item; }