The property Rights allows you to connect your UI components to as many user rights as you require. To do this, a specific right; e.g., ProductEdit, is connected to one of three possible states of a UI component:
As such, a total of six different states is covered:
Right | Explanation | Cases | Strategy | Status | State |
---|---|---|---|---|---|
ProductEdit | User can save customer records. | Right available. | ENABLED | TRUE | UI component is enabled |
VISIBLE | TRUE | UI component is visible | |||
READ_ONLY | FALSE | UI component displays value. However, entering or editing values is not possible. | |||
Right is not available. | ENABLED | FALSE | UI component is disabled. | ||
VISIBLE | FALSE | UI component is not visible. | |||
READ_ONLY | TRUE | Entering or editing values is possible. |
As user rights depend on the use case; all rights must be defined separately. Common rights include:
They are needed for almost any input mask and the views themselves, e.g. for the Product entity:
Thus, you can have a large number of different rights for bigger applications.
AuthorizationResources - This class is added in Projekt Management > Business Objects to allow a global management of rights.
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> { CUSTOMERCREATE("CustomerCreate") ; /** * 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; } } |
UI Component - The UI component is linked to a right.
/* * WARNING: Do NOT edit!<br>The content of this method is always regenerated * by the UI designer. */ // <generated-code name="initUI"> private void initUI() { this.button = new XdevButton(); this.button.setCaption("Save"); Authorization.setSubjectEvaluatingComponentExtension(this.button, SubjectEvaluatingComponentExtension.Builder .New().add(AuthorizationResources.CUSTOMERSAVE.resource(), SubjectEvaluationStrategy.ENABLED).build()); Authorization.evaluateComponents(this); |
Global Management of User Rights