Skip to content

Commit

Permalink
HSEARCH-5131 Remove usage and mentions of a security manager
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Apr 17, 2024
1 parent f8d825b commit be9e1ae
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static <T> Constructor<T> getConstructor(TypeToken<T> type) {
try {
return (Constructor<T>) type.getRawType().getConstructor();
}
catch (NoSuchMethodException | SecurityException e) {
catch (NoSuchMethodException e) {
throw new AssertionFailure( "Missing or inaccessible no-arg constructor on type " + type );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static <T> T instanceFromName(Class<T> targetSuperType,
* @return a new instance of classToLoad
*
* @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
* missing proper constructor, securitymanager errors.
* missing proper constructor errors.
*/
public static <T> T untypedInstanceFromClass(final Class<T> classToLoad) {
try {
Expand Down Expand Up @@ -142,9 +142,6 @@ private static <T> T callNoArgConstructor(Class<T> classToLoad)
Constructor<T> constructor = classToLoad.getConstructor();
return constructor.newInstance();
}
catch (SecurityException e) {
throw log.securityManagerLoadingError( classToLoad, e.getMessage(), e );
}
catch (NoSuchMethodException e) {
throw log.noPublicNoArgConstructor( classToLoad );
}
Expand All @@ -160,9 +157,6 @@ private static <T> T callMapArgConstructor(Class<T> classToLoad, Map<String, Str
Constructor<T> singleMapConstructor = classToLoad.getConstructor( Map.class );
return singleMapConstructor.newInstance( constructorParameter );
}
catch (SecurityException e) {
throw log.securityManagerLoadingError( classToLoad, e.getMessage(), e );
}
catch (NoSuchMethodException e) {
throw log.noPublicMapArgConstructor( classToLoad );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.concurrent.ThreadFactory;

import org.hibernate.search.engine.environment.thread.spi.ThreadProvider;
import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;

public final class EmbeddedThreadProvider implements ThreadProvider {

Expand All @@ -31,13 +30,8 @@ public String createThreadName(String prefix, int threadNumber) {
}

@Override
@SuppressForbiddenApis(reason = "It's unclear how we will handle this without the security manager;"
+ " we'll see when the security manager actually gets removed from the JDK")
public ThreadFactory createThreadFactory(String prefix) {
@SuppressWarnings("removal")
SecurityManager s = System.getSecurityManager();
@SuppressWarnings({ "removal", "deprecation" })
ThreadGroup group = ( s != null ) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
ThreadGroup group = Thread.currentThread().getThreadGroup();
String namePrefix = createFullThreadNamePrefix( prefix );
return new SimpleThreadFactory( group, namePrefix );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ void newCollectedFailure(String process,
)
SearchException dslExtensionNoMatch(List<?> attemptedExtensions);

@Message(id = ID_OFFSET + 28, value = "Security manager does not allow access to the constructor of type '%1$s': %2$s")
SearchException securityManagerLoadingError(@FormatWith(ClassFormatter.class) Class<?> classToLoad,
String causeMessage, @Cause Exception cause);

@Message(id = ID_OFFSET + 30, value = "Unable to load class '%1$s': %2$s")
ClassLoadingException unableToLoadTheClass(String className, String causeMessage, @Cause Throwable cause);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
Expand Down Expand Up @@ -154,17 +153,10 @@ private <T> HibernateOrmClassRawTypeModel<T> createClassTypeModel(Class<T> type)
}

private static void setAccessible(Member member) {
try {
// always try to set accessible to true regardless of visibility
// as it's faster even for public fields:
// it bypasses the security model checks at execution time.
( (AccessibleObject) member ).setAccessible( true );
}
catch (SecurityException se) {
if ( !Modifier.isPublic( member.getModifiers() ) ) {
throw se;
}
}
// always try to set accessible to true regardless of visibility
// as it's faster even for public fields:
// it bypasses the security model checks at execution time.
( (AccessibleObject) member ).setAccessible( true );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -94,16 +93,9 @@ private <T> PojoRawTypeModel<T> createTypeModel(Class<T> clazz) {
}

private static void setAccessible(Member member) {
try {
// always try to set accessible to true regardless of visibility
// as it's faster even for public fields:
// it bypasses the security model checks at execution time.
( (AccessibleObject) member ).setAccessible( true );
}
catch (SecurityException se) {
if ( !Modifier.isPublic( member.getModifiers() ) ) {
throw se;
}
}
// always try to set accessible to true regardless of visibility
// as it's faster even for public fields:
// it bypasses the security model checks at execution time.
( (AccessibleObject) member ).setAccessible( true );
}
}

0 comments on commit be9e1ae

Please sign in to comment.