Search in sources :

Example 1 with PasswordPanel

use of com.evolveum.midpoint.gui.api.component.password.PasswordPanel in project midpoint by Evolveum.

the class ChangePasswordPanel method initLayout.

private void initLayout(final boolean oldPasswordVisible) {
    model = (LoadableModel<MyPasswordsDto>) getModel();
    Label oldPasswordLabel = new Label(ID_OLD_PASSWORD_LABEL, createStringResource("PageSelfCredentials.oldPasswordLabel"));
    add(oldPasswordLabel);
    oldPasswordLabel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return oldPasswordVisible;
        }
    });
    Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
    add(passwordLabel);
    PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<String>(model, MyPasswordsDto.F_OLD_PASSWORD));
    oldPasswordField.setRequired(false);
    oldPasswordField.setResetPassword(false);
    add(oldPasswordField);
    oldPasswordField.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        public boolean isVisible() {
            return oldPasswordVisible;
        }

        ;
    });
    PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<ProtectedStringType>(model, MyPasswordsDto.F_PASSWORD));
    passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
    add(passwordPanel);
    WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
    List<IColumn<PasswordAccountDto, String>> columns = initColumns();
    ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<PasswordAccountDto>(this, new PropertyModel<List<PasswordAccountDto>>(model, MyPasswordsDto.F_ACCOUNTS));
    TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
    accounts.setItemsPerPage(30);
    accounts.setShowPaging(false);
    if (model.getObject().getPropagation() != null && model.getObject().getPropagation().equals(CredentialsPropagationUserControlType.MAPPING)) {
        accountContainer.setVisible(false);
    }
    accountContainer.add(accounts);
    AjaxLink help = new AjaxLink(ID_BUTTON_HELP) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHelpPerformed(target);
        }
    };
    accountContainer.add(help);
    add(accountContainer);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) Label(org.apache.wicket.markup.html.basic.Label) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TablePanel(com.evolveum.midpoint.web.component.data.TablePanel)

Example 2 with PasswordPanel

use of com.evolveum.midpoint.gui.api.component.password.PasswordPanel in project midpoint by Evolveum.

the class ChangePasswordPanel method initLayout.

private void initLayout() {
    WebMarkupContainer oldPasswordContainer = new WebMarkupContainer(ID_OLD_PASSWORD_CONTAINER);
    oldPasswordContainer.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isCheckOldPassword();
        }
    });
    add(oldPasswordContainer);
    PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<>(getModel(), MyPasswordsDto.F_OLD_PASSWORD));
    oldPasswordField.setRequired(false);
    oldPasswordContainer.add(oldPasswordField);
    Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
    add(passwordLabel);
    PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<>(getModel(), MyPasswordsDto.F_PASSWORD), getModelObject().getFocus(), getPageBase()) {

        @Override
        protected <F extends FocusType> ValuePolicyType getValuePolicy(PrismObject<F> object) {
            return getModelObject().getFocusPolicy();
        }

        @Override
        protected void updatePasswordValidation(AjaxRequestTarget target) {
            super.updatePasswordValidation(target);
            limitationsByPolicyOid.clear();
            getTable().visitChildren(PasswordPolicyValidationPanel.class, (IVisitor<PasswordPolicyValidationPanel, PasswordPolicyValidationPanel>) (panel, iVisit) -> {
                panel.refreshValidationPopup(target);
            });
        }
    };
    passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
    add(passwordPanel);
    WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
    List<IColumn<PasswordAccountDto, String>> columns = initColumns();
    ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<>(this, new PropertyModel<>(getModel(), MyPasswordsDto.F_ACCOUNTS));
    TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
    accounts.setItemsPerPage(30);
    accounts.setShowPaging(false);
    accountContainer.add(accounts);
    accountContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return shouldShowPasswordPropagation();
        }
    });
    add(accountContainer);
}
Also used : PageSelfCredentials(com.evolveum.midpoint.web.page.self.PageSelfCredentials) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) StringUtils(org.apache.commons.lang3.StringUtils) AuthUtil(com.evolveum.midpoint.authentication.api.util.AuthUtil) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) AbstractColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn) TablePanel(com.evolveum.midpoint.web.component.data.TablePanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Label(org.apache.wicket.markup.html.basic.Label) ProgressReportActivityDto(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto) Model(org.apache.wicket.model.Model) LabelWithHelpPanel(com.evolveum.midpoint.gui.api.component.LabelWithHelpPanel) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) Task(com.evolveum.midpoint.task.api.Task) AttributeModifier(org.apache.wicket.AttributeModifier) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) PropertyModel(org.apache.wicket.model.PropertyModel) Item(org.apache.wicket.markup.repeater.Item) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) java.util(java.util) GuiDisplayTypeUtil(com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil) com.evolveum.midpoint.web.component.data.column(com.evolveum.midpoint.web.component.data.column) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) CollectionUtils(org.apache.commons.collections4.CollectionUtils) GuiStyleConstants(com.evolveum.midpoint.gui.api.GuiStyleConstants) CredentialsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) IVisitor(org.apache.wicket.util.visit.IVisitor) Selectable(com.evolveum.midpoint.web.component.util.Selectable) DataTable(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) PrismObject(com.evolveum.midpoint.prism.PrismObject) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) PrismReference(com.evolveum.midpoint.prism.PrismReference) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) Label(org.apache.wicket.markup.html.basic.Label) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TablePanel(com.evolveum.midpoint.web.component.data.TablePanel)

