com.atlassian.confluence.user.ConfluenceUser Java Examples

The following examples show how to use com.atlassian.confluence.user.ConfluenceUser. 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: ExtendedPeopleDirectoryAction.java    From adam with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
protected List<Profile> searchFor(@Nullable Report report, @Nullable Iterable<Column> columns) {
    final List<Profile> profiles = new ArrayList<>();
    if (report != null && columns != null) {
        final SearchResults results = performSearch(report, makeSearchQuery(columns), makeSearchFilterFor(report));
        final List<Searchable> resultObjects = _searchManager.convertToEntities(results, EntityVersionPolicy.LATEST_VERSION);
        final ManualTotalPaginationSupport<Searchable> paginationSupport = (ManualTotalPaginationSupport<Searchable>) getPaginationSupport();
        paginationSupport.setPageSize(report.getResultsPerPage());
        paginationSupport.setStartIndex(getStartIndex());
        paginationSupport.setTotal(results.getUnfilteredResultsCount());
        paginationSupport.setItems(resultObjects);
        for (final Searchable resultObject : resultObjects) {
            final PersonalInformation personalInformation = (PersonalInformation) resultObject;
            final ConfluenceUser user = personalInformation.getUser();
            final Profile profile = profileProvider().provideFor(user);
            profiles.add(profile);
        }
    }
    if (isShowingAllPeople()) {
        determineBlankExperience();
    }
    return profiles;
}
 
Example #4
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 #5
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 #6
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 #7
Source File: ConfluenceLivingDocServiceImpl.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
private void checkPermissions(Space space, ConfluenceUser user) throws NotPermittedException {
    List<String> permTypes = new ArrayList<>();
    permTypes.add(SpacePermission.VIEWSPACE_PERMISSION);
    if (!ldUtil.getSpacePermissionManager().hasPermissionForSpace(user, permTypes, space)) {
        throw new NotPermittedException();
    }
}
 
Example #8
Source File: ConfluenceLivingDocServiceImpl.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
private ConfluenceUser login(String username, String password) throws EntityException {

        if (StringUtils.isNotEmpty(username) && ldUtil.isCredentialsValid(username, password)) {
            return (ConfluenceUser) ldUtil.getConfluenceUserManager().getUser(username);
        }
        return null;

    }
 
Example #9
Source File: ExtendedEditUserAction.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String doEdit() throws Exception {
    final String result = super.doEdit();
    final ConfluenceUser user = getUser();
    final Profile profile = user != null ? profileProvider().provideFor(user) : null;
    if (profile != null && "success".equals(result)) {
        updateFields(profile);
        profile.reIndex();
    }
    return result;
}
 
Example #10
Source File: ExtendedEditMyProfileAction.java    From adam with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String doEdit() throws Exception {
    final String result = super.doEdit();
    final ConfluenceUser user = getUser();
    final Profile profile = user != null ? profileProvider().provideFor(user) : null;
    if (profile != null && "success".equals(result)) {
        updateFields(profile);
        profile.reIndex();
    }
    return result;
}
 
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: OnlyOfficeEditorServlet.java    From onlyoffice-confluence with GNU Affero General Public License v3.0 4 votes vote down vote up
private String getTemplate(String apiUrl, String callbackUrl, String fileUrl, String key, String fileName,
        ConfluenceUser user, String errorMessage) throws UnsupportedEncodingException {
    Map<String, Object> defaults = MacroUtils.defaultVelocityContext();
    Map<String, String> config = new HashMap<String, String>();

    String docTitle = fileName.trim();
    String docExt = docTitle.substring(docTitle.lastIndexOf(".") + 1).trim().toLowerCase();

    config.put("docserviceApiUrl", apiUrl + properties.getProperty("files.docservice.url.api"));
    config.put("errorMessage", errorMessage);
    config.put("docTitle", docTitle);

    JSONObject responseJson = new JSONObject();
    JSONObject documentObject = new JSONObject();
    JSONObject editorConfigObject = new JSONObject();
    JSONObject userObject = new JSONObject();
    JSONObject permObject = new JSONObject();

    try {
        responseJson.put("type", "desktop");
        responseJson.put("width", "100%");
        responseJson.put("height", "100%");
        responseJson.put("documentType", getDocType(docExt));

        responseJson.put("document", documentObject);
        documentObject.put("title", docTitle);
        documentObject.put("url", fileUrl);
        documentObject.put("fileType", docExt);
        documentObject.put("key", key);
        documentObject.put("permissions", permObject);
        permObject.put("edit", callbackUrl != null && !callbackUrl.isEmpty());

        responseJson.put("editorConfig", editorConfigObject);
        editorConfigObject.put("lang", localeManager.getLocale(user).toLanguageTag());
        editorConfigObject.put("mode", "edit");
        editorConfigObject.put("callbackUrl", callbackUrl);

        if (user != null) {
            editorConfigObject.put("user", userObject);
            userObject.put("id", user.getName());
            userObject.put("name", user.getFullName());
        }

        if (jwtManager.jwtEnabled()) {
            responseJson.put("token", jwtManager.createToken(responseJson));
        }

        // AsHtml at the end disables automatic html encoding
        config.put("jsonAsHtml", responseJson.toString());
    } catch (Exception ex) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        ex.printStackTrace(pw);
        String error = ex.toString() + "\n" + sw.toString();
        log.error(error);
    }

    defaults.putAll(config);
    return VelocityUtils.getRenderedTemplate("templates/editor.vm", defaults);
}