Global Rights Management
All rights that you define in your project are managed in Project Management > Business Objects in the AuthorizationResources.java class. This class is automatically generated when you link a UI component to a user right, for the first time, e.g. an XdevButton Save with the CustomerSave right.
package com.company.example.business;
import com.xdev.security.authorization.Resource;
import com.xdev.security.authorization.ResourceEnum;
import com.xdev.security.authorization.ui.Authorization;
/**
* Central collection of all authorization resources used in the project.
*/
public enum AuthorizationResources implements ResourceEnum<AuthorizationResources> {
CUSTOMERSAVE("CustomerSave")
;
/**
* Helper method to export all resource names.
* <p>
* Right click and select 'Run As' - 'Java Application'
* </p>
*/
public static void main(String[] args) {
for (AuthorizationResources value : AuthorizationResources.values()) {
System.out.println(value.name);
}
}
/////////////////////////////
// implementation details //
///////////////////////////
private final String name;
private Resource resource;
private AuthorizationResources(final String name) {
this.name = name;
}
@Override
public String resourceName() {
return this.name;
}
@Override
public Resource resource() {
if (this.resource == null) {
this.resource = Authorization.resource(this.name);
}
return this.resource;
}
}Add rights
You can add further rights when connecting a UI component to a right by using the wizard or by simply adding other rights to this class.
package com.company.example.business;
import com.xdev.security.authorization.Resource;
import com.xdev.security.authorization.ResourceEnum;
import com.xdev.security.authorization.ui.Authorization;
/**
* Central collection of all authorization resources used in the project.
*/
public enum AuthorizationResources implements ResourceEnum<AuthorizationResources> {
CUSTOMERSAVE("CustomerSave"),
CUSTOMERNEW("CustomerNew"),
CUSTOMERUPDATE("CustomerUpdate"),
CUSTOMERDELET("CustomerDelete"),
PRODUCTSAVE("ProductSave"),
PRODUCTNEW("ProductNew"),
PRODUCTUPDATE("ProductUpdate"),
PRODUCTDELETE("ProductDelete")
;Show all rights
The class AuthorizationResources contains a Main method that can start. By default, all rights are printed to the console so that you can use them further, e.g. save them in your database.
Right-click the code of the class AuthorizationResources.
Select Run As > Java Application in the following context menu.
Note:
Generate Insert Statements - You can generate either insert statements for your database and other formats of your choice.