/hudson-core/src/main/java/hudson/model/PasswordParameterValue.java

http://github.com/hudson/hudson · Java · 71 lines · 35 code · 9 blank · 27 comment · 0 complexity · 0123ac2e3726d157537ce72ef9aed1bd MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Romain Seguy, Yahoo! Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.model;
  25. import hudson.EnvVars;
  26. import hudson.util.Secret;
  27. import hudson.util.VariableResolver;
  28. import org.kohsuke.stapler.DataBoundConstructor;
  29. import java.util.Locale;
  30. /**
  31. * @author Kohsuke Kawaguchi
  32. */
  33. public class PasswordParameterValue extends ParameterValue {
  34. private final Secret value;
  35. // kept for backward compatibility
  36. public PasswordParameterValue(String name, String value) {
  37. this(name, value, null);
  38. }
  39. @DataBoundConstructor
  40. public PasswordParameterValue(String name, String value, String description) {
  41. super(name, description);
  42. this.value = Secret.fromString(value);
  43. }
  44. @Override
  45. public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
  46. String v = Secret.toString(value);
  47. env.put(name, v);
  48. env.put(name.toUpperCase(Locale.ENGLISH),v); // backward compatibility pre 1.345
  49. }
  50. @Override
  51. public VariableResolver<String> createVariableResolver(AbstractBuild<?, ?> build) {
  52. return new VariableResolver<String>() {
  53. public String resolve(String name) {
  54. return PasswordParameterValue.this.name.equals(name) ? Secret.toString(value) : null;
  55. }
  56. };
  57. }
  58. @Override
  59. public boolean isSensitive() {
  60. return true;
  61. }
  62. }