/usercompatibility-sal/src/main/java/com/atlassian/sal/usercompatibility/UserManager.java

https://bitbucket.org/atlassian/user-compatibility-sal · Java · 121 lines · 18 code · 13 blank · 90 comment · 0 complexity · 3578d05d4e21bf79c6972a0a90f97419 MD5 · raw file

  1. package com.atlassian.sal.usercompatibility;
  2. import java.security.Principal;
  3. import javax.servlet.http.HttpServletRequest;
  4. import com.atlassian.sal.api.user.UserResolutionException;
  5. /**
  6. * This wraps SAL's {@link com.atlassian.sal.api.user.UserManager} to allow plugin developers to support product
  7. * version with and without the new UseyKey support (introduced in SAL v.2.10)
  8. */
  9. public interface UserManager
  10. {
  11. /**
  12. * Returns the profile of the currently logged in user or null if no user can be found.
  13. * <p/>
  14. * Getting the full {@link UserProfile} may have performance implications in some applications.
  15. * Consider using {@link #getRemoteUserKey()} if you don't need the full object.
  16. *
  17. * @return the {@link UserProfile} of the logged in user or null
  18. * @see #getRemoteUserKey()
  19. */
  20. UserProfile getRemoteUser();
  21. /**
  22. * Returns the key of the currently logged in user or null if no user can be found.
  23. *
  24. * @return the {@link UserKey} of the logged in user or null
  25. * @see #getRemoteUser()
  26. */
  27. UserKey getRemoteUserKey();
  28. /**
  29. * Returns the username of the currently logged in user or null if no user can be found.
  30. * <p/>
  31. * Getting the full {@link UserProfile} may have performance implications in some applications.
  32. * Consider using {@link #getRemoteUserKey()} if you don't need the full object.
  33. *
  34. * @param request The request to retrieve the username from
  35. * @return the {@link UserProfile} of the logged in user or null
  36. * @see #getRemoteUser()
  37. * @see #getRemoteUserKey(javax.servlet.http.HttpServletRequest)
  38. */
  39. UserProfile getRemoteUser(HttpServletRequest request);
  40. /**
  41. * Returns the key of the currently logged in user or null if no user can be found.
  42. *
  43. * @param request The request to retrieve the username from
  44. * @return The key of the currently logged in user or null
  45. * @see #getRemoteUserKey()
  46. * @see #getRemoteUser(javax.servlet.http.HttpServletRequest)
  47. */
  48. UserKey getRemoteUserKey(HttpServletRequest request);
  49. /**
  50. * Returns a {@code UserProfile object} for the specified user or null if no user can be found
  51. * @param userKey The userKey of the user whose profile is requested
  52. * @return The user's profile or null
  53. */
  54. UserProfile getUserProfile(UserKey userKey);
  55. /**
  56. * Returns a {@code UserProfile object} for the specified user or null if no user can be found
  57. * @param username The username of the user whose profile is requested
  58. * @return The user's profile or null
  59. */
  60. UserProfile getUserProfileByUsername(String username);
  61. /**
  62. * Returns whether the given user is in the given group
  63. *
  64. * @param userKey The user
  65. * @param group The group
  66. * @return {@code true} if the user is in the specified group
  67. */
  68. boolean isUserInGroup(UserKey userKey, String group);
  69. /**
  70. * Returns {@code true} or {@code false} depending on whether a user has been granted the system administrator
  71. * permission. A system administrator has full administrative permissions in the application, including permission
  72. * to perform operations that may affect the underlying operating system, such as specifying filesystem paths,
  73. * installing plugins, configuring mail servers and logging, performing backups and restores, etc. Only check for
  74. * system administrator when performing this type of operation. Operations that do not affect the underlying system
  75. * should use {@link #isAdmin(UserKey)} instead.
  76. *
  77. * @param userKey The key of the user to check
  78. * @return {@code true} or {@code false} depending on whether a user has been granted the system admin permission.
  79. * @see <a href="http://confluence.atlassian.com/display/JIRA/Managing+Global+Permissions#ManagingGlobalPermissions-About%27JIRASystemAdministrators%27and%27JIRAAdministrators%27">About 'JIRA System Administrators' and 'JIRA Administrators'</a>
  80. * @see <a href="http://confluence.atlassian.com/display/DOC/Global+Permissions+Overview#GlobalPermissionsOverview-confluenceadmin">Comparing the System Administrator with the Confluence Administrator Permission</a>
  81. */
  82. boolean isSystemAdmin(UserKey userKey);
  83. /**
  84. * Returns {@code true} or {@code false} depending on whether a user has been granted the administrator permission.
  85. * An administrator may have restricted administrative permissions that only apply to application-level
  86. * configuration that cannot affect the underlying operating system. Only check for administrator permission when
  87. * performing this type of operation. Operations that can affect security, the filesystem, or allow arbitrary code
  88. * execution must check {@link #isSystemAdmin(UserKey)} instead.
  89. * <p/>
  90. * Note that system administrator permission implies administrator permission. That is, any username for which
  91. * {@code userManager.isSystemAdmin(username)} returns {@code true} will also return {@code true} for
  92. * {@code userManager.isAdmin(username)}.
  93. *
  94. * @param userKey The user of the user to check
  95. * @return {@code true} or {@code false} depending on whether the user has been granted the admin permission
  96. * @see <a href="http://confluence.atlassian.com/display/JIRA/Managing+Global+Permissions#ManagingGlobalPermissions-About%27JIRASystemAdministrators%27and%27JIRAAdministrators%27">About 'JIRA System Administrators' and 'JIRA Administrators'</a>
  97. * @see <a href="http://confluence.atlassian.com/display/DOC/Global+Permissions+Overview#GlobalPermissionsOverview-confluenceadmin">Comparing the System Administrator with the Confluence Administrator Permission</a>
  98. */
  99. boolean isAdmin(UserKey userKey);
  100. /**
  101. * @see {@link com.atlassian.sal.api.user.UserManager#authenticate(String, String)}
  102. */
  103. boolean authenticate(String username, String password);
  104. /**
  105. * @see {@link com.atlassian.sal.api.user.UserManager#resolve(String)}
  106. */
  107. Principal resolve(String username) throws UserResolutionException;
  108. }