Java Code Examples for com.atlassian.confluence.user.AuthenticatedUserThreadLocal#get()

The following examples show how to use com.atlassian.confluence.user.AuthenticatedUserThreadLocal#get() . 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: 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 6
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 7
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 8
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();
}