RichText rendering issue for anonymous users

200 views Asked by At

I am trying to render richtext content from WCM using wcm API. I have jsp to do so. It renders properly for all user group except anonymous. When I view rendered content I see broken image inside richtext. When I log in and view the rendered content, image is displayed.

here is my code:

Workspace ws = WCM_API.getRepository().getSystemWorkspace();
ws.login();
DocumentLibrary lib = ws.getDocumentLibrary("Portal Site");
String s1 = "";
String s2 = "";


if (lib!=null) {
    DocumentIdIterator<Document> it = ws.findByName(DocumentTypes.Content,"kino");

    if (it.hasNext()) {
        DocumentId<Document> docid = it.next();

        Content doc = (Content) ws.getById(docid);
        s1 = "Title: " + doc.getTitle() + "\n";

        RichTextComponent c = (RichTextComponent) doc.getComponent("Body");

        s2 = "Text: " + c.getRichText();
    }
} 
out.println(s1);
out.println(s2);

s2 is outputs richtext with image for authorized users. When I logout and view s2 output: text is displayed but image is broken

2

There are 2 answers

0
Gabit Kemelov On BEST ANSWER

Solution has nothing to do with access level in my case! I checked url of the content and in both cases it consisted /myconnect word (example: http:ip_address:port/wps/wcm/myconnect/...) I found out that myconnect is for authorized user and connect is for anon users. (example: http:ip_address:port/wps/wcm/connect/...) Just by replacing myconnect with connect in the url to the wcm content I managed to solve the problem:

5
Georgy Gobozov On

Please make sure that you have anonymous access granted to all your RichText component and parent site areas at user level. And add this call on workspace object

workspace.useUserAccess(true);