cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

Extract user name from Session Atribute field

ajdimanuel
Inactive

Hi,

I am trying to extract Username field from a Session Atribute. The Username is APP1000, I am trying whith RegExp but I dont get it:

"org.springframework.security.core.context.SecurityContextImpl@b03d8ffe: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@b03d8ffe: Principal: org.springframework.security.core.userdetails.User@b03d3ca6: Username: APP10000; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Not granted any authorities; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@ffff4c9c: RemoteIpAddress: 62.81.229.130; SessionId: c4OjFbX2lWGx6Q42eUKuTXn; Not granted any authorities"

Could you help me?

Thanks.

11 REPLIES 11

Babar_Qayyum
DynaMight Leader
DynaMight Leader

Hello Alberto,

I guess it is very straightforward to extract the user name from session attribute if you know the exact name of "Attribute"

Please see the below screenshot.

Regards,

Babar

felipe_estrella
Inactive

Hello, Alberto!

Can you try this one?

(?<=Username: )(.*)(?=; Password)

Regards,

Felipe

rob_vollum
Dynatrace Pro
Dynatrace Pro

Hi Alberto,

You may want to consider this one:

Username: ([^;]*)

which is more specific than the one mentioned above and therefore executes a bit more efficiently. According to the regex utility "regex101.com", it will execute and return your match in about 30 steps, as opposed to about 2449 steps for the one above.

Rob

Indeed! 😃

ajdimanuel
Inactive

Hi,

the Session Attribute field is named SECURITY_CONTEXT, so I have configured the measure as Session Attribute. Session Attribute: SECURITY_CONTEXT match regex ; Questions:

1- Value: Should I put again SECURITY_CONTEXT¿?. ,

2- Transformatioj regex, this one Username: ([^;]*)?

I suppose this is wrong because I cannot see yet tagged visits.

Thanks in advance.

Let's go one step at a time. First thing to do is to make sure you are capturing the Session Attribute. You do this by configuring the properties of the Servlet Sensor. This will take effect immediately.

Once this is done, the next thing is to find a PurePath that you know will have this SECURITY_CONTEXT attribute. Right-click on the PurePath tree and look at the Details. You should see that attribute captured on the PurePath.

Once you see the attribute being captured on your PurePaths, then you can troubleshoot your measure definition if it is not working. The way you've described it (creating the measure, with the transformation regex) looks right (at least at the high level). If it's not working, perhaps you can include a screen shot of the definition.

Rob

ajdimanuel
Inactive

I don't have a problem in the first step but in the second one while defining the Regex measure. I have attached the screenshot.

Thanks.

jerry_lobenstei
Dynatrace Advisor
Dynatrace Advisor

Your session attribute and regex are correct. Remove the value entry.

ajdimanuel
Inactive

It is mandatory to type a value, I got message "The regular expression value for match cannot be empty.

rob_vollum
Dynatrace Pro
Dynatrace Pro

In the "Match" field you do not want "regex". Please leave it as it defaulted, which is "contains", and leave the Value field blank. That will work fine. What that means is that you don't care what's in the Value - you will match anything. Then you apply the Transformation RegEx to that, which will pull out your user name. 🙂

ajdimanuel
Inactive

It works!

Thanks a lot!!!!