PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/jira/plugins/bitbucket/spi/github/webwork/ConfigureGithubOAuth.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 101 lines | 77 code | 20 blank | 4 comment | 3 complexity | f27f9604d0757cd387e4b450f701cfeb MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.spi.github.webwork;
  2. import org.apache.commons.lang.StringUtils;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import com.atlassian.jira.plugins.bitbucket.spi.github.GithubOAuth;
  6. import com.atlassian.jira.security.xsrf.RequiresXsrfCheck;
  7. import com.atlassian.jira.web.action.JiraWebActionSupport;
  8. import com.atlassian.sal.api.ApplicationProperties;
  9. public class ConfigureGithubOAuth extends JiraWebActionSupport
  10. {
  11. final Logger logger = LoggerFactory.getLogger(ConfigureGithubOAuth.class);
  12. private final GithubOAuth githubOAuth;
  13. private final ApplicationProperties applicationProperties;
  14. public ConfigureGithubOAuth(GithubOAuth githubOAuth, ApplicationProperties applicationProperties)
  15. {
  16. this.githubOAuth = githubOAuth;
  17. this.applicationProperties = applicationProperties;
  18. }
  19. @Override
  20. protected void doValidation()
  21. {
  22. if (StringUtils.isBlank(clientSecret) || StringUtils.isBlank(clientID))
  23. {
  24. addErrorMessage("Please enter both the GitHub OAuth Client ID and Client Secret.");
  25. }
  26. }
  27. @Override
  28. @RequiresXsrfCheck
  29. protected String doExecute() throws Exception
  30. {
  31. if (!getHasErrorMessages())
  32. {
  33. // TODO test identifiers if they are correct
  34. addClientIdentifiers();
  35. }
  36. return INPUT;
  37. }
  38. private void addClientIdentifiers()
  39. {
  40. githubOAuth.setClient(clientID, clientSecret);
  41. messages = "GitHub Client Identifiers Set Correctly";
  42. }
  43. public String getSavedClientSecret()
  44. {
  45. return githubOAuth.getClientSecret();
  46. }
  47. public String getSavedClientID()
  48. {
  49. return githubOAuth.getClientId();
  50. }
  51. // Client ID (from GitHub OAuth Application)
  52. private String clientID = "";
  53. public void setClientID(String value)
  54. {
  55. this.clientID = value;
  56. }
  57. public String getClientID()
  58. {
  59. return this.clientID;
  60. }
  61. // Client Secret (from GitHub OAuth Application)
  62. private String clientSecret = "";
  63. public void setClientSecret(String value)
  64. {
  65. this.clientSecret = value;
  66. }
  67. public String getClientSecret()
  68. {
  69. return this.clientSecret;
  70. }
  71. // Confirmation Messages
  72. private String messages = "";
  73. public String getMessages()
  74. {
  75. return this.messages;
  76. }
  77. public String getBaseUrl()
  78. {
  79. return applicationProperties.getBaseUrl();
  80. }
  81. }