Package com.atlassian.connect.spring
Class AtlassianHostUser
- java.lang.Object
-
- com.atlassian.connect.spring.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
Userand can be resolved as a Spring MVC controller argument by using theAuthenticationPrincipalannotation:@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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAtlassianHostUser.AtlassianHostUserBuilderBuilder used to create anAtlassianHostUser.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAtlassianHostUser()Creates a new empty Atlassian host principal (used for deserialization).AtlassianHostUser(AtlassianHost host, Optional<String> optionalUserKey)Deprecated.as of 1.5.0 with migration to Atlassian Account ID, replaced byAtlassianHostUser.AtlassianHostUserBuilder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AtlassianHostUser.AtlassianHostUserBuilderbuilder(AtlassianHost host)Creates anAtlassianHostUser.AtlassianHostUserBuilderusing the provided host.booleanequals(Object o)AtlassianHostgetHost()Returns the host from which the request originated.Optional<String>getUserAccountId()The Atlassian Account ID of the user on whose behalf a request was made.Optional<String>getUserKey()Deprecated.as of 1.5.0 with migration to Atlassian Account IDinthashCode()StringtoString()
-
-
-
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 byAtlassianHostUser.AtlassianHostUserBuilderCreates a new Atlassian host principal.- Parameters:
host- the host from which the request originatedoptionalUserKey- the key of the user on whose behalf a request was made (optional)
-
-
Method Detail
-
getHost
public AtlassianHost getHost()
Returns the host from which the request originated.- Returns:
- the Atlassian host
-
getUserKey
@Deprecated public Optional<String> getUserKey()
Deprecated.as of 1.5.0 with migration to Atlassian Account IDThe the key of the user on whose behalf a request was made.- Returns:
- the user key
-
getUserAccountId
public Optional<String> getUserAccountId()
The Atlassian Account ID of the user on whose behalf a request was made.- Returns:
- the Atlassian Account ID
-
builder
public static AtlassianHostUser.AtlassianHostUserBuilder builder(AtlassianHost host)
Creates anAtlassianHostUser.AtlassianHostUserBuilderusing the provided host.- Parameters:
host- the host to create the AtlassianHostUser for- Returns:
- a builder.
-
-