Skip to content

Commit

Permalink
Merge pull request #323 from newrelic/enhancments/websphere-lib-NR-30…
Browse files Browse the repository at this point in the history
…3483

NR-303483: Server Configuration for WebSphere Liberty
  • Loading branch information
IshikaDawda authored Sep 20, 2024
2 parents ef922cb + e8db0c7 commit b2b8f7a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
dependencies {
implementation(project(":newrelic-security-api"))
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation(fileTree(include: ["*.jar"], dir: "lib"))
}

def shouldBuild = fileTree(include: ["*.jar"], dir: "lib").size() > 0

compileJava {
enabled(shouldBuild)
}

compileTestJava {
enabled(shouldBuild)
}

tasks.getByName("writeCachedWeaveAttributes").enabled(shouldBuild)

jar {
enabled(shouldBuild)
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.websphere-liberty' }
}

site {
title 'WebSphere Liberty'
type 'Appserver'
versionOverride '[8.5,)'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ibm.ws.tcpchannel.internal;

import com.ibm.websphere.channelfw.ChannelData;
import com.ibm.wsspi.channelfw.Channel;
import com.ibm.wsspi.channelfw.exception.ChannelException;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import java.util.Map;

@Weave
public class TCPChannelFactory {

protected Channel createChannel(final ChannelData channelData) throws ChannelException {
try {
if (channelData.isInbound() && "defaultHttpEndpoint".equals(channelData.getExternalName())) {
Map<Object, Object> propertyBag = channelData.getPropertyBag();
if (propertyBag.containsKey("port")) {
try {
int port = Integer.parseInt((String) propertyBag.get("port"));
NewRelicSecurity.getAgent().setApplicationConnectionConfig(port, "http");
} catch (NumberFormatException e) {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.SERVER_CONFIG_ERROR, "WEBSPHERE_LIBERTY", e.getMessage()), e, this.getClass().getName());
}
} else {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.SERVER_CONFIG_ERROR, "WEBSPHERE_LIBERTY", null), null, this.getClass().getName());
}
} else {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.SERVER_CONFIG_ERROR, "WEBSPHERE_LIBERTY", null), null, this.getClass().getName());
}
} catch (Exception ignored) {
}
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class GenericHelper {
public static final String NR_SEC_CUSTOM_SPRING_REDIS_ATTR = "SPRING-DATA-REDIS";

public static final String REGISTER_OPERATION_EXCEPTION_MESSAGE = "Instrumentation library: %s , error while library instrumented call processing : %s";
public static final String SERVER_CONFIG_ERROR = "Instrumentation library: %s , error while detecting Server Configuration : %s";
public static final String EXIT_OPERATION_EXCEPTION_MESSAGE = "Instrumentation library: %s , error while generating exit operation: %s";
public static final String SECURITY_EXCEPTION_MESSAGE = "New Relic Security Exception raised for Instrumentation library: %s, reason: %s ";
public static final String URI_EXCEPTION_MESSAGE = "Instrumentation library: %s , error while extracting URI : %s";
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ include 'instrumentation:solr-5.1.0'
include 'instrumentation:solr-7.0.0'
include 'instrumentation:solr-8.0.0'
include 'instrumentation:solr-9.0.0'
include 'instrumentation:websphere-liberty-profile-environment-8.5.5.5'

0 comments on commit b2b8f7a

Please sign in to comment.