Information
This explains basic usage of the Sakai FunctionManager Service. This service is used to register new Authz (permission) groups.
- Trunk javadocs:
- Trunk source location: https://source.sakaiproject.org/svn/authz/trunk/
Accessing the FunctionManager
- You can use Spring Framework to inject the service or use the cover
- Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
- Add the FunctionManager bean to the bean for YourAppClass
<bean id="org.sakaiproject.yourapp.logic.YourAppClass" class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl"> <property name="functionManager" ref="org.sakaiproject.authz.api.FunctionManager" /> </bean>
- Add a variable and setter to YourAppClass to use the service in like so:
private FunctionManager functionManager; public void setFunctionManager(FunctionManager functionManager) { this.functionManager = functionManager; }
- Add the FunctionManager bean to the bean for YourAppClass
- Using the Component Manager to get the service
- Note: This is not the recommended method, you should be using Spring to inject the service
- Use the CM cover to get the service
import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.authz.api.FunctionManager; ... private FunctionManager functionManager; ... functionManager = (FunctionManager) ComponentManager.get(FunctionManager.class);
Registering a new permission with the Sakai security system
- Note: This will cause the permission to appear in the list of perms in Realms
- Create a static final String to store the name of the permission
- Note: This is partially so you can access this string from elsewhere in your app (if needed)
public final static String TOOL_PERM_NAME = "toolname.perm.name";
- Note: This is partially so you can access this string from elsewhere in your app (if needed)
- Use the FunctionManager to register the permission with the security system when your class initializes
public void init() { functionManager.registerFunction(TOOL_PERM_NAME); }
- Note: Recommend that you place this in the init function of a business logic class (or service)