use of org.apache.catalina.Valve in project tomee by apache.
the class LazyValve method instance.
private Valve instance() {
if (delegate == null) {
synchronized (this) {
if (delegate == null) {
final Object instance;
ClassLoader cl = loader();
if (cl == null) {
return null;
}
final Class<?> clazz;
try {
clazz = cl.loadClass(delegateClassName);
} catch (final ClassNotFoundException e) {
throw new TomEERuntimeException(e);
}
try {
final ObjectRecipe recipe = new ObjectRecipe(clazz);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.FIELD_INJECTION);
recipe.allow(Option.PRIVATE_PROPERTIES);
if (properties != null) {
final Properties props = new PropertiesAdapter().unmarshal(properties.trim().replaceAll("\\p{Space}*(\\p{Alnum}*)=", "\n$1="));
recipe.setAllProperties(props);
}
instance = recipe.create();
} catch (final Exception e) {
throw new TomEERuntimeException(e);
}
delegate = Valve.class.cast(instance);
delegate.setNext(next);
if (Contained.class.isInstance(delegate)) {
Contained.class.cast(delegate).setContainer(container);
}
if (Lifecycle.class.isInstance(delegate)) {
if (init) {
try {
final Lifecycle lifecycle = Lifecycle.class.cast(delegate);
for (final LifecycleListener listener : lifecycleListeners) {
lifecycle.addLifecycleListener(listener);
}
lifecycle.init();
if (start) {
lifecycle.start();
}
} catch (final LifecycleException e) {
// no-op
}
}
}
if (ClusterValve.class.isInstance(delegate)) {
ClusterValve.class.cast(delegate).setCluster(cluster);
}
}
}
}
return delegate;
}
use of org.apache.catalina.Valve in project tomee by apache.
the class TomcatHessianRegistry method deploy.
@Override
public String deploy(final ClassLoader loader, final HessianServer listener, final String hostname, final String app, final String authMethod, final String transportGuarantee, final String realmName, final String name) throws URISyntaxException {
Container host = engine.findChild(hostname);
if (host == null) {
host = engine.findChild(engine.getDefaultHost());
if (host == null) {
throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?");
}
}
final String contextRoot = contextName(app);
Context context = Context.class.cast(host.findChild(contextRoot));
if (context == null) {
Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot);
if (fakeContext != null) {
context = fakeContext.getLeft();
fakeContext.setValue(fakeContext.getValue() + 1);
} else {
context = Context.class.cast(host.findChild(contextRoot));
if (context == null) {
fakeContext = fakeContexts.get(contextRoot);
if (fakeContext == null) {
context = createNewContext(loader, authMethod, transportGuarantee, realmName, app);
fakeContext = new MutablePair<>(context, 1);
fakeContexts.put(contextRoot, fakeContext);
} else {
context = fakeContext.getLeft();
fakeContext.setValue(fakeContext.getValue() + 1);
}
}
}
}
final String servletMapping = generateServletPath(name);
Wrapper wrapper = Wrapper.class.cast(context.findChild(servletMapping));
if (wrapper != null) {
throw new IllegalArgumentException("Servlet " + servletMapping + " in web application context " + context.getName() + " already exists");
}
wrapper = context.createWrapper();
wrapper.setName(HESSIAN.replace("/", "") + "_" + name);
wrapper.setServlet(new OpenEJBHessianServlet(listener));
context.addChild(wrapper);
context.addServletMappingDecoded(servletMapping, wrapper.getName());
if ("BASIC".equals(authMethod) && StandardContext.class.isInstance(context)) {
final StandardContext standardContext = StandardContext.class.cast(context);
boolean found = false;
for (final Valve v : standardContext.getPipeline().getValves()) {
if (LimitedBasicValve.class.isInstance(v) || BasicAuthenticator.class.isInstance(v)) {
found = true;
break;
}
}
if (!found) {
standardContext.addValve(new LimitedBasicValve());
}
}
final List<String> addresses = new ArrayList<>();
for (final Connector connector : connectors) {
for (final String mapping : wrapper.findMappings()) {
final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), contextRoot + mapping, null, null);
addresses.add(address.toString());
}
}
return HttpUtil.selectSingleAddress(addresses);
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class StandardEngineSF method storeChildren.
/**
* Store the specified Engine properties.
*
* @param aWriter
* PrintWriter to which we are storing
* @param indent
* Number of spaces to indent this element
* @param aEngine
* Object whose properties are being stored
*
* @exception Exception
* if an exception occurs while storing
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine, StoreDescription parentDesc) throws Exception {
if (aEngine instanceof StandardEngine) {
StandardEngine engine = (StandardEngine) aEngine;
// Store nested <Listener> elements
LifecycleListener[] listeners = ((Lifecycle) engine).findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <Realm> element
Realm realm = engine.getRealm();
Realm parentRealm = null;
// TODO is this case possible? (see it a old Server 5.0 impl)
if (engine.getParent() != null) {
parentRealm = engine.getParent().getRealm();
}
if (realm != parentRealm) {
storeElement(aWriter, indent, realm);
}
// Store nested <Valve> elements
Valve[] valves = engine.getPipeline().getValves();
if (valves != null && valves.length > 0) {
List<Valve> engineValves = new ArrayList<>();
for (int i = 0; i < valves.length; i++) {
if (!(valves[i] instanceof ClusterValve))
engineValves.add(valves[i]);
}
storeElementArray(aWriter, indent, engineValves.toArray());
}
// store all <Cluster> elements
Cluster cluster = engine.getCluster();
if (cluster != null) {
storeElement(aWriter, indent, cluster);
}
// store all <Host> elements
Container[] children = engine.findChildren();
storeElementArray(aWriter, indent, children);
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class ContextConfig method authenticatorConfig.
/**
* Set up an Authenticator automatically if required, and one has not
* already been configured.
*/
protected void authenticatorConfig() {
LoginConfig loginConfig = context.getLoginConfig();
SecurityConstraint[] constraints = context.findConstraints();
if (context.getIgnoreAnnotations() && (constraints == null || constraints.length == 0) && !context.getPreemptiveAuthentication()) {
return;
} else {
if (loginConfig == null) {
// Not metadata-complete or security constraints present, need
// an authenticator to support @ServletSecurity annotations
// and/or constraints
loginConfig = DUMMY_LOGIN_CONFIG;
context.setLoginConfig(loginConfig);
}
}
// Has an authenticator been configured already?
if (context.getAuthenticator() != null) {
return;
}
// Has a Realm been configured for us to authenticate against?
if (context.getRealm() == null) {
log.error(sm.getString("contextConfig.missingRealm"));
ok = false;
return;
}
/*
* First check to see if there is a custom mapping for the login
* method. If so, use it. Otherwise, check if there is a mapping in
* org/apache/catalina/startup/Authenticators.properties.
*/
Valve authenticator = null;
if (customAuthenticators != null) {
authenticator = (Valve) customAuthenticators.get(loginConfig.getAuthMethod());
}
if (authenticator == null) {
if (authenticators == null) {
log.error(sm.getString("contextConfig.authenticatorResources"));
ok = false;
return;
}
// Identify the class name of the Valve we should configure
String authenticatorName = authenticators.getProperty(loginConfig.getAuthMethod());
if (authenticatorName == null) {
log.error(sm.getString("contextConfig.authenticatorMissing", loginConfig.getAuthMethod()));
ok = false;
return;
}
// Instantiate and install an Authenticator of the requested class
try {
Class<?> authenticatorClass = Class.forName(authenticatorName);
authenticator = (Valve) authenticatorClass.newInstance();
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log.error(sm.getString("contextConfig.authenticatorInstantiate", authenticatorName), t);
ok = false;
}
}
if (authenticator != null) {
Pipeline pipeline = context.getPipeline();
if (pipeline != null) {
pipeline.addValve(authenticator);
if (log.isDebugEnabled()) {
log.debug(sm.getString("contextConfig.authenticatorConfigured", loginConfig.getAuthMethod()));
}
}
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class ContainerMBean method removeValve.
/**
* Remove an existing Valve.
*
* @param valveName MBean Name of the Valve to remove
*
* @exception MBeanException if a component cannot be removed
*/
public void removeValve(String valveName) throws MBeanException {
Container container = doGetManagedResource();
ObjectName oname;
try {
oname = new ObjectName(valveName);
} catch (MalformedObjectNameException e) {
throw new MBeanException(e);
} catch (NullPointerException e) {
throw new MBeanException(e);
}
if (container != null) {
Valve[] valves = container.getPipeline().getValves();
for (int i = 0; i < valves.length; i++) {
if (valves[i] instanceof JmxEnabled) {
ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
if (voname.equals(oname)) {
container.getPipeline().removeValve(valves[i]);
}
}
}
}
}
Aggregations