Entitlement.java revision 4d1d71cf6c0dd2b545d8adfbbae9b28a3afdecd4
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: Entitlement.java,v 1.7 2010/01/25 23:48:14 veiming Exp $
*
* Portions copyright 2010-2013 ForgeRock, Inc.
*/
/**
* This class encapsulates entitlement of a subject.
* <p>
* Example of how to use this class
* <pre>
* Set set = new HashSet();
* set.add("GET");
* Evaluator evaluator = new Evaluator(adminToken);
* boolean isAllowed = evaluator.hasEntitlement(subject,
* new Entitlement("http://www.sun.com/example", set),
* Collections.EMPTY_MAP);
* </pre>
* Or do a sub tree search like this.
* <pre>
* Evaluator evaluator = new Evaluator(adminToken);
* List<Entitlement> entitlements = evaluator.getEntitlements(
* subject, "http://www.sun.com", Collections.EMPTY_MAP, true);
* for (Entitlement e : entitlements) {
* String resource = e.getResourceNames();
* boolean isAllowed =((Boolean)e.getActionValue("GET")).booleanValue();
* ...
* }
* </pre>
*/
public class Entitlement {
private String applicationName =
private Application application;
/**
* Creates an entitlement object with default service name.
*/
public Entitlement() {
}
}
/**
* Creates an entitlement object.
*
* @param resourceNames Resource names.
* @param actionNames Set of action names.
*/
}
/**
* Creates an entitlement object.
*
* @param resourceName Resource name.
* @param actionNames Set of action names.
*/
}
/**
* Creates an entitlement object.
*
* @param applicationName Application name.
* @param resourceName Resource name.
* @param actionNames Set of action names.
*/
public Entitlement(
) {
}
/**
* Creates an entitlement object.
*
* @param resourceName Resource namess.
* @param actionValues Map of action name to set of values.
*/
public Entitlement(
) {
}
/**
* Creates an entitlement object.
*
* @param applicationName applicationName
* @param resourceName Resource namess.
* @param actionValues Map of action name to set of values.
*/
public Entitlement(
) {
}
/**
* Creates an entitlement object.
*
* @param applicationName Application name.
* @param resourceNames Resource names.
* @param actionValues Map of action name to set of values.
*/
public Entitlement(
) {
}
/**
* Sets the name of the entitlement
* @param name the name of the entitlement
*/
}
/**
* Returns the name of the entitlement
* @return the name of the entitlement
*/
return this.name;
}
/**
* Sets resource names.
*
* @param resourceNames Resource Names.
*/
this.resourceNames = resourceNames;
}
/**
* Returns resource names.
*
* @return resource names.
*/
return resourceNames;
}
/**
* Sets resource name.
*
* @param resourceName Resource Name.
*/
}
/**
* Returns resource name.
*
* @return resource names.
*/
public String getResourceName() {
return null;
}
}
/**
* Sets excluded resource names.
*
* @param excludedResourceNames excluded resource names.
*/
public void setExcludedResourceNames(
}
/**
* Returns excluded resource names.
*
* @return excluded resource names.
*/
}
/**
* Returns application name.
*
* @return application name.
*/
public String getApplicationName() {
return applicationName;
}
/**
* Sets application name.
*
* @param applicationName application name.
*/
this.applicationName = applicationName;
}
/**
* Sets action name
*
* @param actionName Action name.
*/
}
/**
* Sets action names
*
* @param actionNames Set of action names.
*/
for (String i : actionNames) {
}
}
/**
* Sets action values map.
*
* @param actionValues Action values.
*/
}
/**
* Returns action value.
*
* @param name Name of the action.
* @return action values.
*/
}
/**
* Returns action values.
*
* @return action values.
*/
return actionValues;
}
/**
* Returns action values.
*
* @param name Name of the action.
* @return action values.
*/
if (o instanceof Set) {
}
return set;
}
/**
* Sets advices.
*
* @param advices Advices.
*/
}
/**
* Returns advices.
*
* @return Advices.
*/
return advices;
}
/**
* @return Whether this entitlement has any advice.
*/
public boolean hasAdvice() {
}
/**
* Sets attributes.
*
* @param attributes Attributes.
*/
this.attributes = attributes;
}
/**
* Returns attributes.
*
* @return Attributes.
*/
return attributes;
}
/**
* Sets this entitlements TTL
*
* @param ttl The TTL to set
*/
this.timeToLive = ttl;
}
/**
* Returns the TTL
*
* @return The TTL in ms
*/
public long getTTL() {
return this.timeToLive;
}
/**
* Returns a set of resource names that match the given resource.
*
* @param adminSubject Admin Subject.
* @param realm Realm Name
* @param subject Subject who is under evaluation.
* @param applicationName application name.
* @param resourceName Resource name.
* @param environment Environment parameters.
* @return a set of resource names that match the given resource.
* @throws EntitlementException if resource names cannot be returned.
*/
boolean recursive)
throws EntitlementException {
for (String a : actionNames) {
}
}
return Collections.EMPTY_SET;
}
boolean recursive
) throws EntitlementException {
return Collections.EMPTY_SET;
}
return Collections.EMPTY_SET;
}
if (!recursive) {
if (resComparator instanceof RegExResourceName) {
resourceName, r, true);
}
} else {
r, resourceName, false);
} else {
}
}
}
} else {
if (resComparator instanceof RegExResourceName) {
r, resourceName, true);
}
} else {
resourceName, r, true);
} else {
}
}
}
}
}
if ((excludedResourceNames != null) &&
!excludedResourceNames.isEmpty()) {
i.remove();
break;
i.remove();
break;
}
}
}
}
return matched;
}
throws EntitlementException {
return set;
}
if (!principals.isEmpty()) {
for (Principal p : principals) {
} else {
}
}
}
}
}
}
return resources;
}
/**
* Returns string representation of the object
* @return string representation of the object
*/
try {
} catch (JSONException joe) {
}
return s;
}
/**
* Returns JSONObject mapping of the object
* @return JSONObject mapping of the object
* @throws JSONException if can not map to JSONObject
*/
if (resourceNames != null) {
}
if (excludedResourceNames != null) {
}
if (actionValues != null) {
}
}
if (attributes != null) {
}
return jo;
}
/**
* Returns <code>true</code> if the passed in object is equal to this object
* @param obj object to check for equality
* @return <code>true</code> if the passed in object is equal to this object
*/
boolean equalled = true;
return false;
}
return false;
}
return false;
}
} else { // name not null
return false;
return false;
}
}
if (applicationName == null) {
return false;
}
} else { // serviceName not null
return false;
return false;
}
}
if (resourceNames == null) {
return false;
}
} else { // resourceNames not null
return false;
return false;
}
}
return false;
}
} else {
return false;
}
if (!excludedResourceNames.equals(
return false;
}
}
if (actionValues == null) {
return false;
}
} else { // actionValues not null
return false;
} else if (!actionValues.equals(
object.getActionValues())) {
return false;
}
}
return false;
}
} else { // advices not null
return false;
object.getAdvices())) {
return false;
}
}
if (attributes == null) {
return false;
}
} else { // attributes not null
return false;
} else if (!attributes.equals(
object.getAttributes())) {
return false;
}
}
return equalled;
}
/**
* Returns hash code of the object
* @return hash code of the object
*/
public int hashCode() {
int code = 0;
}
if (applicationName != null) {
}
if (resourceNames != null) {
}
if (excludedResourceNames != null) {
}
if (actionValues != null) {
}
}
if (attributes != null) {
}
return code;
}
/**
* Returns resource search indexes.
*
* @param adminSubject Admin Subject.
* @param realm Realm Name
* @return resource search indexes.
*/
) throws EntitlementException {
for (String r : resourceNames) {
} else {
}
}
return result;
}
/**
* Returns resource save indexes.
*
* @param adminSubject Admin Subject.
* @param realm Realm Name
* @return resource save indexes.
*/
) throws EntitlementException {
// application can be null if the referred privilege is removed.
// get the application from root realm
}
for (String r : resourceNames) {
} else {
}
}
}
return result;
}
/**
* Returns application for this entitlement.
*
* @param adminSubject Admin Subject.
* @param realm Realm Name
* @return application for this entitlement.
*/
throws EntitlementException {
if (application == null) {
}
if (application == null) {
}
return application;
}
throws EntitlementException {
}
) throws EntitlementException {
for (String r : resourceNames) {
}
}
}
}
/**
* Canonicalizes resource name before persistence.
*
* @param adminSubject Admin Subject.
* @param realm Realm Name
*/
throws EntitlementException {
for (String r : resourceNames) {
}
}
{
for (String r : excludedResourceNames) {
}
}
}
}