Customizing Surf Platform Root-Scoped API

北战南征 提交于 2020-01-02 10:06:32

问题


I want to customize Surf Platform Root-Scoped API specifically user object. That means add new property or method to user object to check the user is in certain group in header.inc.ftl [in share] like `<#if user.isAdmin>

  1. How can I implement this?
  2. Is Alfresco Root Scoped Objects can be used as Surf Platform Root-Scoped object?

I have no idea of customizing surf platform root object. Can anyone help me???


回答1:


Not quite sure what you are trying to accomplish, but the role security model is hardcoded in spring-surf/spring webscripts. There is guest, user and admin. If what you want is another analogous role you'll have to hack the spring-surf libaries, namely:

org/springframework/extensions/surf/mvc/PageView.java
org/springframework/extensions/webscripts/ScriptUser.java
org/springframework/extensions/webscripts/Description.java
org/springframework/extensions/webscripts/connector/User.java

This is what I had to do to implement user.isEmployee. This approach allows you to literally treat your new role just as the others.

you can use

<authentication>employee</authentication>

in page descriptors or

<item type="link" permission="employee" id="people">/people-finder</item>

on the navigation.

Just checking whether the user is in a certain group in a certain webscript is a whole diffrent story and does not provide the same functionality.

If what you want is the latter, you should make a call to

/alfresco/service/api/groups/{shortName}

miss and works through the response.

Update: The item permission attribute requires a little more tweaking. In header.get.js, propagate the new role to it gets processed properly in header.inc.ftl:

model.permissions =
{
    guest: user.isGuest,
    admin: user.isAdmin,
    employee : user.isEmployee
};



回答2:


you could try (in JavaScript I managed something like) this:

user = Application.getCurrentUser(context);
       String userName = user.getUserName();
       user.isAdmin() >>> result return true if user logining is admin

or in JSP:

#{NavigationBean.currentUser.admin == true}

Sorry, i noticed now you was talking about Surf Platform root objects, but the link you put there, is deprecated for Alfresco versions above 3.3. You still use something so old? If you manage to use JavaScript API's you could use "person" root object, with boolean isAdmin().



来源:https://stackoverflow.com/questions/12293331/customizing-surf-platform-root-scoped-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!