Manage rights globally

All the rights you define in your project are managed in Project Management > main-java in the class AuthorizationResources.java. This class is automatically generated the first time you create a Associate a UI component with a user right, e.g. a Button Save with the CustomerSave right.

package com.company.demoproj;

import java.util.MissingResourceException;

import com.rapidclipse.framework.security.authorization.Resource;
import com.rapidclipse.framework.security.authorization.ResourceEnum;
import com.rapidclipse.framework.server.resources.Caption;
import com.rapidclipse.framework.server.resources.StringResourceUtils;
import com.rapidclipse.framework.server.security.authorization.Authorization;


/**
 * Central collection of all authorization resources used in the project.
 */
@Caption("{%description}")
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 String       description;

    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;
    }

    public String getDescription()
    {
        if(this.description == null)
        {
            try
            {
                this.description = StringResourceUtils.getResourceString(name(), this);
            }
            catch(final MissingResourceException e)
            {
                this.description = this.name;
            }
        }

        return this.description;
    }
}

Add rights

You can add further rights each time you link a UI component to a right via a wizard or centrally in this class by simply appending further rights.

package com.company.demoproj;

import java.util.MissingResourceException;

import com.rapidclipse.framework.security.authorization.Resource;
import com.rapidclipse.framework.security.authorization.ResourceEnum;
import com.rapidclipse.framework.server.resources.Caption;
import com.rapidclipse.framework.server.resources.StringResourceUtils;
import com.rapidclipse.framework.server.security.authorization.Authorization;


/**
 * Central collection of all authorization resources used in the project.
 */
@Caption("{%description}")
public enum AuthorizationResources implements ResourceEnum<AuthorizationResources>
{
    CUSTOMERSAVE("CustomerSave"),
    CUSTOMERNEW("CustomerNew"),
    CUSTOMERUPDATE("CustomerUpdate"),
    CUSTOMERDELET("CustomerDelete"),
    PRODUCTSAVE("ProductSave"),
    PRODUCTNEW("ProductNew"),
    PRODUCTUPDATE("ProductUpdate"),
    PRODUCTDELETE("ProductDelete")
    ;

Output of all rights

The AuthorizationResources class contains a Main method that you can start. This will output all permissions to the console by default, so you can process them further, e.g. store them in your database.

  1. Right-click in the code of the AuthorizationResources class.

  2. In the following context menu, select > Run As > Java Application.
    image not found

Notice:

  • Generate insert statements - you can also have insert statements generated for your database or any other format at the same time as the output.