[SYNCOPE-946] Combining jQuery and AdminLTE to provide the new EncryptedFieldPanel
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/74d8abec Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/74d8abec Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/74d8abec Branch: refs/heads/master Commit: 74d8abec6c245fc1ed763f190886cd76c2b6b52f Parents: 7b9f975 Author: Francesco Chicchiriccò <ilgro...@apache.org> Authored: Fri Sep 30 17:27:54 2016 +0200 Committer: Francesco Chicchiriccò <ilgro...@apache.org> Committed: Fri Sep 30 17:28:09 2016 +0200 ---------------------------------------------------------------------- .../console/rest/AbstractAnyRestClient.java | 3 +- .../markup/html/form/EncryptedFieldPanel.java | 39 ++++++++++++ .../client/console/wizards/any/PlainAttrs.java | 17 ++++-- .../markup/html/form/AjaxTextFieldPanel.html | 25 +++----- .../markup/html/form/EncryptedFieldPanel.html | 64 ++++++++++++++++++++ 5 files changed, 127 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/74d8abec/client/console/src/main/java/org/apache/syncope/client/console/rest/AbstractAnyRestClient.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/AbstractAnyRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/AbstractAnyRestClient.java index b287029..9d7d1d7 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/rest/AbstractAnyRestClient.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/AbstractAnyRestClient.java @@ -34,7 +34,6 @@ import org.apache.syncope.common.lib.to.ProvisioningResult; import org.apache.syncope.common.lib.types.ResourceAssociationAction; import org.apache.syncope.common.lib.types.ResourceDeassociationAction; import org.apache.syncope.common.rest.api.service.AnyService; -import org.apache.syncope.common.rest.api.service.UserService; import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; public abstract class AbstractAnyRestClient<TO extends AnyTO, P extends AnyPatch> extends BaseRestClient { @@ -63,7 +62,7 @@ public abstract class AbstractAnyRestClient<TO extends AnyTO, P extends AnyPatch result = getService(etag, getAnyServiceClass()).update(patch). readEntity(new GenericType<ProvisioningResult<TO>>() { }); - resetClient(UserService.class); + resetClient(getAnyServiceClass()); } return result; } http://git-wip-us.apache.org/repos/asf/syncope/blob/74d8abec/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.java new file mode 100644 index 0000000..10befa0 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.wicket.markup.html.form; + +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.ResourceModel; + +public class EncryptedFieldPanel extends FieldPanel<String> implements Cloneable { + + public EncryptedFieldPanel(final String id, final String name, final IModel<String> model) { + super(id, name, model); + + field = new TextField<String>("encryptedField", model) { + + @Override + protected String[] getInputTypes() { + return new String[] { "password" }; + } + }; + add(field.setLabel(new ResourceModel(name, name)).setRequired(false).setOutputMarkupId(true)); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/74d8abec/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/PlainAttrs.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/PlainAttrs.java b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/PlainAttrs.java index 96d9273..b0429ef 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/PlainAttrs.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/PlainAttrs.java @@ -33,6 +33,7 @@ import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPa import org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel; import org.apache.syncope.client.console.wicket.markup.html.form.DateTextFieldPanel; import org.apache.syncope.client.console.wicket.markup.html.form.DateTimeFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel; import org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel; import org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel; import org.apache.syncope.client.console.wizards.AjaxWizard; @@ -266,8 +267,8 @@ public class PlainAttrs extends AbstractAttrs<PlainSchemaTO> { break; case Long: - panel = new AjaxSpinnerFieldPanel.Builder<Long>() - .build("panel", schemaTO.getKey(), Long.class, new Model<Long>()); + panel = new AjaxSpinnerFieldPanel.Builder<Long>(). + build("panel", schemaTO.getKey(), Long.class, new Model<Long>()); if (required) { panel.addRequiredLabel(); @@ -275,8 +276,8 @@ public class PlainAttrs extends AbstractAttrs<PlainSchemaTO> { break; case Double: - panel = new AjaxSpinnerFieldPanel.Builder<Double>().step(0.1) - .build("panel", schemaTO.getKey(), Double.class, new Model<Double>()); + panel = new AjaxSpinnerFieldPanel.Builder<Double>().step(0.1). + build("panel", schemaTO.getKey(), Double.class, new Model<Double>()); if (required) { panel.addRequiredLabel(); @@ -291,6 +292,14 @@ public class PlainAttrs extends AbstractAttrs<PlainSchemaTO> { } break; + case Encrypted: + panel = new EncryptedFieldPanel("panel", schemaTO.getKey(), new Model<String>()); + + if (required) { + panel.addRequiredLabel(); + } + break; + default: panel = new AjaxTextFieldPanel("panel", schemaTO.getKey(), new Model<String>(), false); http://git-wip-us.apache.org/repos/asf/syncope/blob/74d8abec/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.html ---------------------------------------------------------------------- diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.html b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.html index 0b29bba..2c1b7bb 100644 --- a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.html +++ b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.html @@ -17,19 +17,14 @@ specific language governing permissions and limitations under the License. --> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org"> - <head> - <title>Ajaxt text field panel</title> - </head> - <body> - <wicket:extend> - <wicket:enclosure child="field-label"> - <label wicket:id="field-label">[LABEL]</label><span wicket:id="required"/> - <span wicket:id="jexlInfo" class="glyphicon glyphicon-info-sign" style="cursor: pointer"></span> - <span wicket:id="externalAction"/> - </wicket:enclosure> - <fieldset class="input-group"> - <input type="text" class="form-control" wicket:id="textField" placeholder=""/> - </fieldset> - </wicket:extend> - </body> + <wicket:extend> + <wicket:enclosure child="field-label"> + <label wicket:id="field-label">[LABEL]</label><span wicket:id="required"/> + <span wicket:id="jexlInfo" class="glyphicon glyphicon-info-sign" style="cursor: pointer"></span> + <span wicket:id="externalAction"/> + </wicket:enclosure> + <fieldset class="input-group"> + <input type="text" class="form-control" wicket:id="textField" placeholder=""/> + </fieldset> + </wicket:extend> </html> http://git-wip-us.apache.org/repos/asf/syncope/blob/74d8abec/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.html ---------------------------------------------------------------------- diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.html b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.html new file mode 100644 index 0000000..6a6117f --- /dev/null +++ b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/EncryptedFieldPanel.html @@ -0,0 +1,64 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org"> + <wicket:extend> + <wicket:enclosure child="field-label"> + <label wicket:id="field-label">[LABEL]</label><span wicket:id="required"/> + <span wicket:id="externalAction"/> + </wicket:enclosure> + <div class="input-group input-group-sm"> + <span class="input-group-btn"> + <button type="button" class="btn btn-warning btn-flat" + onclick="var pwd = $(this).parent().next('input'); + var children = $(this).children(); + if (pwd.is('[readonly]')) { + if (pwd.val() === '') { + pwd.removeAttr('readonly'); + children.attr('class', 'fa fa-unlock'); + } else { + bootbox.confirm('This will remove the current value. Continue?', function (result) { + if (result === true) { + pwd.removeAttr('readonly'); + pwd.val(''); + children.attr('class', 'fa fa-unlock'); + } + return true; + }); + } + } + "><i class="fa fa-lock"></i></button> + </span> + <input type="password" class="form-control" wicket:id="encryptedField" readonly="true"/> + <span class="input-group-btn"> + <button type="button" class="btn btn-primary btn-flat" + onmousedown="var pwd = $(this).parent().prev('input'); + if (!pwd.is('[readonly]')) { + pwd.attr('type', 'text'); + $(this).children().attr('class', 'fa fa-eye-slash'); + }" + onmouseup="var pwd = $(this).parent().prev('input'); + if (!pwd.is('[readonly]')) { + pwd.attr('type', 'password'); + $(this).children().attr('class', 'fa fa-eye'); + }" + ><i class="fa fa-eye"></i></button> + </span> + </div> + </wicket:extend> +</html>