UI-Komponenten lassen sich über die Property Rights mit beliebig vielen Benutzerrechten verknüpfen. Dazu wird jeweils ein bestimmtes Recht, z.B. ProductEdit, mit einem von 3 möglichen Zuständen (Strategy) einer UI-Komponente verknüpft:
...
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:
- ENABLED - The UI component is enabled.
- VISIBLE - The UI component is visible.
- READ_ONLY - Die UI-Komponente kann Daten lediglich anzeigen. Eingaben oder Änderungen sind nicht möglich.
Dadurch werden insgesamt 6 verschiedene Zustände abgedeckt:
...
- The UI component can only display data. Entries or modifications are not possible.
As such, a total of six different states is covered:
- None - Benutzer hat keine Berechtigung.
- Create - Benutzer darf einen neuen Datensatz anlegen.
- Read - Benutzer darf einen Datensatz lesen.
- Edit - Benutzer darf einen Datensatz ändern.
- Delete - Benutzer darf einen Datensatz löschen.
die für nahezu jede Eingabemaske sowie für die Views selbst benötigt werden, z.B. für das Entity Product:
- ProductNone - Benutzer auf keinen Zugriff auf den Produkt-Datensatz.
- ProductCreate - Benutzer darf einen neuen Produkt-Datensatz anlegen.
- ProductRead - Benutzer darf einen Produkt-Datensatz lesen.
- ProductEdit - Benutzer darf einen Produkt-Datensatz ändern.
- ProductDelete - Benutzer darf einen Produkt-Datensatz löschen.
Dadurch können sich für ene größere Anwendung sehr viele verschiedene Rechte ergeben.
Hinweis:
...
- Klicken Sie eine UI-Komponente an, die Sie verrechten möchten, z.B. einen Save Button.
- Klicken Sie bei Properties > Authorization > Rights auf ....
- Klicken Sie im folgenden Dialog Rights auf + New, um ein neues Recht hinzuzufügen.
- Geben Sie bei Right die Bezeichnung für ein neues Recht ein, z.B. CustomerCreate, oder wählen Sie ein bereits existierendes Recht aus.
- Wählen Sie bei Strategy einen für diese UI-Komponente möglichen Zustand aus, z.B. ENABLED.
- Klicken Sie auf OK.
Ergebnis:
...
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:
- None: User has no access rights.
- Create: User can create a new record.
- Read: User can read a record.
- Edit: User can edit a record.
- Delete: User can delete a record.
They are needed for almost any input mask and the views themselves, e.g. for the Product entity:
- Product None: User cannot access the product data.
- Product Create: User can create a new product record.
- Product Read: User can read a product record.
- ProductEdit: User can change a product record.
- ProductDelete: User can delete a product record.
Thus, you can have a large number of different rights for bigger applications.
Note:
- To assign rights to the UI component, you need data sources in your project as a prerequisite for authentication and authorization .
- A UI component can also be linked to multiple rights.
- Click a UI component you want to link to a right, e.g. a Save button.
- In Properties > Authorization > Rights click on ...
- Click Rights > + New in the following dialog, to create a new right.
- In Right, enter the name for a new right, e.g. CustomerCreate, or choose an already existing right.
- Select a potential state for this UI component in Strategy, e.g. ENABLED.
- Click on OK
Result:
AuthorizationResources - This class is added in Projekt Management > Business Objects to allow a global management of rights.
Code Block language java theme Confluence 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 - Komponente - Die UI-Komponente wird mit dem Recht verknüpftThe UI component is linked to a right.
Code Block language java theme Confluence /* * 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);
Benutzerrechte global verwaltenGlobal Management of User Rights