Example 3 with PasswordPanel

use of com.evolveum.midpoint.gui.api.component.password.PasswordPanel in project midpoint by Evolveum.

the class NotificationConfigTabPanel method initMailServersColumns.

private List<IColumn<MailServerConfiguration, String>> initMailServersColumns() {
    List<IColumn<MailServerConfiguration, String>> columns = new ArrayList<>();
    columns.add(new CheckBoxHeaderColumn<>());
    columns.add(new IconColumn<>(Model.of("")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected DisplayType getIconDisplayType(IModel<MailServerConfiguration> rowModel) {
            return GuiDisplayTypeUtil.createDisplayType(WebComponentUtil.createDefaultBlackIcon(SystemConfigurationType.COMPLEX_TYPE));
        }
    });
    columns.add(new EditableAjaxLinkColumn<>(createStringResource("MailServerConfigurationType.host")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected IModel<String> createLinkModel(IModel<MailServerConfiguration> rowModel) {
            return Model.of(rowModel.getObject().getValue().getHost());
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            MailServerConfigurationType mailServer = rowModel.getObject().getValue();
            InputPanel input = new TextPanel<>(componentId, new PropertyModel<>(mailServer, "host"));
            input.add(AttributeAppender.prepend("class", getInputCssClass()));
            return input;
        }

        @Override
        public void onClick(AjaxRequestTarget target, IModel<MailServerConfiguration> rowModel) {
            mailServerEditPerformed(target, rowModel, null);
        }
    });
    columns.add(new EditableColumn<>(createStringResource("MailServerConfigurationType.port")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createStaticPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            return new Label(componentId, Model.of(rowModel.getObject().getValue().getPort()));
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            MailServerConfigurationType mailServer = rowModel.getObject().getValue();
            InputPanel input = new TextPanel<>(componentId, new PropertyModel<>(mailServer, "port"));
            input.add(AttributeAppender.prepend("class", getInputCssClass()));
            return input;
        }
    });
    columns.add(new EditableColumn<>(createStringResource("MailServerConfigurationType.username")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createStaticPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            return new Label(componentId, Model.of(rowModel.getObject().getValue().getUsername()));
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            MailServerConfigurationType mailServer = rowModel.getObject().getValue();
            InputPanel input = new TextPanel<>(componentId, new PropertyModel<>(mailServer, "username"));
            input.add(AttributeAppender.prepend("class", getInputCssClass()));
            return input;
        }
    });
    columns.add(new EditableColumn<>(createStringResource("MailServerConfigurationType.password")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createStaticPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            return new PasswordPanel(componentId, Model.of(rowModel.getObject().getValue().getPassword()), true, false);
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            MailServerConfigurationType mailServer = rowModel.getObject().getValue();
            return new PasswordPanel(componentId, new PropertyModel<>(mailServer, "password"), false, true);
        }
    });
    columns.add(new EditableColumn<>(createStringResource("MailServerConfigurationType.transportSecurity")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createStaticPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            IModel<String> retModel = WebComponentUtil.createLocalizedModelForEnum(rowModel.getObject().getValue().getTransportSecurity(), null);
            return new Label(componentId, retModel != null && retModel.getObject() != null ? retModel.getObject() : "");
        }

        @Override
        protected Component createInputPanel(String componentId, IModel<MailServerConfiguration> rowModel) {
            MailServerConfigurationType mailServer = rowModel.getObject().getValue();
            InputPanel input = WebComponentUtil.createEnumPanel(MailTransportSecurityType.class, componentId, new PropertyModel<>(mailServer, "transportSecurity"), NotificationConfigTabPanel.this);
            input.add(AttributeAppender.prepend("class", getInputCssClass()));
            return input;
        }
    });
    List<InlineMenuItem> menuActionsList = getMenuActions();
    columns.add(new InlineMenuButtonColumn<>(menuActionsList, getPageBase()));
    return columns;
}
Also used : ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) Component(org.apache.wicket.Component) IModel(org.apache.wicket.model.IModel) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)

