3.1 Security API: Configuring the File Security Provider
If you are using the built-in security provider (see Configuring the Default Security Provider) and find it cumbersome to manually setup users, groups, roles, and permissions, you can programmatically configure the security provider using the security API. For LDAP and custom security implementations, use the interface provided by the external security data store to add and remove users, groups, and roles. The security provider should only pull from, and never push to, that store.
The code snippet below performs the following tasks:
• Create a new group of users called “Accounts”.
• Add a new user called “brian” to the “Accounts” group.
• Give the “Accounts” group read permissions on a folder called “Audit Reports”.
import inetsoft.sree.security.*;
import inetsoft.sree.*;
...
System.setProperty("sree.home", "{Absolute Path to your sree home location}");
SecurityEngine sEngine = SecurityEngine.getSecurity();
FileSecurityProvider fsProvider = (FileSecurityProvider)sEngine.getSecurityProvider();
// Get a handle to the authentication module
FileAuthenticationProvider fap = (FileAuthenticationProvider)fsProvider.getAuthenticationProvider();
// Add the new group called 'Accounts'
fap.addGroup(new FSGroup("Accounts"));
// Add a user called 'brian' and assign him to the 'Accounts' group
FSUser user = new FSUser("brian");
user.setGroups(new String[] {"Accounts"});
fap.addUser(user);
// Give the Accounts group read permissions on a folder called 'Audit Reports'
// Get a handle to the authorization module
FileAuthorizationProvider fathp = (FileAuthorizationProvider)fsProvider.getAuthorizationProvider();
// Create a permission object
Permission folderPermission = new Permission();
folderPermission.setReadGroups(new String[] {"Accounts"});
// Set permissions on the folder
fathp.setPermission("Audit Reports", folderPermission);
| << 3 Java API Utility Applications | © 1996-2013 InetSoft Technology Corporation (v11.4) | 3.2 Creating a Custom Report List >> |