Class EntitlementClassResolver
- java.lang.Object
-
- com.sun.identity.entitlement.EntitlementClassResolver
-
public final class EntitlementClassResolver extends Object
Resolves an externally-supplied class name into an instance of an expected entitlement type, safely.The entitlement (de)serialization layer stores the concrete implementation class of every nested subject / condition / resource-attribute member as a
classNamestring and rebuilds the object graph reflectively. Historically each call site didClass.forName(name)followed bynewInstance()and only then cast to the expected type. That is unsafe reflection (CWE-470 / CWE-502): the one-argumentClass.forName(String)runs the target class's static initializer at load time andnewInstance()runs its no-argument constructor, so an attacker-controlled name executes arbitrary classpath code before the trailing cast can reject it. A cast is not a guard.This helper closes that gap: it loads the class without initializing it (the three-argument
Class.forName(String, boolean, ClassLoader)form withinitialize == false) and verifies it is an instantiable subtype ofexpectedTypebefore it is ever instantiated. Only genuine, allowed entitlement types are constructed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntitlementClassResolver.RejectedTypeExceptionSignals that the requested class was found on the classpath but refused: it is not a subtype of the expected entitlement type, or it is not instantiable (abstract class or interface).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TnewInstance(String className, Class<T> expectedType)Loads, validates and instantiatesclassNameas an instance ofexpectedType.
-
-
-
Method Detail
-
newInstance
public static <T> T newInstance(String className, Class<T> expectedType) throws ClassNotFoundException, InstantiationException, IllegalAccessException
Loads, validates and instantiatesclassNameas an instance ofexpectedType.- Type Parameters:
T- the entitlement type- Parameters:
className- the requested implementation class name (may carry surrounding whitespace)expectedType- the entitlement type the class must implement or extend- Returns:
- a new instance of the requested class, guaranteed to be a
expectedType - Throws:
EntitlementClassResolver.RejectedTypeException- if the class exists but is not an instantiable subtype ofexpectedType(i.e. the name is not on the allowlist implied byexpectedType); the class is never instantiated in this caseClassNotFoundException- if the class cannot be loaded at allInstantiationException- if the validated class cannot be instantiated, including when its no-argument constructor is missing or throwsIllegalAccessException- if the validated class's no-argument constructor is inaccessible
-
-