Class AtlassianHostUser


  • public final class AtlassianHostUser
    extends Object
    The Spring Security authentication principal for requests coming from an Atlassian host application in which the add-on is installed.

    This class is the Atlassian Connect equivalent of Spring Security's User and can be resolved as a Spring MVC controller argument by using the AuthenticationPrincipal annotation:

     @Controller
     public class HelloWorldController {
    
         @RequestMapping(value = "/helloWorld", method = GET)
         public String (@AuthenticationPrincipal AtlassianHostUser hostUser) {
             ...
         }
     }

    Outside of the context of a controller, the current authentication principal can be obtained programmatically via SecurityContextHolder:

     Optional<AtlassianHostUser> optionalHostUser = Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
             .map(Authentication::getPrincipal)
             .filter(AtlassianHostUser.class::isInstance)
             .map(AtlassianHostUser.class::cast);
    Since:
    1.0.0
    • Constructor Detail

      • AtlassianHostUser

        protected AtlassianHostUser()
        Creates a new empty Atlassian host principal (used for deserialization).
      • AtlassianHostUser

        @Deprecated
        public AtlassianHostUser​(AtlassianHost host,
                                 Optional<String> optionalUserKey)
        Deprecated.
        as of 1.5.0 with migration to Atlassian Account ID, replaced by AtlassianHostUser.AtlassianHostUserBuilder
        Creates a new Atlassian host principal.
        Parameters:
        host - the host from which the request originated
        optionalUserKey - the key of the user on whose behalf a request was made (optional)