PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/jira/plugins/bitbucket/webwork/GitHubOAuth2.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 83 lines | 60 code | 17 blank | 6 comment | 1 complexity | 3c81ab5e0ff4817d4de886aea031ec0a MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.webwork;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import com.atlassian.jira.web.action.JiraWebActionSupport;
  5. import com.atlassian.sal.api.ApplicationProperties;
  6. import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
  7. /**
  8. * Webwork action to handle OAuth callback URL from github configured from instructions in jira-github-connector
  9. * Remove in the future versions of the plugin.
  10. */
  11. @Deprecated
  12. public class GitHubOAuth2 extends JiraWebActionSupport
  13. {
  14. private final Logger log = LoggerFactory.getLogger(GitHubOAuth2.class);
  15. private final PluginSettingsFactory pluginSettingsFactory;
  16. private String code;
  17. private String error;
  18. private String redirectUrl;
  19. private final ApplicationProperties applicationProperties;
  20. public GitHubOAuth2(PluginSettingsFactory pluginSettingsFactory, ApplicationProperties applicationProperties)
  21. {
  22. this.pluginSettingsFactory = pluginSettingsFactory;
  23. this.applicationProperties = applicationProperties;
  24. }
  25. @Override
  26. protected String doExecute() throws Exception
  27. {
  28. log.debug("Handling old (from jira-github-connector) callback Url. Arguments are error: ["+error+"], code=["+code+"]");
  29. if ("redirect_uri_mismatch".equals(error))
  30. {
  31. // github didn't like our redirect url because the currently registed application is github has points elsewhere
  32. redirectUrl = (String) pluginSettingsFactory.createGlobalSettings().get("OAuthRedirectUrl");
  33. return getRedirect(redirectUrl);
  34. }
  35. String parameters = (String) pluginSettingsFactory.createGlobalSettings().get("OAuthRedirectUrlParameters");
  36. redirectUrl = "/secure/admin/AddGithubRepository!finish.jspa?"+parameters+"&code="+code;
  37. // clean up
  38. pluginSettingsFactory.createGlobalSettings().remove("OAuthRedirectUrl");
  39. pluginSettingsFactory.createGlobalSettings().remove("OAuthRedirectUrlParameters");
  40. return SUCCESS;
  41. }
  42. public String getRedirectUrl()
  43. {
  44. return redirectUrl;
  45. }
  46. public String getError()
  47. {
  48. return error;
  49. }
  50. public void setError(String error)
  51. {
  52. this.error = error;
  53. }
  54. public String getCode()
  55. {
  56. return code;
  57. }
  58. public void setCode(String code)
  59. {
  60. this.code = code;
  61. }
  62. public String getBaseUrl()
  63. {
  64. return applicationProperties.getBaseUrl();
  65. }
  66. }