Repository navigation
Password component #2000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shravani-0811
wants to merge
7
commits into
dev
Choose a base branch
from
password-component-clean
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Password component #2000
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d1f63e
Adding Password Component
shravani-0811 a526e9a
Fix tests
shravani-0811 0cace35
Address comments
shravani-0811 ff6d22d
Address comments
shravani-0811 568cb38
Update passwordinput.html
shravani-0811 49e9830
Address comment
shravani-0811 93a31a0
Address comments
shravani-0811 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...in/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordInputImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2026 Adobe | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
| package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import org.apache.sling.api.SlingHttpServletRequest; | ||
| import org.apache.sling.api.resource.Resource; | ||
| import org.apache.sling.models.annotations.Default; | ||
| import org.apache.sling.models.annotations.Exporter; | ||
| import org.apache.sling.models.annotations.Model; | ||
| import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
| import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import com.adobe.cq.export.json.ComponentExporter; | ||
| import com.adobe.cq.export.json.ExporterConstants; | ||
| import com.adobe.cq.forms.core.components.internal.form.FormConstants; | ||
| import com.adobe.cq.forms.core.components.internal.form.ReservedProperties; | ||
| import com.adobe.cq.forms.core.components.models.form.FieldType; | ||
| import com.adobe.cq.forms.core.components.models.form.PasswordInput; | ||
| import com.adobe.cq.forms.core.components.util.AbstractFieldImpl; | ||
|
|
||
| @Model( | ||
| adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
| adapters = { PasswordInput.class, ComponentExporter.class }, | ||
| resourceType = { FormConstants.RT_FD_FORM_PASSWORD_V1 }) | ||
| @Exporter( | ||
| name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, | ||
| extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
| public class PasswordInputImpl extends AbstractFieldImpl implements PasswordInput { | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_PATTERN) | ||
| @Nullable | ||
| protected String pattern; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_AUTOCOMPLETE) | ||
| @Nullable | ||
| protected String autocomplete; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_SHOW_HIDE_PASSWORD) | ||
| @Default(booleanValues = true) | ||
| protected boolean showHidePassword; | ||
|
|
||
| @Override | ||
| public String getFieldType() { | ||
| return super.getFieldType(FieldType.PASSWORD); | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public Object[] getDefault() { | ||
| // password values must never be exposed in rendered markup or the exported JSON model, | ||
| // regardless of how the underlying property was set (authoring dialog, direct content write, etc.) | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public Integer getMinLength() { | ||
| return minLength; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public Integer getMaxLength() { | ||
| return maxLength; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public String getPattern() { | ||
| return pattern; | ||
| } | ||
|
|
||
| @Override | ||
| public String getAutoComplete() { | ||
| return autocomplete; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isShowHidePasswordEnabled() { | ||
| return showHidePassword; | ||
| } | ||
|
|
||
| /** | ||
| * Exposes {@code showHidePassword} as the OOTB {@code fd:}-prefixed custom property so it is available to headless | ||
| * clients (the boolean getter above is only a convenience for the HTL rendering path and is not itself serialized). | ||
| */ | ||
| @Override | ||
| public @NotNull Map<String, Object> getProperties() { | ||
| Map<String, Object> properties = new LinkedHashMap<>(super.getProperties()); | ||
| properties.put(ReservedProperties.FD_SHOW_HIDE_PASSWORD, showHidePassword); | ||
| return properties; | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...s/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/PasswordInput.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2026 Adobe | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
| package com.adobe.cq.forms.core.components.models.form; | ||
|
|
||
| import org.jetbrains.annotations.Nullable; | ||
| import org.osgi.annotation.versioning.ConsumerType; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Defines the form {@code Password} Sling Model used for the | ||
| * {@code /apps/core/fd/components/form/passwordinput/v1/passwordinput} component. | ||
| * | ||
| * <p> | ||
| * Password is modelled as a first-class field type (rather than a variant of {@link TextInput}) so that the | ||
| * password-specific contract (visibility toggle, default-value masking, credential autofill tokens) does not leak | ||
| * into the text, email and telephone components that share {@code TextInput}. | ||
| * </p> | ||
| * | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.13.0 | ||
| */ | ||
| @ConsumerType | ||
| public interface PasswordInput extends Field, StringConstraint { | ||
|
|
||
| /** | ||
| * Returns {@code true} if the password show/hide visibility toggle should be rendered, otherwise {@code false}. | ||
| * | ||
| * @return {@code true} if the visibility toggle should be rendered, otherwise {@code false} | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.13.0 | ||
| */ | ||
| @JsonIgnore | ||
| default boolean isShowHidePasswordEnabled() { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Returns {@code "off"} if autocomplete is disabled, otherwise the configured autofill token (for example | ||
| * {@code new-password} or {@code current-password}) @see | ||
| * <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete">here</a>. | ||
| * | ||
| * @return the autocomplete attribute value, or {@code null} if not set | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.13.0 | ||
| */ | ||
| @JsonProperty("autocomplete") | ||
| @Nullable | ||
| default String getAutoComplete() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the format of the form field as specified in the json schema specification. Password fields have no | ||
| * format by default. | ||
| * | ||
| * @return the format of the form field | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.13.0 | ||
| */ | ||
| @Override | ||
| @Nullable | ||
| default String getFormat() { | ||
| return null; | ||
| } | ||
|
|
||
| } |
84 changes: 84 additions & 0 deletions
84
...ava/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordInputImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2026 Adobe | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
| package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import com.adobe.cq.forms.core.Utils; | ||
| import com.adobe.cq.forms.core.components.internal.form.FormConstants; | ||
| import com.adobe.cq.forms.core.components.models.form.FieldType; | ||
| import com.adobe.cq.forms.core.components.models.form.PasswordInput; | ||
| import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext; | ||
| import io.wcm.testing.mock.aem.junit5.AemContext; | ||
| import io.wcm.testing.mock.aem.junit5.AemContextExtension; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| @ExtendWith(AemContextExtension.class) | ||
| public class PasswordInputImplTest { | ||
| private static final String BASE = "/form/textinput"; | ||
| private static final String CONTENT_ROOT = "/content"; | ||
| private static final String PATH_PASSWORD = CONTENT_ROOT + "/password-textinput"; | ||
| private static final String PATH_PASSWORD_TOGGLE_DISABLED = CONTENT_ROOT + "/password-textinput-toggle-disabled"; | ||
|
|
||
| private final AemContext context = FormsCoreComponentTestContext.newAemContext(); | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT); | ||
| } | ||
|
|
||
| @Test | ||
| void testFieldType() { | ||
| PasswordInput passwordInput = Utils.getComponentUnderTest(PATH_PASSWORD, PasswordInput.class, context); | ||
| assertEquals(FieldType.PASSWORD.getValue(), passwordInput.getFieldType()); | ||
| assertEquals(FormConstants.RT_FD_FORM_PASSWORD_V1, passwordInput.getExportedType()); | ||
| } | ||
|
|
||
| @Test | ||
| void testShowHidePasswordEnabledByDefault() { | ||
| PasswordInput passwordInput = Utils.getComponentUnderTest(PATH_PASSWORD, PasswordInput.class, context); | ||
| assertTrue(passwordInput.isShowHidePasswordEnabled()); | ||
| PasswordInput passwordInputMock = Mockito.mock(PasswordInput.class); | ||
| Mockito.when(passwordInputMock.isShowHidePasswordEnabled()).thenCallRealMethod(); | ||
| assertTrue(passwordInputMock.isShowHidePasswordEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| void testShowHidePasswordCanBeDisabled() { | ||
| PasswordInput passwordInput = Utils.getComponentUnderTest(PATH_PASSWORD_TOGGLE_DISABLED, PasswordInput.class, context); | ||
| assertFalse(passwordInput.isShowHidePasswordEnabled()); | ||
| } | ||
|
|
||
| @Test | ||
| void testDefaultValueIsMaskedForPassword() { | ||
| // password default values must never be exposed in the exported model, regardless of stored content | ||
| PasswordInput passwordInput = Utils.getComponentUnderTest(PATH_PASSWORD, PasswordInput.class, context); | ||
| assertNull(passwordInput.getDefault()); | ||
| } | ||
|
|
||
| @Test | ||
| void testJSONExport() throws Exception { | ||
| PasswordInput passwordInput = Utils.getComponentUnderTest(PATH_PASSWORD, PasswordInput.class, context); | ||
| Utils.testJSONExport(passwordInput, Utils.getTestExporterJSONPath(BASE, PATH_PASSWORD)); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
bundles/af-core/src/test/resources/form/textinput/exporter-password-textinput.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "id": "passwordinput-5c6da9d601", | ||
| "fieldType": "password", | ||
| "name": "abc", | ||
| "type": "string", | ||
| "minLength": 8, | ||
| "maxLength": 20, | ||
| "pattern": "^[a-zA-Z0-9]+$", | ||
| "label": { | ||
| "value": "def" | ||
| }, | ||
| "properties": { | ||
| "fd:showHidePassword": true, | ||
| "fd:path": "/content/password-textinput" | ||
| }, | ||
| "events": { | ||
| "custom:setProperty": [ | ||
| "$event.payload" | ||
| ] | ||
| }, | ||
| ":type": "core/fd/components/form/passwordinput/v1/passwordinput" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ontent/jcr_root/apps/forms-components-examples/components/form/passwordinput/.content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" | ||
| jcr:primaryType="cq:Component" | ||
| jcr:title="Adaptive Form Password Input" | ||
| jcr:description="Add a field to capture passwords, with an optional show/hide toggle." | ||
| sling:resourceSuperType="core/fd/components/form/passwordinput/v1/passwordinput" | ||
| componentGroup="Core Components Examples - Adaptive Form"/> |
6 changes: 6 additions & 0 deletions
6
...nt/jcr_root/apps/forms-components-examples/components/form/passwordinput/_cq_template.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" | ||
| jcr:primaryType="nt:unstructured" | ||
| jcr:title="Password Input" | ||
| autocomplete="new-password" | ||
| fieldType="password"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.