List of usage examples for com.liferay.portal.kernel.model Company isStrangers
public boolean isStrangers();
From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS); }/* w w w .j a va2 s. c o m*/ actionRequest = _wrapActionRequest(actionRequest); String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try { if (cmd.equals(Constants.ADD)) { CaptchaConfiguration captchaConfiguration = getCaptchaConfiguration(); if (captchaConfiguration.createAccountCaptchaEnabled()) { CaptchaUtil.check(actionRequest); } addUser(actionRequest, actionResponse); } else if (cmd.equals(Constants.RESET)) { resetUser(actionRequest, actionResponse); } else if (cmd.equals(Constants.UPDATE)) { updateIncompleteUser(actionRequest, actionResponse); } } catch (Exception e) { if (e instanceof UserEmailAddressException.MustNotBeDuplicate || e instanceof UserScreenNameException.MustNotBeDuplicate) { String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); User user = _userLocalService.fetchUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress); if ((user == null) || (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) { SessionErrors.add(actionRequest, e.getClass(), e); } else { actionResponse.setRenderParameter("mvcPath", "/update_account.jsp"); } } else if (e instanceof AddressCityException || e instanceof AddressStreetException || e instanceof AddressZipException || e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException || e instanceof ContactBirthdayException || e instanceof ContactNameException || e instanceof DuplicateOpenIdException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException || e instanceof NoSuchListTypeException || e instanceof NoSuchOrganizationException || e instanceof NoSuchRegionException || e instanceof OrganizationParentException || e instanceof PhoneNumberException || e instanceof RequiredFieldException || e instanceof RequiredUserException || e instanceof TermsOfUseException || e instanceof UserEmailAddressException || e instanceof UserIdException || e instanceof UserPasswordException || e instanceof UserScreenNameException || e instanceof UserSmsException || e instanceof WebsiteURLException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { throw e; } } if (Validator.isNull(PropsValues.COMPANY_SECURITY_STRANGERS_URL)) { return; } try { Layout layout = _layoutLocalService.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, PropsValues.COMPANY_SECURITY_STRANGERS_URL); String redirect = _portal.getLayoutURL(layout, themeDisplay); sendRedirect(actionRequest, actionResponse, redirect); } catch (NoSuchLayoutException nsle) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsle, nsle); } } }
From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletConfig portletConfig = (PortletConfig) actionRequest .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); String portletName = portletConfig.getPortletName(); if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) { throw new PrincipalException("Unable to create anonymous account"); }/* w ww.ja va2 s . co m*/ if (actionRequest.getRemoteUser() != null) { actionResponse.sendRedirect(themeDisplay.getPathMain()); return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, LoginPortletKeys.FAST_LOGIN, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect"); portletURL.setParameter("emailAddress", emailAddress); portletURL.setParameter("anonymousUser", Boolean.TRUE.toString()); portletURL.setWindowState(LiferayWindowState.POP_UP); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try { if (cmd.equals(Constants.ADD)) { addAnonymousUser(actionRequest, actionResponse); sendRedirect(actionRequest, actionResponse, portletURL.toString()); } else if (cmd.equals(Constants.UPDATE)) { Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS); } jsonObject = updateIncompleteUser(actionRequest, actionResponse); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } } catch (Exception e) { if (cmd.equals(Constants.UPDATE)) { jsonObject.putException(e); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) { User user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress); if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) { SessionErrors.add(actionRequest, e.getClass()); } else { sendRedirect(actionRequest, actionResponse, portletURL.toString()); } } else if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException || e instanceof ContactNameException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof UserEmailAddressException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { _log.error("Unable to create anonymous account", e); _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.web.internal.servlet.taglib.include.CreateAccountNavigationPostPageInclude.java
License:Open Source License
@Override public void include(PageContext pageContext) throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String mvcRenderCommandName = request.getParameter("mvcRenderCommandName"); if ("/login/create_account".equals(mvcRenderCommandName)) { return;/*from w w w. j a va2s. c om*/ } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { return; } PortletConfig portletConfig = (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); String portletName = portletConfig.getPortletName(); if (portletName.equals(PortletKeys.FAST_LOGIN)) { return; } IconTag iconTag = new IconTag(); iconTag.setIconCssClass("icon-plus"); iconTag.setMessage("create-account"); try { iconTag.setUrl(_portal.getCreateAccountURL(request, themeDisplay)); } catch (Exception e) { throw new JspException(e); } iconTag.doTag(pageContext); }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java
License:Open Source License
protected void checkDeleteUserPermission(long deleteUserId, long companyId, long userId, ServiceContext serviceContext) throws PortalException { Company company = CompanyLocalServiceUtil.getCompany(companyId); boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser"); long defaultUserId = userLocalService.getDefaultUserId(companyId); if (((deleteUserId != 0) && (deleteUserId != defaultUserId)) || (!company.isStrangers() && !anonymousUser)) { PermissionChecker permissionChecker = getPermissionChecker(); // Check if user has an according group added with assign members User creator = this.getUser(deleteUserId); long[] creatorUserGroupIds = creator.getGroupIds(); boolean hasGroupRight = false; // Either group needs right ADD_USER if (creatorUserGroupIds != null && creatorUserGroupIds.length > 0) { int index = 0; while (!hasGroupRight && index < creatorUserGroupIds.length) { hasGroupRight = UserGroupPermissionUtil.contains(getPermissionChecker(), creatorUserGroupIds[index++], ActionKeys.DELETE_USER); }//w ww.j ava2 s . c o m } // or the user itself if (!hasGroupRight && !PortalPermissionUtil.contains(permissionChecker, ActionKeys.DELETE_USER)) { throw new PrincipalException.MustHavePermission(permissionChecker, Organization.class.getName(), 0, ActionKeys.UPDATE_USER, ActionKeys.ASSIGN_MEMBERS); } } }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java
License:Open Source License
protected void checkUpdateUserPermission(long updateUserId, long userId, long companyId, long[] groupIds, long[] organizationIds, long[] roleIds, long[] userGroupIds, ServiceContext serviceContext) throws PortalException { Company company = CompanyLocalServiceUtil.getCompany(companyId); // Adding user must be member of everything he adds long[] userIds = new long[] { updateUserId }; // Check if creator / updater is also part in the groups ServicePermissionUtil.checkMembership(userIds, groupIds, organizationIds, roleIds, userGroupIds); if (groupIds != null && groupIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER); angularGroupService.checkGroups(userId, groupIds); }/*from ww w . ja va2 s .c om*/ if (organizationIds != null && organizationIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION); angularOrganizationService.checkOrganizations(userId, organizationIds); } if (roleIds != null && roleIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE); angularRoleService.checkRoles(userId, roleIds); } if (userGroupIds != null && userGroupIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER_GROUP); angularUserGroupService.checkUserGroupIds(userId, userGroupIds); } if (serviceContext == null) { serviceContext = new ServiceContext(); } boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser"); long defaultUserId = userLocalService.getDefaultUserId(companyId); if (((updateUserId != 0) && (updateUserId != defaultUserId)) || (!company.isStrangers() && !anonymousUser)) { UserPermissionUtil.check(getPermissionChecker(), updateUserId, ActionKeys.UPDATE_USER); UserPermissionUtil.check(getPermissionChecker(), userId, organizationIds, ActionKeys.UPDATE); } }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java
License:Open Source License
protected void checkAddUserPermission(long creatorUserId, long companyId, String emailAddress, long[] groupIds, long[] organizationIds, long[] roleIds, long[] userGroupIds, ServiceContext serviceContext) throws PortalException { Company company = CompanyLocalServiceUtil.getCompany(companyId); // Check if user has an according right assigned with add user permission; Either he owns the right itself, by his roles or by his user roles User creator = this.getGuestOrUser(); long[] userIds = new long[] { creatorUserId }; // Adding user must be member of everything he adds ServicePermissionUtil.checkMembership(userIds, groupIds, organizationIds, roleIds, userGroupIds); if (groupIds != null && groupIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_TO_PAGE); angularGroupService.checkGroups(0, groupIds); }/*from w ww. j a v a2 s . com*/ if (organizationIds != null && organizationIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ORGANIZATION); angularOrganizationService.checkOrganizations(0, organizationIds); } if (roleIds != null && roleIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE); angularRoleService.checkRoles(0, roleIds); } if (userGroupIds != null && userGroupIds.length > 0) { PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER_GROUP); angularUserGroupService.checkUserGroupIds(0, userGroupIds); } boolean anonymousUser = ParamUtil.getBoolean(serviceContext, "anonymousUser"); long defaultUserId = userLocalService.getDefaultUserId(companyId); if (((creatorUserId != 0) && (creatorUserId != defaultUserId)) || (!company.isStrangers() && !anonymousUser)) { ServicePermissionUtil.checkAllPersonalPermissions(creator, ActionKeys.ADD_USER, companyId, getPermissionChecker(), User.class.getName()); } if ((creatorUserId == 0) || (creatorUserId == defaultUserId)) { if (!company.isStrangersWithMx() && company.hasCompanyMx(emailAddress)) { throw new UserEmailAddressException.MustNotUseCompanyMx(emailAddress); } } }