com.atlassian.user.User Java Examples
The following examples show how to use
com.atlassian.user.User.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditUserProfileWebPanel.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Override public String getHtml(@Nullable Map<String, Object> context) { final User currentUser = findCurrentUserOf(context); final User user = findUserOf(context); final Profile profile = findProfileFor(user); final List<Group> groups = asImmutableList(_groupProvider); final Locale locale = getLocaleFor(currentUser); final Map<String, Object> velocityContext = defaultVelocityContext(); velocityContext.putAll(context); velocityContext.put("currentUser", currentUser); velocityContext.put("user", user); velocityContext.put("profile", profile); velocityContext.put("groups", groups); velocityContext.put("elementRenderer", _elementRenderer); velocityContext.put("groupRenderer", _groupRenderer); velocityContext.put("localizationHelper", _localizationHelper); velocityContext.put("locale", locale); velocityContext.put("wikiStyleRenderer", _localeManager); velocityContext.put("rendererContext", new RenderContext()); final String templateName = getTemplateNameFor(currentUser); return getRenderedTemplate(templateName, velocityContext); }
Example #2
Source File: ElementRenderer.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull @HtmlSafe protected String renderXhtml(@Nonnull ElementModel model, @Nullable User currentUser, @Nonnull Profile profile, @Nullable String value, @Nonnull String mode, @Nullable Hints hints) { final Map<String, Object> context = defaultVelocityContext(); context.put("readOnly", !isRenderOfEditAllowedFor(model, currentUser, profile)); context.put("value", value); context.put("elementModel", model); context.put("currentUser", currentUser); context.put("profile", profile); context.put("wikiStyleRenderer", _wikiStyleRenderer); context.put("renderContext", new RenderContext()); context.put("pageContext", new PageContext()); context.put("nodeId", nodeIdFor(model, profile)); context.put("elementRenderer", this); context.put("hints", nonNullHints(hints)); context.put("enableUserLinkIfPossible", enableUserLinkIfPossible); context.put("fullNameTagName", fullNameTagName); final String templateName = getXhtmlTemplateNameFor(model, mode); return getRenderedTemplate(templateName, context); }
Example #3
Source File: ColumnRenderer.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull protected Map<String, Object> renderViewXhtmlOfElementModelsFor(@Nonnull Column column, @Nullable User currentUser, @Nonnull Profile profile) { final Map<String, Object> result = new LinkedHashMap<>(); for (final ColumnElementModel model : column) { final Format format = model.getFormat(); final Object content; if (format == Format.plain) { content = profile.getValue(model); } else if (format == Format.formatted) { content = _elementRenderer.renderViewXhtml(model, currentUser, profile); } else { throw new IllegalArgumentException("Could not handle format " + format + " of " + column + ":" + model + "."); } result.put(model.getId(), content); } return Collections.unmodifiableMap(result); }
Example #4
Source File: GroupSupport.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull @Override public ViewAccess getAccess() { return new ViewAccess() { @Nonnull @Override public Visibility checkView(@Nullable User forUser, @Nullable User target) { Visibility result = Visibility.forbidden; for (final ElementModel elementModel : GroupSupport.this) { final Visibility candidate = elementModel.getAccess().checkView(forUser, target); if (Visibility.isBetterVisibility(candidate, result)) { result = candidate; } } return result; } }; }
Example #5
Source File: UserProfileMacro.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nonnull protected String getTemplateNameFor(@Nonnull Map<String, Object> context, @Nullable User user) { final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get(); final String variant; if ((user == null || !user.equals(currentUser)) && !_permissionManager.hasPermission(currentUser, VIEW, TARGET_PEOPLE_DIRECTORY)) { variant = ".accessDenied"; } else { final Object username = context.get("username"); if (username == null || username.toString().isEmpty()) { variant = ".missingUsername"; } else if (context.get("user") == null) { variant = ".unknownUser"; } else { variant = ""; } } return TEMPLATE_NAME_PREFIX + variant + TEMPLATE_NAME_SUFFIX; }
Example #6
Source File: UserProfileMacro.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable protected View tryExtractViewFrom(@Nullable String elements, @Nullable User currentUser) { View result; if (elements == null) { result = _viewProvider.provideDefault(); } else { final Matcher matcher = EXTRACT_VIEW_NAME_PATTERN.matcher(elements); if (matcher.matches()) { result = _viewProvider.provideBy(matcher.group(1)); if (result == null) { result = _viewProvider.provideDefault(); } } else { result = null; } } return result != null && result.getAccess().checkView(currentUser, null).isViewAllowed() ? result : null; }
Example #7
Source File: AccessProvider.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
protected boolean isEqual(@Nullable User left, @Nullable User right) { final boolean result; if (left == null || right == null) { result = false; } else { result = left.getName().equals(right.getName()); } return result; }
Example #8
Source File: ExtendedPeopleDirectoryAction.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable protected View evaluateViewFor(@Nullable View view, @Nullable Report report, @Nullable User forUser) { final View result; if (view != null) { final View defaultView = getDefaultViewFor(report, forUser); if (defaultView != view) { result = view; } else { result = null; } } else { result = null; } return result; }
Example #9
Source File: EditUserProfileWebPanel.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable protected User findUserOf(@Nullable Map<String, Object> context) { final Object plain = context != null ? context.get("action") : null; final User result; if (plain instanceof UserAware) { result = ((UserAware)plain).getUser(); } else if (plain instanceof AbstractUsersAction) { result = ((AbstractUsersAction) plain).getUser(); } else { result = null; } return result; }
Example #10
Source File: ViewMyUserProfileWebPanel.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String getHtml(@Nullable Map<String, Object> context) { final Map<String, Object> velocityContext = defaultVelocityContext(); velocityContext.putAll(context); if (context != null) { final Object user = context.get("user"); if (user instanceof User) { velocityContext.put("username", ((Principal) user).getName()); } } velocityContext.put("helper", new GlobalHelper()); return getRenderedTemplate(TEMPLATE_NAME, velocityContext); }
Example #11
Source File: UserProfileMacro.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Override public String execute(@Nonnull Map<String, String> parameters, @Nullable String body, @Nonnull ConversionContext conversionContext) throws MacroExecutionException { final User currentUser = AuthenticatedUserThreadLocal.get(); final User user = findUserFor(parameters); final Profile profile = findProfileFor(user); final Set<String> allowedElementIds = getAllowedElementIdsBy(parameters, currentUser); final List<Group> groups = _viewProvider.createGroupsFor(allowedElementIds); final Locale locale = getLocaleFor(currentUser); final Map<String, Object> context = defaultVelocityContext(); context.putAll(parameters); context.put("conversionContext", conversionContext); context.put("currentUser", currentUser); context.put("user", user); context.put("profile", profile); context.put("groups", groups); context.put("elementRenderer", _elementRenderer); context.put("groupRenderer", _groupRenderer); context.put("localizationHelper", _localizationHelper); context.put("locale", locale); context.put("allowedElementIds", allowedElementIds); context.put("border", getValueFor(parameters, Border.visible, Border.visible, Border.hidden)); context.put("avatar", getValueFor(parameters, Avatar.visible, Avatar.visible, Avatar.hidden)); context.put("groupLabels", getValueFor(parameters, GroupLabels.visible, GroupLabels.visible, GroupLabels.hidden)); context.put("labels", getValueFor(parameters, Labels.visible, Labels.visible, Labels.hidden)); context.put("hints", getHintsFor(parameters)); context.put("wikiStyleRenderer", _localeManager); context.put("rendererContext", conversionContext.getPageContext()); final String templateName = getTemplateNameFor(context, user); return getRenderedTemplate(templateName, context); }
Example #12
Source File: UserProfileMacro.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull protected Set<String> getAllowedElementIdsBy(@Nullable String elements, @Nullable User currentUser) { final View view = tryExtractViewFrom(elements, currentUser); final Set<String> result = new LinkedHashSet<>(); if (view != null) { result.addAll(view.getElementIds()); } else { addAll(result, split(elements, ",", false, true)); } return result; }
Example #13
Source File: AttachmentUtil.java From onlyoffice-confluence with GNU Affero General Public License v3.0 | 5 votes |
public static boolean checkAccess(Long attachmentId, User user, boolean forEdit) { if (user == null) { return false; } AttachmentManager attachmentManager = (AttachmentManager) ContainerManager.getComponent("attachmentManager"); Attachment attachment = attachmentManager.getAttachment(attachmentId); return checkAccess(attachment, user, forEdit); }
Example #14
Source File: AccessProvider.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull protected Set<String> getGroupMembershipsOf(@Nonnull User user) { final Set<String> result = new HashSet<>(); try { for (final com.atlassian.user.Group group : _groupManager.getGroups(user)) { result.add(group.getName()); } } catch (final EntityException e) { throw new RuntimeException("Could not determinate the groups of " + user + ".", e); } return result; }
Example #15
Source File: ProfileResource.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull protected Iterable<Group> createGroupsFor(@Nullable User currentUser, @Nonnull Profile profile, @Nullable Locale locale) { final List<Group> result = new ArrayList<>(); for (final org.echocat.adam.profile.Group group : _groupProvider) { if (_groupRenderer.isRenderOfViewAllowedFor(group, currentUser, profile)) { final String id = group.getId(); final String label = _localizationHelper.getTitleFor(group, locale); result.add(new Group(id, label, createElementsFor(group, currentUser, profile, locale))); } } return result; }
Example #16
Source File: ReportProvider.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull @Override public ViewAccess getAccess() { return new ViewAccess() { @Nonnull @Override public Visibility checkView(@Nullable User forUser, @Nullable User target) { return forUser != null ? Visibility.allowed : Visibility.forbidden; } }; }
Example #17
Source File: ColumnRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @HtmlSafe public String renderViewXhtml(@Nonnull Column column, @Nullable User currentUser, @Nonnull Profile profile, @Nullable Map<String, Object> properties) { final Template template = column.getTemplate(); final String result; final Map<String, Object> elementModelValues = renderViewXhtmlOfElementModelsFor(column, currentUser, profile); if (template != null) { final TemplateFormat format = template.getFormat(); if (format == velocity) { final Map<String, Object> context = defaultVelocityContext(); context.putAll(elementModelValues); context.put("column", column); context.put("profile", profile); context.put("newLine", "\n"); if (properties != null) { context.putAll(properties); } result = getRenderedContent(template.getSource(), context); } else if (format == plain) { result = template.getSource(); } else { throw new UnsupportedOperationException("Could not handle template: " + template); } } else { final StringBuilder sb = new StringBuilder(); for (final Object value : elementModelValues.values()) { if (value != null) { if (sb.length() > 0) { sb.append(" "); } sb.append(value); } } result = sb.toString(); } return result; }
Example #18
Source File: ColumnRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
public boolean isRenderOfViewAllowedFor(@Nonnull Column column, @Nullable User currentUser, @Nonnull Profile profile) { boolean result = true; for (final ColumnElementModel model : column) { if (!_elementRenderer.isRenderOfViewAllowedFor(model, currentUser, profile)) { result = false; break; } } return result; }
Example #19
Source File: ColumnSupport.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull @Override public Visibility checkView(@Nullable User forUser, @Nullable User target) { Visibility result = Visibility.forbidden; boolean thereAreAnyElement = false; for (final ColumnElementModel elementModel : ColumnSupport.this) { thereAreAnyElement = true; final Visibility candidate = elementModel.getAccess().checkView(forUser, target); if (isBetterVisibility(candidate, result)) { result = candidate; } } return thereAreAnyElement ? result : allowed; }
Example #20
Source File: ScheduledMetricEvaluatorImpl.java From prom-confluence-exporter with BSD 2-Clause "Simplified" License | 5 votes |
private void calculateSessions() { int oneHourAgoActiveUserCount = 0; int todayActiveUserCount = 0; try { for (User user : userAccessor.getUsers()) { LoginInfo loginInfo = loginManager.getLoginInfo(user); if (loginInfo == null) { continue; } Date lastSuccessfulLoginDate = loginInfo.getLastSuccessfulLoginDate(); if (lastSuccessfulLoginDate == null) { continue; } long lastSuccessfulLoginTs = lastSuccessfulLoginDate.getTime(); long oneHourAgo = System.currentTimeMillis() - 3600 * 1000; long today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH).getTime(); if (lastSuccessfulLoginTs >= oneHourAgo) { oneHourAgoActiveUserCount++; } if (lastSuccessfulLoginTs >= today) { todayActiveUserCount++; } } } catch (Exception ex) { log.error("Error calculate user sessions", ex); } totalOneHourAgoActiveUsers.set(oneHourAgoActiveUserCount); totalTodayActiveUsers.set(todayActiveUserCount); }
Example #21
Source File: AttachmentUtil.java From onlyoffice-confluence with GNU Affero General Public License v3.0 | 5 votes |
public static boolean checkAccess(Attachment attachment, User user, boolean forEdit) { if (user == null) { return false; } PermissionManager permissionManager = (PermissionManager) ContainerManager.getComponent("permissionManager"); Permission permission = Permission.VIEW; if (forEdit) { permission = Permission.EDIT; } boolean access = permissionManager.hasPermission(user, permission, attachment); return access; }
Example #22
Source File: GroupRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
public boolean isRenderOfViewAllowedFor(@Nonnull Group group, @Nullable User currentUser, @Nonnull Profile profile) { boolean result = false; for (final ElementModel model : group) { if (_elementRenderer.isRenderOfViewAllowedFor(model, currentUser, profile)) { result = true; break; } } return result; }
Example #23
Source File: LivingDocConfluenceManager.java From livingdoc-confluence with GNU General Public License v3.0 | 5 votes |
public User getRemoteUser() { HttpServletRequest request = ServletActionContext.getRequest(); if (request != null) { String remoteUserName = request.getRemoteUser(); if (remoteUserName != null) { return getUserAccessor().getUserByName(remoteUserName); } } return AuthenticatedUserThreadLocal.get(); }
Example #24
Source File: GroupRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
public boolean isRenderOfEditAllowedFor(@Nonnull Group group, @Nullable User currentUser, @Nonnull Profile profile) { boolean result = false; for (final ElementModel model : group) { if (model.getAccess().checkEdit(currentUser, profile).isEditAllowed()) { result = true; break; } } return result; }
Example #25
Source File: ElementRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
public boolean isRenderOfViewAllowedFor(@Nonnull ElementModel model, @Nullable User currentUser, @Nonnull Profile profile) { final boolean result; if (model.getAccess().checkView(currentUser, profile).isViewAllowed()) { if (!isEmpty(profile.getValue(model))) { result = !PERSONAL_INFORMATION_ELEMENT_ID.equals(model.getId()); } else { result = false; } } else { result = false; } return result; }
Example #26
Source File: ElementRenderer.java From adam with GNU Lesser General Public License v3.0 | 5 votes |
public boolean isRenderOfEditAllowedFor(@Nonnull ElementModel model, @Nullable User currentUser, @Nonnull Profile profile) { final boolean result; if (model.getAccess().checkEdit(currentUser, profile).isEditAllowed() && model.getTemplate() == null) { final String id = model.getId(); if (FULL_NAME_ELEMENT_ID.equals(id) || ElementModel.EMAIL_ELEMENT_ID.equals(id)) { result = !_settingsManager.getGlobalSettings().isExternalUserManagement() && !_userAccessor.isReadOnly(profile); } else { result = true; } } else { result = false; } return result; }
Example #27
Source File: AccessProvider.java From adam with GNU Lesser General Public License v3.0 | 4 votes |
@Nonnull @Override public Visibility checkView(@Nonnull User forUser, @Nullable User target) { return Visibility.allowed; }
Example #28
Source File: UserProfileMacro.java From adam with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable protected Profile findProfileFor(@Nullable User user) { return user != null ? _profileProvider.provideFor(user) : null; }
Example #29
Source File: AccessProvider.java From adam with GNU Lesser General Public License v3.0 | 4 votes |
@Nonnull @Override public Editeditability checkEdit(@Nonnull User forUser, @Nullable User target) { return Editeditability.allowed; }
Example #30
Source File: ElementModelProvider.java From adam with GNU Lesser General Public License v3.0 | 4 votes |
@Nonnull @Override public Editeditability checkEdit(@Nonnull User forUser, @Nullable User target) { return Editeditability.allowed; }