Example 4 with PasswordPanel

use of com.evolveum.midpoint.gui.api.component.password.PasswordPanel in project midpoint by Evolveum.

the class ACAttributeValuePanel method createTypedInputComponent.

private InputPanel createTypedInputComponent(String id, PrismPropertyDefinition definition) {
    QName valueType = definition.getTypeName();
    final String baseExpression = ACValueConstructionDto.F_VALUE;
    InputPanel panel;
    if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel = new DatePanel(id, new PropertyModel<>(getModel(), baseExpression));
    } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        panel = new PasswordPanel(id, new PropertyModel<>(getModel(), baseExpression));
    } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel = new TriStateComboPanel(id, new PropertyModel<>(getModel(), baseExpression));
    } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        panel = new TextPanel<>(id, new PropertyModel<>(getModel(), baseExpression + ".orig"), String.class);
    } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
            type = ClassUtils.primitiveToWrapper(type);
        }
        panel = new TextPanel<>(id, new PropertyModel<>(getModel(), baseExpression), type);
        if (ObjectType.F_NAME.equals(definition.getItemName())) {
            panel.getBaseFormComponent().setRequired(true);
        }
    }
    return panel;
}
Also used : TriStateComboPanel(com.evolveum.midpoint.web.component.input.TriStateComboPanel) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) QName(javax.xml.namespace.QName) InputPanel(com.evolveum.midpoint.web.component.prism.InputPanel) DatePanel(com.evolveum.midpoint.web.component.input.DatePanel) PropertyModel(org.apache.wicket.model.PropertyModel) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel)

Example 5 with PasswordPanel

use of com.evolveum.midpoint.gui.api.component.password.PasswordPanel in project midpoint by Evolveum.

the class PrismValuePanel method createTypedInputComponent.

