Getting current user on custom Condition for web-item

I’m truing to get access to current user details on custom condition class. My class implements the com.atlassian.plugin.web.Condition and on shouldDisplay(Map<String, Object> context) context is see member currentUser. That is however typed com.atlassian.stash.internal.user.InternalNormalUser and the “internal” suggests me that I shouldn’t try to use that. I haven’t even checked whether I can include that, but I guess that’s not possible either.

So how should I get access the to the current user on the shouldDisplay() ?

InternalNormalUser ultimately implements ApplicationUser – You’re safe to use that variable mate. :slight_smile:

1 Like

I know this was marked as solved, but to get rid of the internal, you can inject AuthenticationContext in the constructor use it like:

public class MyCondition implements Condition {
    @ComponentImport
    private final AuthenticationContext authenticationContext;

    public MyCondition(AuthenticationContext authenticationContext) {
        this.authenticationContext = authenticationContext;
    }

    @Override
    public boolean shouldDisplay(Map<String, Object> map) {
        ApplicationUser user = authenticationContext.getCurrentUser();
        return user != null; // Check whatever is needed.
    }
}