PageRenderTime 35ms CodeModel.GetById 30ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
24package hudson.model;
25
26import hudson.EnvVars;
27import hudson.util.Secret;
28import hudson.util.VariableResolver;
29import org.kohsuke.stapler.DataBoundConstructor;
30
31import java.util.Locale;
32
33/**
34 * @author Kohsuke Kawaguchi
35 */
36public class PasswordParameterValue extends ParameterValue {
37
38    private final Secret value;
39
40    // kept for backward compatibility
41    public PasswordParameterValue(String name, String value) {
42        this(name, value, null);
43    }
44
45    @DataBoundConstructor
46    public PasswordParameterValue(String name, String value, String description) {
47        super(name, description);
48        this.value = Secret.fromString(value);
49    }
50
51    @Override
52    public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
53        String v = Secret.toString(value);
54        env.put(name, v);
55        env.put(name.toUpperCase(Locale.ENGLISH),v); // backward compatibility pre 1.345
56    }
57
58    @Override
59    public VariableResolver<String> createVariableResolver(AbstractBuild<?, ?> build) {
60        return new VariableResolver<String>() {
61            public String resolve(String name) {
62                return PasswordParameterValue.this.name.equals(name) ? Secret.toString(value) : null;
63            }
64        };
65    }
66
67    @Override
68    public boolean isSensitive() {
69        return true;
70}
71}