Skip to content

Commit

Permalink
Random cleanups
Browse files Browse the repository at this point in the history
- note one FIXME when server tries to used Jersey Client which is not on classpath
  • Loading branch information
dmatej committed Apr 3, 2022
1 parent dbae2da commit 8c29a78
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 607 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -236,7 +237,7 @@ public static AppClientContainer.Builder newBuilder(

private URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();

private Collection<EntityManagerFactory> emfs = null;
private final Collection<EntityManagerFactory> emfs = null;

// private boolean isJWS = false;

Expand Down Expand Up @@ -354,7 +355,7 @@ private void completePreparation(final Instrumentation inst) throws
* Allow pre-destroy handling to work on the main class during clean-up.
*/
cleanup.setInjectionManager(injectionManager,
clientMainClassSetting.clientMainClass);
ClientMainClassSetting.clientMainClass);

/*
* If this app client contains persistence unit refs, then initialize
Expand Down Expand Up @@ -459,9 +460,10 @@ public Map<Thread, StackTraceElement[]> run() {

private void cleanupWhenSafe() {
if (isEDTRunning()) {
final AtomicReference<Thread> edt = new AtomicReference<Thread>();
final AtomicReference<Thread> edt = new AtomicReference<>();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
edt.set(Thread.currentThread());
}
Expand Down Expand Up @@ -498,7 +500,7 @@ private Method getMainMethod() throws NoSuchMethodException,
// String[] as the only argument
Method result = null;

result = clientMainClassSetting.getClientMainClass(
result = ClientMainClassSetting.getClientMainClass(
classLoader,
injectionManager,
invocationManager,
Expand Down Expand Up @@ -729,34 +731,34 @@ void setClassLoader(ACCClassLoader classLoader) {
*/
public interface Builder {

public AppClientContainer newContainer(URI archiveURI) throws Exception, UserError;
AppClientContainer newContainer(URI archiveURI) throws Exception, UserError;

public AppClientContainer newContainer(URI archiveURI,
AppClientContainer newContainer(URI archiveURI,
CallbackHandler callbackHandler,
String mainClassName,
String appName) throws Exception, UserError;

public AppClientContainer newContainer(URI archiveURI,
AppClientContainer newContainer(URI archiveURI,
CallbackHandler callbackHandler,
String mainClassName,
String appName,
boolean isTextAuth) throws Exception, UserError;



public AppClientContainer newContainer(Class mainClass) throws Exception, UserError;
AppClientContainer newContainer(Class mainClass) throws Exception, UserError;

public TargetServer[] getTargetServers();
TargetServer[] getTargetServers();

/**
* Adds an optional {@link MessageSecurityConfig} setting.
*
* @param msConfig the new MessageSecurityConfig
* @return the <code>Builder</code> instance
*/
public Builder addMessageSecurityConfig(final MessageSecurityConfig msConfig);
Builder addMessageSecurityConfig(final MessageSecurityConfig msConfig);

public List<MessageSecurityConfig> getMessageSecurityConfig();
List<MessageSecurityConfig> getMessageSecurityConfig();

/**
* Sets the optional authentication realm for the ACC.
Expand All @@ -767,9 +769,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param className name of the class which implements the realm
* @return the <code>Builder</code> instance
*/
public Builder authRealm(final String className);
Builder authRealm(final String className);

public AuthRealm getAuthRealm();
AuthRealm getAuthRealm();

// /**
// * Sets the callback handler the ACC will use when authentication is
Expand Down Expand Up @@ -802,9 +804,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param password password valid in the default realm on the server for the username
* @return the <code>Builder</code> instance
*/
public Builder clientCredentials(final String user, final char[] password);
Builder clientCredentials(final String user, final char[] password);

public ClientCredential getClientCredential();
ClientCredential getClientCredential();

/**
* Sets the optional client credentials and server-side realm to be used during
Expand All @@ -819,15 +821,15 @@ public AppClientContainer newContainer(URI archiveURI,
* @param realmName name of the realm on the server within which the credentials are valid
* @return the <code>Builder</code> instance
*/
public Builder clientCredentials(final String user, final char[] password, final String realm);
Builder clientCredentials(final String user, final char[] password, final String realm);

/**
* Sets the container-level Properties.
*
* @param containerProperties
* @return
*/
public Builder containerProperties(final Properties containerProperties);
Builder containerProperties(final Properties containerProperties);

/**
* Sets the container-level properties.
Expand All @@ -838,23 +840,23 @@ public AppClientContainer newContainer(URI archiveURI,
* @param containerProperties Property objects to use in setting the properties
* @return
*/
public Builder containerProperties(final List<Property> containerProperties);
Builder containerProperties(final List<Property> containerProperties);

/**
* Returns the container-level Properties.
* @return container-level properties
*/
public Properties getContainerProperties();
Properties getContainerProperties();

/**
* Sets the logger which the ACC should use as it runs.
*
* @param logger
* @return
*/
public Builder logger(final Logger logger);
Builder logger(final Logger logger);

public Logger getLogger();
Logger getLogger();

/**
* Sets whether the ACC should send the password to the server during
Expand All @@ -863,9 +865,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param sendPassword
* @return
*/
public Builder sendPassword(final boolean sendPassword);
Builder sendPassword(final boolean sendPassword);

public boolean getSendPassword();
boolean getSendPassword();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -108,7 +109,7 @@ public class GFServerConfigProvider implements AuthConfigProvider {
protected AuthConfigFactory factory = null;
private WebServicesDelegate wsdelegate = null;

public GFServerConfigProvider(Map properties, AuthConfigFactory factory) {
public GFServerConfigProvider(Map<String, String> properties, AuthConfigFactory factory) {
this.factory = factory;
initializeParser();

Expand Down Expand Up @@ -376,10 +377,10 @@ static class Entry {
private static final Class[] PARAMS = {};
private static final Object[] ARGS = {};

private String moduleClassName;
private MessagePolicy requestPolicy;
private MessagePolicy responsePolicy;
private Map options;
private final String moduleClassName;
private final MessagePolicy requestPolicy;
private final MessagePolicy responsePolicy;
private final Map options;

/**
* Construct a ConfigFile entry.
Expand Down Expand Up @@ -488,11 +489,11 @@ public String getDefaultServerID() {
* parsed ID entry
*/
public static class IDEntry {
private String type; // provider type (client, server, client-server)
private String moduleClassName;
private MessagePolicy requestPolicy;
private MessagePolicy responsePolicy;
private Map options;
private final String type; // provider type (client, server, client-server)
private final String moduleClassName;
private final MessagePolicy requestPolicy;
private final MessagePolicy responsePolicy;
private final Map options;

public String getModuleClassName() {
return moduleClassName;
Expand Down Expand Up @@ -527,8 +528,8 @@ public IDEntry(String type, String moduleClassName, MessagePolicy requestPolicy,
* A data object contains module object and the corresponding map.
*/
protected static class ModuleInfo {
private Object module;
private Map map;
private final Object module;
private final Map map;

ModuleInfo(Object module, Map map) {
this.module = module;
Expand Down Expand Up @@ -940,11 +941,11 @@ public ClientAuthContext getAuthContext(String authContextID, Subject clientSubj

static protected class GFServerAuthContext implements ServerAuthContext {

private GFServerAuthConfig config;
private ServerAuthModule module;
private com.sun.enterprise.security.jauth.ServerAuthModule oldModule;
private final GFServerAuthConfig config;
private final ServerAuthModule module;
private final com.sun.enterprise.security.jauth.ServerAuthModule oldModule;

private Map map;
private final Map map;
boolean managesSession = false;

GFServerAuthContext(GFServerAuthConfig config, ServerAuthModule module, Map map) {
Expand Down Expand Up @@ -1068,9 +1069,9 @@ public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthEx

static protected class GFClientAuthContext implements ClientAuthContext {

private GFClientAuthConfig config;
private ClientAuthModule module;
private com.sun.enterprise.security.jauth.ClientAuthModule oldModule;
private final GFClientAuthConfig config;
private final ClientAuthModule module;
private final com.sun.enterprise.security.jauth.ClientAuthModule oldModule;
// private Map map;

GFClientAuthContext(GFClientAuthConfig config, ClientAuthModule module, Map map) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -36,13 +37,13 @@ public abstract class JAASAuthConfigProvider extends AuthConfigProviderHelper {
private static final String DEFAULT_JAAS_APP_NAME = "other";
private static final String ALL_APPS = "*";

private String configFileName;
private final String configFileName;
private ExtendedConfigFile jaasConfig;

private Map<String, ?> properties;
private AuthConfigFactory factory;
private final Map<String, String> properties;
private final AuthConfigFactory factory;

public JAASAuthConfigProvider(Map properties, AuthConfigFactory factory) {
public JAASAuthConfigProvider(Map<String, String> properties, AuthConfigFactory factory) {
this.properties = properties;
this.factory = factory;

Expand All @@ -62,11 +63,13 @@ public JAASAuthConfigProvider(Map properties, AuthConfigFactory factory) {
selfRegister();
}

@Override
public Map<String, ?> getProperties() {
return properties;
}


@Override
public AuthConfigFactory getFactory() {
return factory;
}
Expand All @@ -85,24 +88,29 @@ private RegistrationContext getRegistrationContext(String id) {

final String description = "JAAS AuthConfig: " + appContext;

@Override
public String getMessageLayer() {
return layer;
}

@Override
public String getAppContext() {
return appContext;
}

@Override
public String getDescription() {
return description;
}

@Override
public boolean isPersistent() {
return false;
}
};
}

@Override
public AuthConfigFactory.RegistrationContext[] getSelfRegistrationContexts() {
final String[] appContexts = jaasConfig.getAppNames(getModuleTypes());
RegistrationContext[] rvalue = new RegistrationContext[appContexts.length];
Expand All @@ -112,6 +120,7 @@ public AuthConfigFactory.RegistrationContext[] getSelfRegistrationContexts() {
return rvalue;
}

@Override
public AuthContextHelper getAuthContextHelper(String appContext, boolean returnNullContexts)
throws AuthException {
return new JAASAuthContextHelper(getLoggerName(), returnNullContexts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public static List<ReferenceContainer> getReferenceContainersOf(Domain d, Config
}

if (!StringUtils.ok(name)) { // we choose to make this not an error
return sub;
return sub;
}

List<ReferenceContainer> all = getAllReferenceContainers(d);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,12 +17,8 @@

package org.glassfish.admin.rest.client;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.client.Invocation.Builder;
Expand All @@ -30,10 +27,14 @@
import jakarta.ws.rs.core.Link;
import jakarta.ws.rs.core.UriBuilder;

import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;

import org.glassfish.jersey.client.JerseyClientBuilder;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.glassfish.jersey.client.filter.CsrfProtectionFilter;
import org.glassfish.jersey.jettison.JettisonFeature;
Expand Down Expand Up @@ -63,11 +64,11 @@ public ClientWrapper(final Map<String, String> headers) {
}

public ClientWrapper(final Map<String, String> headers, String userName, String password) {
realClient = JerseyClientBuilder.newClient();
realClient = ClientBuilder.newClient();
realClient.register(new MultiPartFeature());
realClient.register(new JettisonFeature());
realClient.register(new CsrfProtectionFilter());
if ((userName != null) && (password != null)) {
if (userName != null && password != null) {
realClient.register(HttpAuthenticationFeature.basic(userName, password));
}
realClient.register(new ClientRequestFilter() {
Expand Down

0 comments on commit 8c29a78

Please sign in to comment.