Skip to content

Commit

Permalink
CDI Startup
Browse files Browse the repository at this point in the history
Removed SecurityManager dependency
  • Loading branch information
pizzi80 committed Mar 3, 2022
1 parent 5574b87 commit b773419
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions impl/src/main/java/org/glassfish/soteria/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public static boolean notNull(Object... objects) {
* @param string The string to be checked on emptiness.
* @return True if the given string is null or is empty.
*/
public static boolean isEmpty(String string) {
return string == null || string.isEmpty();
public static boolean isEmpty(String string) {return string == null || string.isEmpty();}
public static boolean isNotEmpty(String string) {
return !isEmpty(string);
}

/**
Expand All @@ -84,6 +85,9 @@ public static boolean isEmpty(String string) {
public static boolean isEmpty(Object[] array) {
return array == null || array.length == 0;
}
public static boolean isNotEmpty(Object[] array) {
return !isEmpty(array);
}

/**
* Returns <code>true</code> if the given collection is null or is empty.
Expand All @@ -94,7 +98,6 @@ public static boolean isEmpty(Object[] array) {
public static boolean isEmpty(Collection<?> collection) {
return collection == null || collection.isEmpty();
}

public static boolean isNotEmpty(Collection<?> collection) {
return !isEmpty(collection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;
import org.glassfish.soteria.cdi.CdiExtension;
import org.glassfish.soteria.cdi.spi.CDIPerRequestInitializer;
import org.glassfish.soteria.cdi.spi.impl.LibertyCDIPerRequestInitializer;
Expand All @@ -36,6 +37,7 @@
import static java.util.logging.Level.FINEST;
import static java.util.logging.Level.INFO;
import static org.glassfish.soteria.Utils.isEmpty;
import static org.glassfish.soteria.Utils.isNotEmpty;
import static org.glassfish.soteria.mechanisms.jaspic.Jaspic.deregisterServerAuthModule;
import static org.glassfish.soteria.mechanisms.jaspic.Jaspic.registerServerAuthModule;

Expand All @@ -51,6 +53,8 @@
* @author Arjan Tijms
*
*/
@WebListener
@ApplicationScoped
public class SamRegistrationInstaller implements ServletContainerInitializer, ServletContextListener {

private static final Logger logger = Logger.getLogger(SamRegistrationInstaller.class.getName());
Expand Down Expand Up @@ -97,17 +101,17 @@ public void onStartup(Set<Class<?>> classes, ServletContext context) {

CDIPerRequestInitializer cdiPerRequestInitializer = null;

if (!isEmpty(System.getProperty("wlp.server.name"))) {
if (isNotEmpty(System.getProperty("wlp.server.name"))) {
// Hardcode server check for now. TODO: design/implement proper service loader/SPI for this
cdiPerRequestInitializer = new LibertyCDIPerRequestInitializer();
logger.log(INFO, "Running on Liberty - installing CDI request scope activator");
logger.info("Running on Liberty - installing CDI request scope activator");
}

registerServerAuthModule(new HttpBridgeServerAuthModule(cdiPerRequestInitializer), context);

// Add a listener so we can process the context destroyed event, which is needed
// to de-register the SAM correctly.
context.addListener(this);
//context.addListener(this);
}

}
Expand All @@ -117,10 +121,12 @@ public void onStartup(Set<Class<?>> classes, ServletContext context) {
@Override
public void contextInitialized(ServletContextEvent event) {
// noop
logger.fine("contextInitialized");
}

@Override
public void contextDestroyed(ServletContextEvent event) {
logger.fine("contextDestroyed");
deregisterServerAuthModule(event.getServletContext());
}

Expand Down

0 comments on commit b773419

Please sign in to comment.