com.atlassian.confluence.user.AuthenticatedUserThreadLocal Java Examples

The following examples show how to use com.atlassian.confluence.user.AuthenticatedUserThreadLocal. 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: IsOfficeFileAttachment.java    From onlyoffice-confluence with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean shouldDisplay(Map<String, Object> context) {
    Attachment attachment = (Attachment) context.get("attachment");
    if (attachment == null) {
        return false;
    }
    if (!isXExtension(attachment.getFileExtension())) {
        return false;
    }
    if (attachment.getFileSize() > DocumentManager.GetMaxFileSize()) {
        return false;
    }

    ConfluenceUser user = AuthenticatedUserThreadLocal.get();
    boolean accessEdit = AttachmentUtil.checkAccess(attachment, user, true);
    boolean accessView = AttachmentUtil.checkAccess(attachment, user, false);
    if (!forEdit && (!accessView || accessEdit)) {
        return false;
    }
    if (forEdit && !accessEdit) {
        return false;
    }

    return true;
}
 
Example #2
Source File: IsOfficeFileConvertAttachment.java    From onlyoffice-confluence with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean shouldDisplay(Map<String, Object> context) {
    Attachment attachment = (Attachment) context.get("attachment");
    if (attachment == null) {
        return false;
    }
    String ext = attachment.getFileExtension();
    if (attachment.getFileSize() > DocumentManager.GetMaxFileSize()) {
        return false;
    }

    ConfluenceUser user = AuthenticatedUserThreadLocal.get();
    boolean accessEdit = AttachmentUtil.checkAccess(attachment, user, true);

    if (!accessEdit || !ConvertManager.isConvertable(ext)) {
        return false;
    }

    return true;
}
 
Example #3
Source File: UserProfileMacro.java    From adam with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: ProfileResource.java    From adam with GNU Lesser General Public License v3.0 6 votes vote down vote up
@GET
@Path("/{username}")
@AnonymousAllowed
@Produces({"application/json"})
public Response getProfile(@PathParam("username") String username) {
    final Response response;
    final ConfluenceUser user = _userAccessor.getUserByName(username);
    final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
    final Locale locale = currentUser != null ? _localeManager.getLocale(currentUser) : null;
    if (user == null || !_userHelper.isProfileViewPermitted()) {
        response = getNotFoundResponse();
    } else {
        final UserDto original = _userDtoFactory.getUserDto(user);
        final ExtendedUserDto dto = new ExtendedUserDto(original, createGroupsFor(currentUser, user, locale));
        response = ok(dto).build();
    }
    return response;
}
 
Example #5
Source File: MetricListener.java    From prom-confluence-exporter with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@EventListener
public void onSpaceRemoveEvent(SpaceRemoveEvent spaceRemoveEvent) {
    String username = AuthenticatedUserThreadLocal.getUsername();
    if (username == null) {
        username = "";
    }
    metricCollector.spaceDeleteCounter(username);
}
 
Example #6
Source File: MetricListener.java    From prom-confluence-exporter with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@EventListener
public void onSpaceCreateEvent(SpaceCreateEvent spaceCreateEvent) {
    String username = AuthenticatedUserThreadLocal.getUsername();
    if (username == null) {
        username = "";
    }
    metricCollector.spaceCreateCounter(username);
}
 
Example #7
Source File: AttachmentUtil.java    From onlyoffice-confluence with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void saveAttachment(Long attachmentId, InputStream attachmentData, int size, ConfluenceUser user)
        throws IOException, IllegalArgumentException {
    AttachmentManager attachmentManager = (AttachmentManager) ContainerManager.getComponent("attachmentManager");
    Attachment attachment = attachmentManager.getAttachment(attachmentId);

    Attachment oldAttachment = attachment.copy();
    attachment.setFileSize(size);

    AuthenticatedUserThreadLocal.set(user);

    attachmentManager.saveAttachment(attachment, oldAttachment, attachmentData);
}
 
Example #8
Source File: LivingDocConfluenceManager.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
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 #9
Source File: ExtendedEditUserAction.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateFields(@Nonnull Profile profile) {
    for (final Group group : profileModelProvider().get()) {
        for (final ElementModel elementModel : group) {
            final String id = elementModel.getId();
            if (id != null && !id.equals(FULL_NAME_ELEMENT_ID) && !id.equals(EMAIL_ELEMENT_ID) && !id.equals(USER_NAME_ELEMENT_ID)) {
                final String[] plainValues = _parameters.get(id);
                final String plainValue = plainValues != null && plainValues.length > 0 ? join(plainValues, ' ') : null;
                if (plainValue != null && elementModel.getAccess().checkEdit(AuthenticatedUserThreadLocal.get(), profile).isEditAllowed()) {
                    profile.setValue(elementModel, plainValue);
                }
            }
        }
    }
}
 
Example #10
Source File: UserProfileMacro.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: ViewResource.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@GET
@Path("/")
@AnonymousAllowed
@Produces({"application/json"})
public Response getViews() {
    final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
    final Locale locale = currentUser != null ? _localeManager.getLocale(currentUser) : null;
    final List<View> views = new ArrayList<>();
    for (final org.echocat.adam.view.View view : _viewProvider) {
        views.add(new View(_localizationHelper, view, locale, currentUser));
    }
    return ok(views).build();
}
 
Example #12
Source File: ModelResource.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@GET
@Path("/profile")
@AnonymousAllowed
@Produces({"application/json"})
public Response getProfile() {
    final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
    final Locale locale = currentUser != null ? _localeManager.getLocale(currentUser) : null;
    return ok(new ProfileModel(_localizationHelper, _groupProvider, locale, currentUser)).build();
}
 
Example #13
Source File: ConfluenceLivingDocServiceImpl.java    From livingdoc-confluence with GNU General Public License v3.0 4 votes vote down vote up
private void logout() {
    AuthenticatedUserThreadLocal.set(null);
}