提交 ad1c0a0b 编写于 作者: K kohsuke

<input type='hidden'> field shouldn't be getting the plain text password value.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@32853 71c3de6d-444a-0410-be80-ed276b4c234a
上级 bb55503f
......@@ -66,6 +66,7 @@ import hudson.util.Area;
import hudson.util.Iterators;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.util.Secret;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
......@@ -1234,6 +1235,15 @@ public class Functions {
}
}
}
/**
* Used by &lt;f:password/> so that we send an encrypted value to the client.
*/
public String getPasswordValue(Object o) {
if (o==null) return null;
if (o instanceof Secret) return ((Secret)o).getEncryptedValue();
return o.toString();
}
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
......
......@@ -55,7 +55,7 @@ THE SOFTWARE.
<m:input xmlns:m="jelly:hudson.util.jelly.MorphTagLibrary"
class="setting-input ${attrs.checkUrl!=null?'validated ':''}${attrs.clazz}"
name ="${attrs.name ?: '_.'+attrs.field}"
value="${attrs.value ?: instance[attrs.field]}"
value="${h.getPasswordValue(attrs.value ?: instance[attrs.field])}"
type="password"
ATTRIBUTES="${attrs}" EXCEPT="field clazz" />
</j:jelly>
/*
* The MIT License
*
* Copyright (c) 2004-2010, InfraDNA, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lib.form;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.util.Secret;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class PasswordTest extends HudsonTestCase implements Describable<PasswordTest> {
public Secret secret;
public void test1() throws Exception {
secret = Secret.fromString("secret");
HtmlPage p = createWebClient().goTo("self/test1");
String value = ((HtmlInput)p.getElementById("password")).getValueAttribute();
assertFalse("password shouldn't be plain text",value.equals("secret"));
assertEquals("secret",Secret.fromString(value).getPlainText());
}
public DescriptorImpl getDescriptor() {
return hudson.getDescriptorByType(DescriptorImpl.class);
}
@Extension
public static final class DescriptorImpl extends Descriptor<PasswordTest> {
public String getDisplayName() {
return null;
}
}
}
<!--
The MIT License
Copyright (c) 2010, InfraDNA, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
Config page
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<l:layout title="Making sure the password field gets an encrypted value">
<l:main-panel>
<f:form method="post" name="config" action="thisFormWillNotBeSubmitted">
<j:set var="instance" value="${it}" />
<j:set var="descriptor" value="${it.descriptor}" />
<f:entry field="secret">
<f:password id="password" />
</f:entry>
</f:form>
</l:main-panel>
</l:layout>
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册