You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExternalUsersProvider.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.api.security;
  21. import javax.annotation.Nullable;
  22. import javax.servlet.http.HttpServletRequest;
  23. /**
  24. * Note that prefix "do" for names of methods is reserved for future enhancements, thus should not be used in subclasses.
  25. *
  26. * @see SecurityRealm
  27. * @since 2.14
  28. */
  29. public abstract class ExternalUsersProvider {
  30. /**
  31. * Override this method in order load user information.
  32. *
  33. * @return the user, or null if user doesn't exist
  34. * @throws RuntimeException in case of unexpected error such as connection failure
  35. * @since 3.1
  36. */
  37. public UserDetails doGetUserDetails(Context context) {
  38. return null;
  39. }
  40. public static final class Context {
  41. private String username;
  42. private HttpServletRequest request;
  43. public Context(@Nullable String username, HttpServletRequest request) {
  44. this.username = username;
  45. this.request = request;
  46. }
  47. public String getUsername() {
  48. return username;
  49. }
  50. public HttpServletRequest getRequest() {
  51. return request;
  52. }
  53. }
  54. }