use of com.sun.enterprise.config.serverbeans.SecureAdmin in project Payara by payara.
the class ProxyImpl method proxyRequest.
@Override
public Properties proxyRequest(UriInfo sourceUriInfo, Client client, ServiceLocator habitat) {
Properties proxiedResponse = new Properties();
try {
Domain domain = habitat.getService(Domain.class);
String forwardInstanceName = extractTargetInstanceName(sourceUriInfo);
Server forwardInstance = domain.getServerNamed(forwardInstanceName);
if (forwardInstance != null) {
UriBuilder forwardUriBuilder = constructForwardURLPath(sourceUriInfo);
// Host and Port are replaced to that of forwardInstanceName
URI forwardURI = forwardUriBuilder.scheme("https").host(forwardInstance.getAdminHost()).port(forwardInstance.getAdminPort()).build();
client = addAuthenticationInfo(client, forwardInstance, habitat);
WebTarget resourceBuilder = client.target(forwardURI);
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
Builder builder = resourceBuilder.request(MediaType.APPLICATION_JSON).header(SecureAdmin.Util.ADMIN_INDICATOR_HEADER_NAME, secureAdmin.getSpecialAdminIndicator());
// TODO if the target server is down, we get ClientResponseException. Need to handle it
Response response = builder.get(Response.class);
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status.getFamily() == javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) {
String jsonDoc = response.readEntity(String.class);
Map responseMap = MarshallingUtils.buildMapFromDocument(jsonDoc);
Map resultExtraProperties = (Map) responseMap.get("extraProperties");
if (resultExtraProperties != null) {
Object entity = resultExtraProperties.get("entity");
if (entity != null) {
proxiedResponse.put("entity", entity);
}
@SuppressWarnings({ "unchecked" }) Map<String, String> childResources = (Map<String, String>) resultExtraProperties.get("childResources");
for (Map.Entry<String, String> entry : childResources.entrySet()) {
String targetURL = null;
try {
URL originalURL = new URL(entry.getValue());
// Construct targetURL which has host+port of DAS and path from originalURL
targetURL = constructTargetURLPath(sourceUriInfo, originalURL).build().toASCIIString();
} catch (MalformedURLException e) {
// TODO There was an exception while parsing URL. Need to decide what to do. For now ignore the child entry
}
entry.setValue(targetURL);
}
proxiedResponse.put("childResources", childResources);
}
Object message = responseMap.get("message");
if (message != null) {
proxiedResponse.put("message", message);
}
Object properties = responseMap.get("properties");
if (properties != null) {
proxiedResponse.put("properties", properties);
}
} else {
throw new WebApplicationException(response.readEntity(String.class), status);
}
} else {
// server == null
// TODO error to user. Can not locate server for whom data is being looked for
}
} catch (Exception ex) {
throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
}
return proxiedResponse;
}
use of com.sun.enterprise.config.serverbeans.SecureAdmin in project Payara by payara.
the class AdminConsoleAuthModule method getAuthenticationURL.
/**
* Compute the rest URL needed to authenticate a user
* @return
*/
private String getAuthenticationURL() {
ServiceLocator habitat = SecurityServicesUtil.getInstance().getHabitat();
Domain domain = habitat.getService(Domain.class);
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
NetworkListener adminListener = domain.getServerNamed("server").getConfig().getNetworkConfig().getNetworkListener("admin-listener");
String host = adminListener.getAddress();
String port = adminListener.getPort();
return (SecureAdmin.Util.isEnabled(secureAdmin) ? "https://" : "http://") + (host.equals("0.0.0.0") ? "localhost" : host) + ":" + port + "/management/sessions";
}
use of com.sun.enterprise.config.serverbeans.SecureAdmin in project Payara by payara.
the class RestUtil method initialize.
// ******************************************************************************************************************
// Jersey client methods
// ******************************************************************************************************************
public static ClientBuilder initialize(ClientBuilder clientBuilder) {
try {
ServiceLocator habitat = SecurityServicesUtil.getInstance().getHabitat();
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
final SSLContext sslContext = habitat.<SSLUtils>getService(SSLUtils.class).getAdminSSLContext(SecureAdmin.Util.DASAlias(secureAdmin), null);
// Instruct Jersey to use HostNameVerifier and SSLContext provided by us.
clientBuilder.hostnameVerifier(new BasicHostnameVerifier()).sslContext(sslContext).register(CsrfProtectionFilter.class);
} catch (Exception ex) {
GuiUtil.getLogger().warning("RestUtil.initialize() failed");
if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
ex.printStackTrace();
}
}
return clientBuilder;
}
use of com.sun.enterprise.config.serverbeans.SecureAdmin in project Payara by payara.
the class ProxyImpl method addAuthenticationInfo.
/**
* Use SSL to authenticate
*/
private Client addAuthenticationInfo(Client client, Server server, ServiceLocator habitat) {
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
// TODO need to get hardcoded "TLS" from corresponding ServerRemoteAdminCommand constant);
final SSLContext sslContext = habitat.<SSLUtils>getService(SSLUtils.class).getAdminSSLContext(SecureAdmin.Util.DASAlias(secureAdmin), "TLS");
// Instruct Jersey to use HostNameVerifier and SSLContext provided by us.
final ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(client.getConfiguration()).hostnameVerifier(new BasicHostnameVerifier(server.getAdminHost())).sslContext(sslContext);
return clientBuilder.build();
}
Aggregations