Skip to content

Commit 92b2a70

Browse files
committed
#841 added the attribute render-value which sends the password to the client if the programmer insists on doing so
1 parent b81e70e commit 92b2a70

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

src/main/java/net/bootsfaces/component/inputSecret/InputSecret.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package net.bootsfaces.component.inputSecret;
2020

2121
import javax.faces.component.FacesComponent;
22-
import net.bootsfaces.C;
2322

23+
import net.bootsfaces.C;
2424
import net.bootsfaces.component.inputText.InputText;
2525

2626
/**
@@ -30,7 +30,49 @@
3030

3131
@FacesComponent(InputSecret.COMPONENT_TYPE)
3232
public class InputSecret extends InputText {
33-
34-
public static final String COMPONENT_TYPE=C.BSFCOMPONENT + ".inputSecret.InputSecret";
35-
33+
34+
public static final String COMPONENT_TYPE = C.BSFCOMPONENT + ".inputSecret.InputSecret";
35+
36+
protected enum PropertyKeys {
37+
renderValue;
38+
String toString;
39+
40+
PropertyKeys(String toString) {
41+
this.toString = toString;
42+
}
43+
44+
PropertyKeys() {
45+
}
46+
47+
public String toString() {
48+
return ((this.toString != null) ? this.toString : super.toString());
49+
}
50+
}
51+
52+
/**
53+
* By default, the value of the password field is never sent to the client.
54+
* However, if you need to send the value to the client for some reason, you can
55+
* set this flag to true. Please make sure that this is not a security hole. The
56+
* password may be unreadable on the screen, but hackers can read it easily.
57+
* <P>
58+
*
59+
* @return Returns the value of the attribute, or false, if it hasn't been set
60+
* by the JSF file.
61+
*/
62+
public boolean isRenderValue() {
63+
return (boolean) (Boolean) getStateHelper().eval(PropertyKeys.renderValue, false);
64+
}
65+
66+
/**
67+
* By default, the value of the password field is never sent to the client.
68+
* However, if you need to send the value to the client for some reason, you can
69+
* set this flag to true. Please make sure that this is not a security hole. The
70+
* password may be unreadable on the screen, but hackers can read it easily.
71+
* <P>
72+
* Usually this method is called internally by the JSF engine.
73+
*/
74+
public void setRenderValue(boolean _renderValue) {
75+
getStateHelper().put(PropertyKeys.renderValue, _renderValue);
76+
}
77+
3678
}

src/main/java/net/bootsfaces/component/inputText/InputTextRenderer.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ public void decode(FacesContext context, UIComponent component, List<String> leg
7474
}
7575
String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(name);
7676
if (inputText instanceof InputSecret) {
77-
if ("*******".equals(submittedValue)) {
78-
submittedValue = null;
77+
if (!((InputSecret)inputText).isRenderValue()) {
78+
if ("*******".equals(submittedValue)) {
79+
submittedValue = null;
80+
}
7981
}
8082
}
8183

@@ -232,9 +234,11 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
232234
}
233235

234236
String v = getValue2Render(context, component);
235-
if (component instanceof InputSecret) {
236-
if (v != null && v.length()> 0) {
237-
v = "*******";
237+
if (inputText instanceof InputSecret) {
238+
if (!((InputSecret) inputText).isRenderValue()) {
239+
if (v != null && v.length() > 0) {
240+
v = "*******";
241+
}
238242
}
239243
}
240244
if (v != null && v.length()> 0) {

0 commit comments

Comments
 (0)