Skip to content

Commit

Permalink
NR-272899: Fix for user class detection grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
IshikaDawda committed Sep 17, 2024
1 parent 339ee15 commit fed109e
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ private UserClassEntity setUserClassEntityByAnnotation(StackTraceElement[] servi
}

private UserClassEntity setUserClassEntity(AbstractOperation operation, SecurityMetaData securityMetaData) {
boolean frameworkSpecificEntityFound = false;
UserClassEntity userClassEntity = new UserClassEntity();
StackTraceElement userStackTraceElement = securityMetaData.getCustomAttribute(GenericHelper.USER_CLASS_ENTITY, StackTraceElement.class);
if(userStackTraceElement == null && securityMetaData.getMetaData().getServiceTrace() != null && securityMetaData.getMetaData().getServiceTrace().length > 0){
Expand All @@ -520,21 +521,18 @@ private UserClassEntity setUserClassEntity(AbstractOperation operation, Security
switch (framework){
case "vertx-web":
case "GRPC":
if(i-1 >= 0) {
if(!frameworkSpecificEntityFound && i-1 >= 0) {
userClassEntity = setUserClassEntityForVertx(operation, userStackTraceElement, userClassEntity, securityMetaData.getMetaData().isUserLevelServiceMethodEncountered(), i);
if(userClassEntity.getUserClassElement() != null){
return userClassEntity;
frameworkSpecificEntityFound = true;
}
}
break;
default:
if(userStackTraceElement != null){
if(StringUtils.equals(stackTraceElement.getClassName(), userStackTraceElement.getClassName())
&& StringUtils.equals(stackTraceElement.getMethodName(), userStackTraceElement.getMethodName())){
userClassEntity.setUserClassElement(stackTraceElement);
userClassEntity.setCalledByUserCode(securityMetaData.getMetaData().isUserLevelServiceMethodEncountered());
return userClassEntity;
}
if(userStackTraceElement != null && StringUtils.equals(stackTraceElement.getClassName(), userStackTraceElement.getClassName())
&& StringUtils.equals(stackTraceElement.getMethodName(), userStackTraceElement.getMethodName())){
userClassEntity.setUserClassElement(stackTraceElement);
userClassEntity.setCalledByUserCode(securityMetaData.getMetaData().isUserLevelServiceMethodEncountered());
}
}
}
Expand All @@ -544,8 +542,16 @@ private UserClassEntity setUserClassEntity(AbstractOperation operation, Security
return userClassEntity;
}

if (frameworkSpecificEntityFound && userClassEntity.getUserClassElement() != null && !securityMetaData.getMetaData().isFoundAnnotedUserLevelServiceMethod()){
return userClassEntity;
}

if (userClassEntity.getUserClassElement() != null){
return userClassEntity;
}

// user class identification using annotations
if (userClassEntity.getUserClassElement() == null && securityMetaData.getMetaData().isFoundAnnotedUserLevelServiceMethod()) {
if (securityMetaData.getMetaData().isFoundAnnotedUserLevelServiceMethod()) {
return setUserClassEntityByAnnotation(securityMetaData.getMetaData().getServiceTrace());
}

Expand Down

0 comments on commit fed109e

Please sign in to comment.