All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapidclipse.framework.security.authorization.AuthorizationConfiguration Maven / Gradle / Ivy

There is a newer version: 14.0.0
Show newest version
/*
 * Copyright (C) 2013-2023 by XDEV Software, All Rights Reserved.
 *
 * This file is part of the RapidClipse Application Platform (RAP).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 *
 * Contributors:
 *     XDEV Software - initial API and implementation
 */
package com.rapidclipse.framework.security.authorization;

import static java.util.Objects.requireNonNull;

import java.util.Map;
import java.util.Set;


/**
 * Intermediate data structure that represents authorization definition
 * information in a general purpose, yet efficiently processable format.
 *
 * @author XDEV Software (TM)
 */
public interface AuthorizationConfiguration
{
	/**
	 * The child resource names (value) for every valid resource (keys). The key
	 * collection of the returned map also represents the complete set of valid
	 * resources.
	 *
	 * @return a table representing all valid resources and their defined child
	 *         resources.
	 */
	public Map> resourceResources();

	/**
	 * The parent role names (value) for every valid role (keys). The key
	 * collection of the returned map also represents the complete set of valid
	 * roles.
	 *
	 * @return a table representing all valid roles and their parent roles.
	 * @see #roleRoles()
	 */
	public Map> roleRoles();

	/**
	 * The explicitely defined permissions (value) for every valid role (keys).
	 * Every permission is represented by its name and its associated factor.
	 * The key collection of the returned map also represents the complete set
	 * of valid roles.
	 *
	 * @return a table representing all valid roles and their defined
	 *         permissions.
	 * @see #rolePermissions()
	 */
	public Map> rolePermissions();

	/**
	 * The role names (value) for every valid subject (keys). The key collection
	 * of the returned map also represents the complete set of valid subjects.
	 *
	 * @return a table representing all valid subjects and their defined roles.
	 */
	public Map> subjectRoles();

	/**
	 * Creates a new {@link AuthorizationConfiguration} instance from the passed
	 * parts.
	 *
	 * @param resourceResources
	 *            see {@link #resourceResources()}
	 * @param roleRoles
	 *            see {@link #roleRoles()}
	 * @param rolePermissions
	 *            see {@link #rolePermissions()}
	 * @param subjectRoles
	 *            see {@link #subjectRoles()}
	 * @return a new {@link AuthorizationConfiguration} instance
	 */
	public static AuthorizationConfiguration New(
		final Map> resourceResources,
		final Map> roleRoles,
		final Map> rolePermissions,
		final Map> subjectRoles)
	{
		return new Default(requireNonNull(resourceResources), requireNonNull(roleRoles),
			requireNonNull(rolePermissions), requireNonNull(subjectRoles));
	}

	/**
	 * A simple immutable {@link AuthorizationConfiguration} default
	 * implementation.
	 *
	 * @author XDEV Software (TM)
	 */
	public final class Default implements AuthorizationConfiguration
	{
		////////////////////////////////////////////////////////////////////////////
		// instance fields //
		////////////////////

		private final Map>          resourceResources;
		private final Map>          roleRoles;
		private final Map> rolePermissions;
		private final Map>          subjectRoles;

		////////////////////////////////////////////////////////////////////////////
		// constructors //
		/////////////////

		/**
		 * Implementation detail constructor that might change in the future.
		 */
		protected Default(
			final Map> resourceResources,
			final Map> roleRoles,
			final Map> rolePermissions,
			final Map> subjectRoles)
		{
			super();
			this.resourceResources = resourceResources;
			this.roleRoles         = roleRoles;
			this.rolePermissions   = rolePermissions;
			this.subjectRoles      = subjectRoles;
		}

		////////////////////////////////////////////////////////////////////////////
		// override methods //
		/////////////////////

		/**
		 * {@inheritDoc}
		 */
		@Override
		public final Map> resourceResources()
		{
			return this.resourceResources;
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public final Map> roleRoles()
		{
			return this.roleRoles;
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public final Map> rolePermissions()
		{
			return this.rolePermissions;
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public final Map> subjectRoles()
		{
			return this.subjectRoles;
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy