Link UI Component to User Rights

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 - The UI component can only display data. Entries or modifications are not possible.

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:

  • 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.
  1. Click a UI component you want to link to a right, e.g. a  Save   button.
  2. In Properties > Authorization > Rights click on ...
  3. Click Rights > + New in the following dialog, to create a new right.
  4. In Right, enter the name for a new right, e.g. CustomerCreate, or choose an already existing right.
  5. Select a potential state for this UI component in  Strategy, e.g.  ENABLED.
  6. Click on OK
Result:
  • 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


XDEV Software Corp. - One Embarcadero Center, San Francisco, CA 94111, US
Copyright © 2015. XDEV Software Corp. All rights reserved.