// normally this method returns an InputPanel;
// however, for some special readonly types (like ObjectDeltaType) it will return a Panel
private Panel createTypedInputComponent(String id) {
    //        ValueWrapper valueWrapper = model.getObject();
    //        ItemWrapper itemWrapper =
    final Item item = valueWrapperModel.getObject().getItem().getItem();
    Panel panel = null;
    if (item instanceof PrismProperty) {
        final PrismProperty property = (PrismProperty) item;
        PrismPropertyDefinition definition = property.getDefinition();
        final QName valueType = definition.getTypeName();
        //pointing to prism property real value
        final String baseExpression = "value.value";
        //now it works only in description
        if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
            return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
        }
        if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
            return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
        } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
            return new LockoutStatusPanel(id, valueWrapperModel.getObject(), new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
        } else {
            if (definition.getTypeName().getLocalPart().equals(ActivationStatusType.class.getSimpleName())) {
                return WebComponentUtil.createEnumPanel(ActivationStatusType.class, id, new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression), this);
            }
        }
        if (DOMUtil.XSD_DATETIME.equals(valueType)) {
            panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));
        } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
            panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression), valueWrapperModel.getObject().isReadonly());
        } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
            panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));
        } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
            InputPanel inputPanel;
            PrismPropertyDefinition def = property.getDefinition();
            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();
                Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
                final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
                if (lookupTable != null) {
                    inputPanel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()), String.class) {

                        @Override
                        public Iterator<String> getIterator(String input) {
                            return prepareAutoCompleteList(input, lookupTable).iterator();
                        }
                    };
                } else {
                    inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
                }
            } else {
                inputPanel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"), String.class);
            }
            if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
                inputPanel.getBaseFormComponent().setRequired(true);
            }
            panel = inputPanel;
        } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
            panel = new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {

                @Override
                public InputStream getStream() {
                    Object object = ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                    return object != null ? new ByteArrayInputStream((byte[]) object) : new ByteArrayInputStream(new byte[0]);
                //                		return super.getStream();
                }

                @Override
                public void updateValue(byte[] file) {
                    ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
                }

                @Override
                public void uploadFilePerformed(AjaxRequestTarget target) {
                    super.uploadFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void removeFilePerformed(AjaxRequestTarget target) {
                    super.removeFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void uploadFileFailed(AjaxRequestTarget target) {
                    super.uploadFileFailed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    target.add(((PageBase) getPage()).getFeedbackPanel());
                }
            };
        } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
            panel = new ModificationsPanel(id, new AbstractReadOnlyModel<DeltaDto>() {

                @Override
                public DeltaDto getObject() {
                    if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null || ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue() == null) {
                        return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType = (ObjectDeltaType) ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                    try {
                        ObjectDelta delta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                        return new DeltaDto(delta);
                    } catch (SchemaException e) {
                        throw new IllegalStateException("Couldn't convert object delta: " + objectDeltaType);
                    }
                }
            });
        } else if (QueryType.COMPLEX_TYPE.equals(valueType) || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
            return new TextAreaPanel(id, new AbstractReadOnlyModel() {

                @Override
                public Object getObject() {
                    if (valueWrapperModel.getObject() == null || valueWrapperModel.getObject().getValue() == null) {
                        return null;
                    }
                    PrismPropertyValue ppv = (PrismPropertyValue) valueWrapperModel.getObject().getValue();
                    if (ppv == null || ppv.getValue() == null) {
                        return null;
                    }
                    QName name = property.getElementName();
                    if (name == null && property.getDefinition() != null) {
                        name = property.getDefinition().getName();
                    }
                    if (name == null) {
                        name = SchemaConstants.C_VALUE;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    try {
                        return prismContext.xmlSerializer().serializeAnyData(ppv.getValue(), name);
                    } catch (SchemaException e) {
                        throw new SystemException("Couldn't serialize property value of type: " + valueType + ": " + e.getMessage(), e);
                    }
                }
            }, 10);
        } else {
            Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
            if (type != null && type.isPrimitive()) {
                type = ClassUtils.primitiveToWrapper(type);
            }
            if (isEnum(property)) {
                return WebComponentUtil.createEnumPanel(definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
            }
            //                  // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
            //                  if (type == QName.class) {
            //                      type = String.class;
            //                  }
            PrismPropertyDefinition def = property.getDefinition();
            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();
                Collection<SelectorOptions<GetOperationOptions>> options = WebModelServiceUtils.createLookupTableRetrieveOptions();
                final PrismObject<LookupTableType> lookupTable = WebModelServiceUtils.loadObject(LookupTableType.class, lookupTableUid, options, pageBase, task, result);
                if (lookupTable != null) {
                    panel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(valueWrapperModel, baseExpression, lookupTable == null ? null : lookupTable.asObjectable()), type) {

                        @Override
                        public Iterator<String> getIterator(String input) {
                            return prepareAutoCompleteList(input, lookupTable).iterator();
                        }

                        @Override
                        public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget target, LookupPropertyModel model) {
                            Iterator<String> lookupTableValuesIterator = prepareAutoCompleteList("", lookupTable).iterator();
                            String value = input.getInput();
                            boolean isValueExist = false;
                            if (value != null) {
                                if (value.trim().equals("")) {
                                    isValueExist = true;
                                } else {
                                    while (lookupTableValuesIterator.hasNext()) {
                                        String lookupTableValue = lookupTableValuesIterator.next();
                                        if (value.trim().equals(lookupTableValue)) {
                                            isValueExist = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (isValueExist) {
                                input.setModelValue(new String[] { value });
                                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                            } else {
                                input.error("Entered value doesn't match any of available values and will not be saved.");
                                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                            }
                        }
                    };
                } else {
                    panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
                }
            } else {
                panel = new TextPanel<>(id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
            }
        }
    } else if (item instanceof PrismReference) {
        PrismContext prismContext = item.getPrismContext();
        if (prismContext == null) {
            prismContext = pageBase.getPrismContext();
        }
        QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
        Class targetClass = null;
        if (targetTypeName != null && prismContext != null) {
            targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
        }
        final Class typeClass = targetClass != null ? targetClass : (item.getDefinition().getTypeClassIfKnown() != null ? item.getDefinition().getTypeClassIfKnown() : FocusType.class);
        Collection typeClasses = new ArrayList();
        // HACK HACK MID-3201 MID-3231
        if (isUserOrgItem(item, typeClass)) {
            typeClasses.add(UserType.class);
            typeClasses.add(OrgType.class);
        } else {
            typeClasses.add(typeClass);
        }
        panel = new ValueChoosePanel(id, new PropertyModel<>(valueWrapperModel, "value"), item.getValues(), false, typeClasses);
    } else if (item instanceof PrismContainer<?>) {
        AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
        final PrismContainer container = (PrismContainer) item;
        PrismContainerDefinition definition = container.getDefinition();
        QName valueType = definition.getTypeName();
        if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {
            PrismContext prismContext = item.getPrismContext();
            if (prismContext == null) {
                prismContext = pageBase.getPrismContext();
            }
            ShadowType shadowType = ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
            PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
            // of resources.
            try {
                resource.revive(prismContext);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedResourceSchema refinedSchema;
            CompositeRefinedObjectClassDefinition rOcDef;
            try {
                refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
                rOcDef = refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
            RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();
            ObjectQuery query = getAssociationsSearchQuery(prismContext, resource, assocTargetDef.getTypeName(), assocTargetDef.getKind());
            List values = item.getValues();
            return new AssociationValueChoicePanel(id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
        }
    }
    return panel;
}
Also used : LockoutStatusPanel(com.evolveum.midpoint.web.component.LockoutStatusPanel) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AutoCompleteTextField(org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField) List(java.util.List) ArrayList(java.util.ArrayList) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) DeltaDto(com.evolveum.midpoint.web.component.model.delta.DeltaDto) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ByteArrayInputStream(java.io.ByteArrayInputStream) Collection(java.util.Collection) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ModificationsPanel(com.evolveum.midpoint.web.component.model.delta.ModificationsPanel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) AssociationValueChoicePanel(com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel) Iterator(java.util.Iterator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) QName(javax.xml.namespace.QName) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) LockoutStatusPanel(com.evolveum.midpoint.web.component.LockoutStatusPanel) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) AutoCompleteTextPanel(com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) ModificationsPanel(com.evolveum.midpoint.web.component.model.delta.ModificationsPanel) Panel(org.apache.wicket.markup.html.panel.Panel) AssociationValueChoicePanel(com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) LookupPropertyModel(com.evolveum.midpoint.web.model.LookupPropertyModel)

Aggregations

PasswordPanel (com.evolveum.midpoint.gui.api.component.password.PasswordPanel)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 Label (org.apache.wicket.markup.html.basic.Label)4 PropertyModel (org.apache.wicket.model.PropertyModel)4 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 ArrayList (java.util.ArrayList)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 TablePanel (com.evolveum.midpoint.web.component.data.TablePanel)2 InputPanel (com.evolveum.midpoint.web.component.prism.InputPanel)2 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)2 MyPasswordsDto (com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)2 PasswordAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)2 AttributeModifier (org.apache.wicket.AttributeModifier)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 PasswordTextField (org.apache.wicket.markup.html.form.PasswordTextField)2 IModel (org.apache.wicket.model.IModel)2