com.vaadin.ui.PasswordField

Here are the examples of the java api com.vaadin.ui.PasswordField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

17 Examples 7

19 Source : PasswordWindow.java
with Apache License 2.0
from opensecuritycontroller

public clreplaced PreplacedwordWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    private static final Logger LOG = LoggerFactory.getLogger(PreplacedwordWindow.clreplaced);

    private static final long serialVersionUID = -7979397047792926898L;

    private PreplacedwordField preplacedwordField;

    private Optional<SubmitFormListener> submitFormListener;

    private final ValidationApi validator;

    public interface SubmitFormListener {

        void submit(String preplacedword);
    }

    public PreplacedwordWindow(ValidationApi validator) throws Exception {
        this.validator = validator;
        createWindow("Create database backup preplacedword");
    }

    @Override
    public void populateForm() throws Exception {
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        HorizontalLayout layout = new HorizontalLayout();
        this.preplacedwordField = new PreplacedwordField();
        this.preplacedwordField.setRequired(true);
        layout.addComponent(this.preplacedwordField);
        layout.setCaption(VmidcMessages.getString(VmidcMessages_.PreplacedWORD_CAPTION));
        this.form.addComponent(layout);
    }

    @Override
    public boolean validateForm() {
        try {
            this.validator.checkValidPreplacedword(this.preplacedwordField.getValue());
        } catch (VmidcBrokerInvalidEntryException e) {
            LOG.error("Invalid preplacedword defined by user.", e);
            ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
            return false;
        }
        return true;
    }

    @Override
    public void submitForm() {
        if (validateForm()) {
            if (this.submitFormListener.isPresent()) {
                this.submitFormListener.get().submit(this.preplacedwordField.getValue());
            }
            close();
        }
    }

    public void setSubmitFormListener(SubmitFormListener listener) {
        this.submitFormListener = Optional.of(listener);
    }
}

19 Source : AddUserWindow.java
with Apache License 2.0
from opensecuritycontroller

public clreplaced AddUserWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    /**
     */
    private static final long serialVersionUID = 1L;

    final String CAPTION = "Add User";

    private static final Logger log = LoggerFactory.getLogger(AddUserWindow.clreplaced);

    // form fields
    private TextField firstName = null;

    private TextField lastName = null;

    private TextField loginName = null;

    private PreplacedwordField preplacedword = null;

    private TextField email = null;

    private ComboBox role = null;

    private final AddUserServiceApi addUserService;

    public AddUserWindow(UserView userView, AddUserServiceApi addUserService) throws Exception {
        this.addUserService = addUserService;
        createWindow(this.CAPTION);
    }

    @Override
    public void populateForm() {
        this.loginName = new TextField("User Name");
        this.loginName.setImmediate(true);
        this.firstName = new TextField("First Name");
        this.lastName = new TextField("Last Name");
        this.preplacedword = new PreplacedwordField("Preplacedword");
        this.preplacedword.setImmediate(true);
        this.email = new TextField("Email");
        this.email.addValidator(new EmailValidator("Please enter a valid email address"));
        this.role = new ComboBox("Role");
        this.role.setTextInputAllowed(false);
        this.role.setNullSelectionAllowed(false);
        this.role.addItem(UpdateUserWindow.ROLE_ADMIN);
        this.role.select(UpdateUserWindow.ROLE_ADMIN);
        // adding not null constraint
        this.loginName.setRequired(true);
        this.loginName.setRequiredError("User Name cannot be empty");
        this.preplacedword.setRequired(true);
        this.preplacedword.setRequiredError("Preplacedword cannot be empty");
        this.role.setRequired(true);
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        this.form.addComponent(this.loginName);
        this.form.addComponent(this.firstName);
        this.form.addComponent(this.lastName);
        this.form.addComponent(this.preplacedword);
        this.form.addComponent(this.email);
        this.form.addComponent(this.role);
        this.loginName.focus();
    }

    @Override
    public boolean validateForm() {
        try {
            this.loginName.validate();
            this.preplacedword.validate();
            this.email.validate();
            this.role.validate();
            return true;
        } catch (Exception e) {
            log.debug("Validation Error");
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        try {
            if (validateForm()) {
                // creating add request with user entered data
                AddUserRequest addRequest = new AddUserRequest();
                addRequest.setFirstName(this.firstName.getValue().trim());
                addRequest.setLastName(this.lastName.getValue().trim());
                addRequest.setLoginName(this.loginName.getValue().trim());
                addRequest.setEmail(this.email.getValue().trim());
                addRequest.setPreplacedword(this.preplacedword.getValue());
                addRequest.setRole(this.role.getValue().toString());
                // calling add service
                AddUserResponse addResponse;
                log.info("adding new user - " + this.loginName.getValue());
                addResponse = this.addUserService.dispatch(addRequest);
                // adding returned ID to the request DTO object
                addRequest.setId(addResponse.getId());
                close();
            }
        } catch (Exception e) {
            log.info(e.getMessage());
            ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }
}

19 Source : AdvancedSettingsWindow.java
with Apache License 2.0
from opensecuritycontroller

public clreplaced AdvancedSettingsWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    /**
     */
    private static final long serialVersionUID = 1L;

    private static final String ADVANCED_SETTINGS_CAPTION = VmidcMessages.getString(VmidcMessages_.ADVANCED);

    private static final Logger LOG = LoggerFactory.getLogger(AdvancedSettingsWindow.clreplaced);

    private CheckBox providerHttps = null;

    private TextField rabbitMQIp = null;

    private TextField rabbitMQUserName = null;

    private PreplacedwordField rabbitMQUserPreplacedword = null;

    private TextField rabbitMQPort = null;

    private final BaseVCWindow baseVCWindow;

    public AdvancedSettingsWindow(BaseVCWindow baseVCWindow) throws Exception {
        this.baseVCWindow = baseVCWindow;
        createWindow(ADVANCED_SETTINGS_CAPTION);
        getComponentModel().setOkClickedListener(new ClickListener() {

            /**
             */
            private static final long serialVersionUID = -8326846388022657979L;

            @Override
            public void buttonClick(ClickEvent event) {
                submitForm();
            }
        });
    }

    @Override
    public void populateForm() throws Exception {
        this.providerHttps = new CheckBox("Https");
        this.providerHttps.setValue(false);
        this.rabbitMQIp = new TextField("RabbitMQ IP");
        this.rabbitMQUserName = new TextField("RabbitMQ User Name");
        this.rabbitMQUserName.setRequired(true);
        this.rabbitMQUserPreplacedword = new PreplacedwordField("RabbitMQ Preplacedword");
        this.rabbitMQUserPreplacedword.setRequired(true);
        this.rabbitMQPort = new TextField("RabbitMQ Port");
        this.rabbitMQPort.setRequired(true);
        this.rabbitMQUserName.setRequiredError(this.rabbitMQUserName.getCaption() + " cannot be empty");
        this.rabbitMQUserPreplacedword.setRequiredError(this.rabbitMQUserPreplacedword.getCaption() + " cannot be empty");
        this.rabbitMQPort.setRequiredError(this.rabbitMQPort.getCaption() + " cannot be empty");
        // fill this form with default/previous values
        this.providerHttps.setValue(new Boolean(this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_HTTPS)));
        if (this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_IP) != null) {
            this.rabbitMQIp.setValue(this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_IP));
        }
        if (this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_USER) != null) {
            this.rabbitMQUserName.setValue(this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_USER));
        }
        if (this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_USER_PreplacedWORD) != null) {
            this.rabbitMQUserPreplacedword.setValue(this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_USER_PreplacedWORD));
        }
        if (this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_PORT) != null) {
            this.rabbitMQPort.setValue(this.baseVCWindow.providerAttributes.get(ATTRIBUTE_KEY_RABBITMQ_PORT));
        }
        this.form.addComponent(this.providerHttps);
        this.form.addComponent(this.rabbitMQIp);
        this.form.addComponent(this.rabbitMQUserName);
        this.form.addComponent(this.rabbitMQUserPreplacedword);
        this.form.addComponent(this.rabbitMQPort);
    }

    @Override
    public boolean validateForm() {
        try {
            if (this.rabbitMQIp != null) {
                this.rabbitMQIp.validate();
            }
            this.rabbitMQUserName.validate();
            this.rabbitMQUserPreplacedword.validate();
            this.rabbitMQPort.validate();
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        if (validateForm()) {
            try {
                // override all default values with user provided ones...
                this.baseVCWindow.providerAttributes.clear();
                this.baseVCWindow.providerAttributes.put(ATTRIBUTE_KEY_HTTPS, this.providerHttps.getValue().toString());
                this.baseVCWindow.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_IP, this.rabbitMQIp.getValue().toString());
                this.baseVCWindow.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER, this.rabbitMQUserName.getValue().toString());
                this.baseVCWindow.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER_PreplacedWORD, this.rabbitMQUserPreplacedword.getValue().toString());
                this.baseVCWindow.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_PORT, this.rabbitMQPort.getValue().toString());
                close();
            } catch (Exception e) {
                String msg = "Failed to encrypt rabbit MQ user preplacedword";
                LOG.error(msg, e);
                ViewUtil.iscNotification(msg, Notification.Type.ERROR_MESSAGE);
            }
        }
    }
}

18 Source : UpdateUserWindow.java
with Apache License 2.0
from opensecuritycontroller

public clreplaced UpdateUserWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    /**
     */
    private static final long serialVersionUID = 1L;

    final String CAPTION = "Edit User";

    private static final Logger log = LoggerFactory.getLogger(UpdateUserWindow.clreplaced);

    public static final String ROLE_ADMIN = "ADMIN";

    // form fields
    private TextField firstName = null;

    private TextField lastName = null;

    private TextField loginName = null;

    private PreplacedwordField preplacedword = null;

    private TextField email = null;

    private ComboBox role = null;

    private final BeanItem<UserDto> currentUser;

    private final UpdateUserServiceApi updateUserService;

    private final ServerApi server;

    public UpdateUserWindow(UserView userView, UpdateUserServiceApi updateUserService, ServerApi server) throws Exception {
        this.currentUser = userView.getParenreplacedem();
        this.updateUserService = updateUserService;
        this.server = server;
        createWindow(this.CAPTION);
    }

    @Override
    public void populateForm() {
        this.loginName = new TextField("User Name");
        this.loginName.setImmediate(true);
        this.firstName = new TextField("First Name");
        this.lastName = new TextField("Last Name");
        this.preplacedword = new PreplacedwordField("Preplacedword");
        this.preplacedword.setImmediate(true);
        this.email = new TextField("Email");
        this.email.addValidator(new EmailValidator("Please enter a valid email address"));
        this.role = new ComboBox("Role");
        this.role.setTextInputAllowed(false);
        this.role.setNullSelectionAllowed(false);
        this.role.addItem(UpdateUserWindow.ROLE_ADMIN);
        this.role.select(UpdateUserWindow.ROLE_ADMIN);
        // filling fields with existing information
        this.loginName.setValue(this.currentUser.gereplacedemProperty("loginName").getValue().toString());
        this.loginName.setEnabled(false);
        this.preplacedword.setValue(this.currentUser.gereplacedemProperty("preplacedword").getValue().toString());
        if (this.currentUser.gereplacedemProperty("email").getValue() != null) {
            this.email.setValue(this.currentUser.gereplacedemProperty("email").getValue().toString());
        }
        if (this.currentUser.gereplacedemProperty("firstName").getValue() != null) {
            this.firstName.setValue(this.currentUser.gereplacedemProperty("firstName").getValue().toString());
        }
        if (this.currentUser.gereplacedemProperty("lastName").getValue() != null) {
            this.lastName.setValue(this.currentUser.gereplacedemProperty("lastName").getValue().toString());
        }
        this.role.setValue(this.currentUser.gereplacedemProperty("role").getValue().toString());
        // adding not null constraint
        this.loginName.setRequired(true);
        this.loginName.setRequiredError("User Name cannot be Empty");
        this.preplacedword.setRequired(true);
        this.preplacedword.setRequiredError("Preplacedword Cannot be empty");
        this.role.setRequired(true);
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        this.form.addComponent(this.loginName);
        this.form.addComponent(this.firstName);
        this.form.addComponent(this.lastName);
        this.form.addComponent(this.preplacedword);
        this.form.addComponent(this.email);
        this.form.addComponent(this.role);
        this.firstName.focus();
    }

    @Override
    public boolean validateForm() {
        try {
            this.loginName.validate();
            this.preplacedword.validate();
            this.email.validate();
            this.role.validate();
            return true;
        } catch (Exception e) {
            log.debug("Validation error");
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        try {
            if (validateForm()) {
                // creating add request with user entered data
                UpdateUserRequest updateRequest = new UpdateUserRequest();
                updateRequest.setId(this.currentUser.getBean().getId());
                updateRequest.setFirstName(this.firstName.getValue().trim());
                updateRequest.setLastName(this.lastName.getValue().trim());
                updateRequest.setLoginName(this.loginName.getValue().trim());
                updateRequest.setEmail(this.email.getValue().trim());
                updateRequest.setPreplacedword(this.preplacedword.getValue());
                updateRequest.setRole(this.role.getValue().toString());
                log.info("Updating user - " + this.loginName.getValue());
                UpdateUserResponse res = this.updateUserService.dispatch(updateRequest);
                if (res.getJobId() != null) {
                    ViewUtil.showJobNotification(res.getJobId(), this.server);
                }
                close();
            }
        } catch (Exception e) {
            log.info("Error updating user", e);
            ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }
}

18 Source : SetEmailSettingsWindow.java
with Apache License 2.0
from opensecuritycontroller

public clreplaced SetEmailSettingsWindow extends CRUDBaseValidateWindow {

    private static final long serialVersionUID = 1L;

    private static final Logger log = LoggerFactory.getLogger(SetEmailSettingsWindow.clreplaced);

    final String CAPTION = "Set Email Settings";

    private TextField smtp = null;

    private TextField port = null;

    private TextField emailId = null;

    private PreplacedwordField preplacedword = null;

    private EmailLayout emailLayout = null;

    private final GetEmailSettingsServiceApi getEmailSettingsService;

    private final SetEmailSettingsServiceApi setEmailSettingsService;

    public SetEmailSettingsWindow(EmailLayout emailLayout, GetEmailSettingsServiceApi getEmailSettingsService, SetEmailSettingsServiceApi setEmailSettingsService) throws Exception {
        super(new OkCancelValidateButtonModel());
        this.emailLayout = emailLayout;
        this.getEmailSettingsService = getEmailSettingsService;
        this.setEmailSettingsService = setEmailSettingsService;
        createWindow(this.CAPTION);
    }

    @Override
    public void populateForm() {
        this.smtp = new TextField("Outgoing Mail Server (SMTP)");
        this.smtp.setImmediate(true);
        this.port = new TextField("Port");
        this.port.setImmediate(true);
        this.emailId = new TextField("Email Id");
        this.emailId.setImmediate(true);
        this.preplacedword = new PreplacedwordField("Preplacedword");
        this.preplacedword.setImmediate(true);
        // filling form with existing data
        BaseDtoResponse<EmailSettingsDto> res = new BaseDtoResponse<EmailSettingsDto>();
        try {
            res = this.getEmailSettingsService.dispatch(new Request() {
            });
            if (res.getDto() != null) {
                this.smtp.setValue(res.getDto().getMailServer());
                this.port.setValue(res.getDto().getPort());
                this.emailId.setValue(res.getDto().getEmailId());
                this.preplacedword.setValue(res.getDto().getPreplacedword());
            }
            // adding not null constraint
            this.smtp.setRequired(true);
            this.smtp.setRequiredError("SMTP server cannot be empty");
            this.port.setRequired(true);
            this.port.setRequiredError("SMTP port cannot be empty");
            this.emailId.setRequired(true);
            this.emailId.setRequiredError("Email Id cannot be empty");
            this.form.addComponent(this.smtp);
            this.smtp.focus();
            this.form.addComponent(this.port);
            this.form.addComponent(this.emailId);
            this.form.addComponent(this.preplacedword);
        } catch (Exception ex) {
            log.error("Failed to get email settings", ex);
            ViewUtil.iscNotification("Failed to get email settings (" + ex.getMessage() + ")", Notification.Type.ERROR_MESSAGE);
        }
    }

    @Override
    public boolean validateForm() {
        try {
            this.smtp.validate();
            this.port.validate();
            this.emailId.validate();
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        try {
            if (validateForm()) {
                BaseRequest<EmailSettingsDto> request = new BaseRequest<EmailSettingsDto>();
                request.setDto(getDto());
                this.setEmailSettingsService.dispatch(request);
                this.emailLayout.populateEmailtable();
                close();
            }
        } catch (Exception e) {
            log.error("Failed to update the email settings", e);
            ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }

    private EmailSettingsDto getDto() {
        EmailSettingsDto dto = new EmailSettingsDto();
        dto.setMailServer(this.smtp.getValue().trim());
        dto.setPort(this.port.getValue().trim());
        dto.setEmailId(this.emailId.getValue().trim());
        dto.setPreplacedword(this.preplacedword.getValue().trim());
        return dto;
    }

    @Override
    public void validateSettings() {
        try {
            if (validateForm()) {
                // Validate Email settings by sending an Email From and To the same email ID provided
                EmailSettingsDto dto = getDto();
                this.setEmailSettingsService.validateEmailSettings(new BaseRequest<>(dto));
                // If every things is correct attempt to send an email..
                this.setEmailSettingsService.sentTestEmail(dto.getMailServer(), dto.getPort(), dto.getEmailId(), dto.getPreplacedword(), dto.getEmailId());
                ViewUtil.iscNotification("Info: ", "Email validation successful. You will be receiving an email shortly.", Type.HUMANIZED_MESSAGE);
            }
        } catch (Exception ex) {
            ViewUtil.iscNotification("Email settings are incorrect. Please re-try again with correct information " + ex.getMessage(), Type.ERROR_MESSAGE);
            log.error("Failed to send email to the interested user(s): ", ex);
        }
    }
}

17 Source : AddManagerConnectorWindow.java
with Apache License 2.0
from opensecuritycontroller

@SuppressWarnings("serial")
public clreplaced AddManagerConnectorWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    private static final long serialVersionUID = 1L;

    final String CAPTION = "Add Manager Connector";

    private static final Logger log = LoggerFactory.getLogger(AddManagerConnectorWindow.clreplaced);

    // current view reference
    private final ManagerConnectorView mcView;

    // form fields
    private TextField name = null;

    private ComboBox type = null;

    private TextField ip = null;

    private TextField user = null;

    private PreplacedwordField pw = null;

    private PreplacedwordField apiKey = null;

    private ArrayList<CertificateResolverModel> certificateResolverModelsList = null;

    private final AddApplianceManagerConnectorServiceApi addMCService;

    private final PluginService pluginStatusService;

    private final ValidationApi validator;

    private final X509TrustManagerApi trustManager;

    private final ServerApi server;

    public AddManagerConnectorWindow(ManagerConnectorView mcView, AddApplianceManagerConnectorServiceApi addMCService, PluginService pluginStatusService, ValidationApi validator, X509TrustManagerApi trustManager, ServerApi server) throws Exception {
        this.mcView = mcView;
        this.addMCService = addMCService;
        this.pluginStatusService = pluginStatusService;
        this.validator = validator;
        this.trustManager = trustManager;
        this.server = server;
        createWindow(this.CAPTION);
    }

    @Override
    public void populateForm() throws Exception {
        Set<String> managerTypes = this.pluginStatusService.getManagerTypes();
        if (managerTypes.size() == 0) {
            throw new VmidcException("No manager plugins found. Please add Manager plugin to perform action");
        }
        this.name = new TextField("Name");
        this.name.setImmediate(true);
        this.type = new ComboBox("Type");
        this.apiKey = new PreplacedwordField("API Key");
        this.apiKey.setImmediate(true);
        this.apiKey.setVisible(false);
        this.apiKey.setImmediate(true);
        this.apiKey.setRequired(true);
        this.apiKey.setRequiredError("Api Key cannot be empty");
        this.type.setImmediate(true);
        this.type.setTextInputAllowed(false);
        this.type.setNullSelectionAllowed(false);
        for (String mt : this.pluginStatusService.getManagerTypes()) {
            this.type.addItem(mt);
        }
        this.type.addValueChangeListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                try {
                    if (AddManagerConnectorWindow.this.pluginStatusService.isKeyAuth(AddManagerConnectorWindow.this.type.getValue().toString())) {
                        AddManagerConnectorWindow.this.apiKey.setVisible(true);
                        AddManagerConnectorWindow.this.user.setVisible(false);
                        AddManagerConnectorWindow.this.pw.setVisible(false);
                        AddManagerConnectorWindow.this.user.setValue("");
                        AddManagerConnectorWindow.this.pw.setValue("");
                    } else {
                        AddManagerConnectorWindow.this.apiKey.setValue("");
                        AddManagerConnectorWindow.this.apiKey.setVisible(false);
                        AddManagerConnectorWindow.this.user.setVisible(true);
                        AddManagerConnectorWindow.this.pw.setVisible(true);
                    }
                } catch (Exception e) {
                    ViewUtil.showError("Error changing manager type", e);
                }
            }
        });
        this.ip = new TextField("IP");
        this.ip.setImmediate(true);
        this.user = new TextField("User Name");
        this.user.setImmediate(true);
        this.pw = new PreplacedwordField("Preplacedword");
        this.pw.setImmediate(true);
        // adding not null constraint
        this.name.setRequired(true);
        this.name.setRequiredError("Name cannot be empty");
        this.type.setRequired(true);
        this.type.setRequiredError("Type cannot be empty");
        this.ip.setRequired(true);
        this.ip.setRequiredError("IP cannot be empty");
        this.user.setRequired(true);
        this.user.setRequiredError("User Name cannot be empty");
        this.pw.setRequired(true);
        this.pw.setRequiredError("Preplacedword cannot be empty");
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        this.form.addComponent(this.name);
        this.name.focus();
        this.form.addComponent(this.type);
        this.form.addComponent(this.ip);
        this.form.addComponent(this.user);
        this.form.addComponent(this.pw);
        this.form.addComponent(this.apiKey);
        // select the first entry as default Manager Connector...
        this.type.select(managerTypes.toArray()[0].toString());
    }

    @Override
    public boolean validateForm() {
        try {
            this.name.validate();
            this.type.validate();
            this.ip.validate();
            this.validator.checkValidIpAddress(this.ip.getValue());
            if (this.pluginStatusService.isKeyAuth(this.type.getValue().toString())) {
                this.apiKey.validate();
            } else {
                this.user.validate();
                this.pw.validate();
            }
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        try {
            if (validateForm()) {
                createAndSubmitRequest(null);
            }
        } catch (Exception e) {
            sslAwareHandleException(e);
        }
    }

    /**
     * Create and submits the add connector request.
     *
     * @param errorTypesToIgnore the errortypes to ignore
     */
    private void createAndSubmitRequest(List<ErrorType> errorTypesToIgnore) throws Exception {
        // creating add request with user entered data
        DryRunRequest<ApplianceManagerConnectorRequest> addRequest = new DryRunRequest<>();
        addRequest.setDto(new ApplianceManagerConnectorRequest());
        addRequest.getDto().setName(this.name.getValue().trim());
        addRequest.getDto().setManagerType(((String) this.type.getValue()).trim());
        addRequest.getDto().setIpAddress(this.ip.getValue().trim());
        addRequest.getDto().setUsername(this.user.getValue().trim());
        addRequest.getDto().setPreplacedword(this.pw.getValue().trim());
        addRequest.getDto().setApiKey(this.apiKey.getValue().trim());
        HashSet<SslCertificateAttrDto> sslSet = new HashSet<>();
        if (this.certificateResolverModelsList != null) {
            sslSet.addAll(this.certificateResolverModelsList.stream().map(crm -> new SslCertificateAttrDto(crm.getAlias(), crm.getSha1())).collect(Collectors.toList()));
        }
        addRequest.getDto().setSslCertificateAttrSet(sslSet);
        addRequest.addErrorsToIgnore(errorTypesToIgnore);
        // calling add MC service
        log.info("adding manager connector - " + this.name.getValue().trim());
        BaseJobResponse addResponse = this.addMCService.dispatch(addRequest);
        // adding returned ID to the request DTO object
        addRequest.getDto().setId(addResponse.getId());
        // adding new object to the parent table
        this.mcView.getParentContainer().addItemAt(0, addRequest.getDto().getId(), addRequest.getDto());
        this.mcView.parentTableClicked(addRequest.getDto().getId());
        close();
        ViewUtil.showJobNotification(addResponse.getJobId(), this.server);
    }

    private void sslAwareHandleException(final Exception originalException) {
        if (originalException instanceof SslCertificatesExtendedException) {
            SslCertificatesExtendedException unknownException = (SslCertificatesExtendedException) originalException;
            ArrayList<CertificateResolverModel> certificateResolverModels = unknownException.getCertificateResolverModels();
            try {
                ViewUtil.addWindow(new AddSSLCertificateWindow(certificateResolverModels, new AddSSLCertificateWindow.SSLCertificateWindowInterface() {

                    @Override
                    public void submitFormAction(ArrayList<CertificateResolverModel> certificateResolverModels) {
                        AddManagerConnectorWindow.this.certificateResolverModelsList = certificateResolverModels;
                    }

                    @Override
                    public void cancelFormAction() {
                        handleException(originalException);
                    }
                }, this.trustManager));
            } catch (Exception e) {
                handleException(originalException);
            }
        } else {
            handleException(originalException);
        }
    }

    private void handleException(final Exception originalException) {
        String caption = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_CAPTION);
        String contentText = null;
        final Throwable cause;
        if (originalException instanceof ErrorTypeException) {
            cause = originalException.getCause();
            if (cause instanceof SocketException || cause instanceof SSLException || cause instanceof SocketTimeoutException) {
                contentText = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_IP, StringEscapeUtils.escapeHtml(this.name.getValue()));
            } else {
                handleCatchAllException(new Exception(VmidcMessages.getString(VmidcMessages_.GENERAL_REST_ERROR, this.ip.getValue(), cause.getMessage()), cause));
                return;
            }
        } else {
            cause = originalException;
        }
        if (contentText != null) {
            final VmidcWindow<OkCancelButtonModel> alertWindow = WindowUtil.createAlertWindow(caption, contentText);
            alertWindow.getComponentModel().setOkClickedListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    if (validateForm()) {
                        try {
                            createAndSubmitRequest(Arrays.asList(ErrorType.MANAGER_CONNECTOR_EXCEPTION));
                        } catch (Exception e) {
                            handleException(e);
                        }
                    }
                    alertWindow.close();
                }
            });
            ViewUtil.addWindow(alertWindow);
        } else {
            handleCatchAllException(cause);
        }
    }
}

14 Source : LoginComponent.java
with Apache License 2.0
from ijazfx

@Override
protected Component createContent(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    userNameField.setCaption("Username");
    preplacedwordField.setCaption("Preplacedword");
    loginButton.setCaption("Login");
    return build(userNameField, preplacedwordField, loginButton);
}

14 Source : VaadinAbstractLoginComponent.java
with Apache License 2.0
from ijazfx

private Component buildLoginForm(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    final MVerticalLayout loginPanel = new MVerticalLayout();
    loginPanel.setSizeUndefined();
    Responsive.makeResponsive(loginPanel);
    loginPanel.addStyleName("login-panel");
    loginPanel.addComponent(buildLabels());
    loginPanel.addComponent(buildFields(userNameField, preplacedwordField, loginButton));
    if (isRememberMeEnabled()) {
        loginPanel.addComponent(new CheckBox("Remember me", true));
    }
    return loginPanel;
}

12 Source : VaadinAbstractLoginComponent.java
with Apache License 2.0
from ijazfx

public Component build(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    MVerticalLayout mainLayout = null;
    if (mainLayout == null) {
        mainLayout = new MVerticalLayout();
        mainLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
        addLoginListener(listener -> {
            UserLoginRequestedEvent userLoginRequestedEvent = new UserLoginRequestedEvent(listener.getLoginParameter(USERNAME), listener.getLoginParameter(PreplacedWORD));
            DashboardEventBus.sessionInstance().post(userLoginRequestedEvent);
        });
        setSizeFull();
        Component loginForm = buildLoginForm(userNameField, preplacedwordField, loginButton);
        mainLayout.setSizeFull();
        mainLayout.addComponent(loginForm);
        postBuild();
    }
    return mainLayout;
}

10 Source : BaseVCWindow.java
with Apache License 2.0
from opensecuritycontroller

public abstract clreplaced BaseVCWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    private static final String OPENSTACK_ICEHOUSE = "Icehouse";

    private static final String KUBERNETES_1_6 = "v1.6";

    /**
     */
    private static final long serialVersionUID = 1L;

    private static final Logger log = LoggerFactory.getLogger(BaseVCWindow.clreplaced);

    public static final String DEFAULT_HTTPS = "false";

    public static final String DEFAULT_RABBITMQ_USER = "guest";

    public static final String DEFAULT_RABBITMQ_USER_PreplacedWORD = "guest";

    public static final String DEFAULT_RABBITMQ_PORT = "5672";

    protected static final String SHOW_ADVANCED_SETTINGS_CAPTION = VmidcMessages.getString(VmidcMessages_.SHOW_ADVANCED);

    protected static final String KEYSTONE_CAPTION = VmidcMessages.getString(VmidcMessages_.KEYSTONE);

    protected static final String SDN_CONTROLLER_CAPTION = "SDN Controller";

    protected static final String OPENSTACK_CAPTION = VmidcMessages.getString(VmidcMessages_.KEYSTONE);

    protected Map<String, String> providerAttributes = new HashMap<>();

    protected List<ErrorType> errorTypesToIgnore = new ArrayList<>();

    private HashSet<SslCertificateAttrDto> sslCertificateAttrs = new HashSet<>();

    // current view referencecurrentVCObject
    protected VirtualizationConnectorView vcView = null;

    protected BeanItem<VirtualizationConnectorDto> currentVCObject = null;

    // form fields
    protected TextField name = null;

    protected ComboBox virtualizationType = null;

    // Controller input fields
    protected TextField controllerIP = null;

    protected TextField controllerUser = null;

    protected PreplacedwordField controllerPW = null;

    // Provider input fields
    protected TextField providerIP = null;

    protected TextField adminDomainId = null;

    protected TextField adminProjectName = null;

    protected TextField providerUser = null;

    protected PreplacedwordField providerPW = null;

    // Open stack Input Fields
    protected ComboBox controllerType = null;

    // All Panels
    protected Panel controllerPanel = null;

    protected Panel providerPanel = null;

    protected Button advancedSettings = null;

    private final PluginService pluginService;

    private final ValidationApi validator;

    private final X509TrustManagerApi trustManager;

    public BaseVCWindow(PluginService pluginService, ValidationApi validator, X509TrustManagerApi trustManager) {
        super();
        this.pluginService = pluginService;
        this.validator = validator;
        this.trustManager = trustManager;
    }

    @Override
    public boolean validateForm() {
        try {
            this.name.validate();
            this.virtualizationType.validate();
            if (this.virtualizationType.getValue().toString().equals(VirtualizationType.OPENSTACK.toString())) {
                String controllerType = (String) BaseVCWindow.this.controllerType.getValue();
                if (!NO_CONTROLLER_TYPE.equals(controllerType) && !this.pluginService.usesProviderCreds(controllerType)) {
                    this.controllerIP.validate();
                    this.validator.checkValidIpAddress(this.controllerIP.getValue());
                    this.controllerUser.validate();
                    this.controllerPW.validate();
                }
            }
            this.providerIP.validate();
            this.validator.checkValidIpAddress(this.providerIP.getValue());
            if (this.adminDomainId.isVisible()) {
                this.adminDomainId.validate();
            }
            if (this.adminProjectName.isVisible()) {
                this.adminProjectName.validate();
            }
            this.providerUser.validate();
            this.providerPW.validate();
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    protected void buildForm() {
        this.name = new TextField("Name");
        this.name.setImmediate(true);
        this.virtualizationType = new ComboBox("Type");
        this.virtualizationType.setTextInputAllowed(false);
        this.virtualizationType.setNullSelectionAllowed(false);
        for (VirtualizationType virtualizationType : VirtualizationType.values()) {
            this.virtualizationType.addItem(virtualizationType.toString());
        }
        this.virtualizationType.select(VirtualizationType.OPENSTACK.toString());
        // adding not null constraint
        this.name.setRequired(true);
        this.name.setRequiredError("Name cannot be empty");
        this.virtualizationType.setRequired(true);
        this.virtualizationType.setRequiredError("Type cannot be empty");
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        this.form.addComponent(this.name);
        this.name.focus();
        this.form.addComponent(this.virtualizationType);
        this.form.addComponent(controllerPanel());
        this.form.addComponent(providerPanel());
        this.advancedSettings = new Button(SHOW_ADVANCED_SETTINGS_CAPTION);
        this.advancedSettings.setImmediate(true);
        this.advancedSettings.setVisible(false);
        this.advancedSettings.addClickListener(new ClickListener() {

            /**
             */
            private static final long serialVersionUID = 7124022733079327543L;

            @Override
            public void buttonClick(ClickEvent event) {
                advancedSettingsClicked();
            }
        });
        this.form.addComponent(this.advancedSettings);
    }

    // Returns OpenStack form
    protected Panel providerPanel() {
        this.providerPanel = new Panel();
        this.providerPanel.setImmediate(true);
        this.providerPanel.setCaption(OPENSTACK_CAPTION);
        this.providerIP = new TextField("IP");
        this.providerIP.setImmediate(true);
        this.adminDomainId = new TextField("Admin Domain Id");
        this.adminDomainId.setImmediate(true);
        this.adminProjectName = new TextField("Admin Project Name");
        this.adminProjectName.setImmediate(true);
        this.providerUser = new TextField("User Name");
        this.providerUser.setImmediate(true);
        this.providerPW = new PreplacedwordField("Preplacedword");
        this.providerPW.setImmediate(true);
        // adding not null constraint
        this.adminDomainId.setRequired(true);
        this.adminDomainId.setRequiredError(this.providerPanel.getCaption() + " Admin Domain Id cannot be empty");
        this.adminProjectName.setRequired(true);
        this.adminProjectName.setRequiredError(this.providerPanel.getCaption() + " Admin Project Name cannot be empty");
        this.providerIP.setRequired(true);
        this.providerIP.setRequiredError(this.providerPanel.getCaption() + " IP cannot be empty");
        this.providerUser.setRequired(true);
        this.providerUser.setRequiredError(this.providerPanel.getCaption() + " User Name cannot be empty");
        this.providerPW.setRequired(true);
        this.providerPW.setRequiredError(this.providerPanel.getCaption() + " Preplacedword cannot be empty");
        FormLayout providerFormPanel = new FormLayout();
        providerFormPanel.addComponent(this.providerIP);
        providerFormPanel.addComponent(this.adminDomainId);
        providerFormPanel.addComponent(this.adminProjectName);
        providerFormPanel.addComponent(this.providerUser);
        providerFormPanel.addComponent(this.providerPW);
        this.providerPanel.setContent(providerFormPanel);
        return this.providerPanel;
    }

    protected Panel controllerPanel() {
        this.controllerPanel = new Panel();
        this.controllerPanel.setImmediate(true);
        this.controllerPanel.setCaption(SDN_CONTROLLER_CAPTION);
        this.controllerType = new ComboBox("Type");
        this.controllerType.setTextInputAllowed(false);
        this.controllerType.setNullSelectionAllowed(false);
        this.controllerType.addItem(NO_CONTROLLER_TYPE);
        for (String ct : this.pluginService.getControllerTypes()) {
            this.controllerType.addItem(ct);
        }
        this.controllerType.setVisible(true);
        this.controllerIP = new TextField("IP");
        this.controllerIP.setImmediate(true);
        this.controllerUser = new TextField("User Name");
        this.controllerUser.setImmediate(true);
        this.controllerPW = new PreplacedwordField("Preplacedword");
        this.controllerPW.setImmediate(true);
        // adding not null constraint
        this.controllerIP.setRequired(true);
        this.controllerIP.setRequiredError(this.controllerPanel.getCaption() + " IP cannot be empty");
        this.controllerUser.setRequired(true);
        this.controllerUser.setRequiredError(this.controllerPanel.getCaption() + " User Name cannot be empty");
        this.controllerPW.setRequired(true);
        this.controllerPW.setRequiredError(this.controllerPanel.getCaption() + " Preplacedword cannot be empty");
        FormLayout sdn = new FormLayout();
        sdn.addComponent(this.controllerType);
        sdn.addComponent(this.controllerIP);
        sdn.addComponent(this.controllerUser);
        sdn.addComponent(this.controllerPW);
        this.controllerPanel.setContent(sdn);
        this.controllerType.addValueChangeListener(event -> updateControllerFields((String) BaseVCWindow.this.controllerType.getValue()));
        this.controllerType.select(NO_CONTROLLER_TYPE);
        return this.controllerPanel;
    }

    protected void handleException(final Exception originalException) {
        String caption = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CAPTION);
        String contentText = null;
        final Throwable exception;
        if (originalException instanceof ErrorTypeException) {
            ErrorType errorType = ((ErrorTypeException) originalException).getType();
            exception = originalException.getCause();
            // TODO this exception leaks large amounts of implementation detail out of the API
            if (isOpenstack()) {
                switch(errorType) {
                    case PROVIDER_EXCEPTION:
                        if (RestClientException.isConnectException(exception)) {
                            // Keystone Connect Exception
                            contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, KEYSTONE_CAPTION);
                        } else {
                            contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, KEYSTONE_CAPTION, exception.getMessage());
                        }
                        break;
                    case PROVIDER_CONNECT_EXCEPTION:
                        contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, KEYSTONE_CAPTION);
                        break;
                    case PROVIDER_AUTH_EXCEPTION:
                        contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CREDS, KEYSTONE_CAPTION);
                        break;
                    case CONTROLLER_EXCEPTION:
                        contentText = handleControllerException(exception);
                        break;
                    case RABBITMQ_EXCEPTION:
                        contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_RABBIT, exception.getMessage());
                        break;
                    case IP_CHANGED_EXCEPTION:
                        contentText = VmidcMessages.getString(VmidcMessages_.VC_WARNING_IPUPDATE);
                        break;
                    default:
                        contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, KEYSTONE_CAPTION, exception.getMessage());
                        break;
                }
            }
        } else if (originalException instanceof RestClientException) {
            RestClientException rce = (RestClientException) originalException;
            handleCatchAllException(new Exception(VmidcMessages.getString(VmidcMessages_.GENERAL_REST_ERROR, rce.getHost(), rce.getMessage()), originalException));
            return;
        } else {
            exception = originalException;
        }
        if (contentText != null) {
            final VmidcWindow<OkCancelButtonModel> alertWindow = WindowUtil.createAlertWindow(caption, contentText);
            alertWindow.getComponentModel().setOkClickedListener(event -> {
                try {
                    if (originalException instanceof ErrorTypeException) {
                        ErrorType errorType = ((ErrorTypeException) originalException).getType();
                        BaseVCWindow.this.errorTypesToIgnore.add(errorType);
                    }
                    submitForm();
                } catch (Exception e) {
                    handleException(e);
                }
                alertWindow.close();
            });
            ViewUtil.addWindow(alertWindow);
        } else {
            handleCatchAllException(exception);
        }
    }

    private boolean isOpenstack() {
        return VirtualizationType.fromText(this.virtualizationType.getValue().toString()) == VirtualizationType.OPENSTACK;
    }

    private String handleControllerException(Throwable exception) {
        String contentText = null;
        if (RestClientException.isCredentialError(exception)) {
            // SDN Invalid Credential Exception
            contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_CREDS, this.controllerType.getValue().toString());
        } else if (RestClientException.isConnectException(exception)) {
            // SDN Controller Connect Exception
            contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_IP, this.controllerType.getValue().toString());
        } else {
            // SDN Controller Connect Exception
            contentText = VmidcMessages.getString(VmidcMessages_.VC_CONFIRM_GENERAL, this.controllerType.getValue().toString(), exception.getMessage());
        }
        return contentText;
    }

    void sslAwareHandleException(final Exception originalException) {
        if (!(originalException instanceof SslCertificatesExtendedException)) {
            handleException(originalException);
            return;
        }
        SslCertificatesExtendedException unknownException = (SslCertificatesExtendedException) originalException;
        ArrayList<CertificateResolverModel> certificateResolverModels = unknownException.getCertificateResolverModels();
        try {
            ViewUtil.addWindow(new AddSSLCertificateWindow(certificateResolverModels, new AddSSLCertificateWindow.SSLCertificateWindowInterface() {

                @Override
                public void submitFormAction(ArrayList<CertificateResolverModel> certificateResolverModels) {
                    if (certificateResolverModels != null) {
                        BaseVCWindow.this.sslCertificateAttrs.addAll(certificateResolverModels.stream().map(crm -> new SslCertificateAttrDto(crm.getAlias(), crm.getSha1())).collect(Collectors.toList()));
                    }
                }

                @Override
                public void cancelFormAction() {
                    handleException(originalException);
                }
            }, this.trustManager));
        } catch (Exception e) {
            handleException(originalException);
        }
    }

    /**
     * Create and submits the add connector request.
     */
    protected DryRunRequest<VirtualizationConnectorRequest> createRequest() throws Exception {
        DryRunRequest<VirtualizationConnectorRequest> request = new DryRunRequest<>();
        request.setDto(new VirtualizationConnectorRequest());
        VirtualizationConnectorDto dto = request.getDto();
        dto.setName(this.name.getValue().trim());
        VirtualizationType virtualizationTypeValue = VirtualizationType.fromText(((String) this.virtualizationType.getValue()).trim());
        dto.setType(virtualizationTypeValue);
        dto.setControllerIP(this.controllerIP.getValue().trim());
        dto.setControllerUser(this.controllerUser.getValue().trim());
        dto.setControllerPreplacedword(this.controllerPW.getValue().trim());
        dto.setProviderIP(this.providerIP.getValue().trim());
        dto.setProviderUser(this.providerUser.getValue().trim());
        dto.setProviderPreplacedword(this.providerPW.getValue().trim());
        dto.setSslCertificateAttrSet(this.sslCertificateAttrs);
        String domainId = this.adminDomainId.getValue();
        if (domainId != null) {
            dto.setAdminDomainId(domainId.trim());
        }
        String projectName = this.adminProjectName.getValue();
        if (projectName != null) {
            dto.setAdminProjectName(projectName.trim());
        }
        if (virtualizationTypeValue.equals(VirtualizationType.OPENSTACK)) {
            dto.setProviderAttributes(this.providerAttributes);
        }
        request.addErrorsToIgnore(this.errorTypesToIgnore);
        // TODO: Future. Get virtualization version this from user.
        if (this.virtualizationType.getValue().equals(VirtualizationType.OPENSTACK.toString())) {
            request.getDto().setSoftwareVersion(OPENSTACK_ICEHOUSE);
        } else {
            request.getDto().setSoftwareVersion(KUBERNETES_1_6);
        }
        request.getDto().setControllerType((String) BaseVCWindow.this.controllerType.getValue());
        return request;
    }

    protected void advancedSettingsClicked() {
        try {
            ViewUtil.addWindow(new AdvancedSettingsWindow(this));
        } catch (Exception e) {
            ViewUtil.iscNotification(e.toString() + ".", Notification.Type.ERROR_MESSAGE);
        }
    }

    protected void updateForm(String type) {
        this.controllerIP.setValue("");
        this.controllerUser.setValue("");
        this.controllerPW.setValue("");
        this.controllerPanel.setVisible(true);
        if (type.equals(VirtualizationType.OPENSTACK.toString())) {
            this.controllerPanel.setCaption(SDN_CONTROLLER_CAPTION);
            this.providerPanel.setCaption(OPENSTACK_CAPTION);
            this.controllerType.setVisible(true);
            this.controllerType.setValue(NO_CONTROLLER_TYPE);
            updateControllerFields(NO_CONTROLLER_TYPE);
            this.adminDomainId.setVisible(true);
            this.adminProjectName.setVisible(true);
            this.advancedSettings.setVisible(true);
            this.advancedSettings.setCaption(SHOW_ADVANCED_SETTINGS_CAPTION);
            updateProviderFields();
        }
        this.controllerIP.setRequiredError(this.controllerPanel.getCaption() + " IP cannot be empty");
        this.controllerUser.setRequiredError(this.controllerPanel.getCaption() + " User Name cannot be empty");
        this.controllerPW.setRequiredError(this.controllerPanel.getCaption() + " Preplacedword cannot be empty");
        this.providerIP.setRequiredError(this.providerPanel.getCaption() + " IP cannot be empty");
        this.providerUser.setRequiredError(this.providerPanel.getCaption() + " User Name cannot be empty");
        this.providerPW.setRequiredError(this.providerPanel.getCaption() + " Preplacedword cannot be empty");
        this.adminDomainId.setRequiredError(this.providerPanel.getCaption() + " Admin Domain Id cannot be empty");
        this.adminProjectName.setRequiredError(this.providerPanel.getCaption() + " Admin Project Name cannot be empty");
    }

    private void updateControllerFields(String type) {
        boolean enableFields = false;
        if (!type.equals(NO_CONTROLLER_TYPE)) {
            try {
                enableFields = !this.pluginService.usesProviderCreds(type.toString());
            } catch (Exception e) {
                log.error("Fail to get controller plugin instance", e);
            }
        }
        BaseVCWindow.this.controllerIP.setEnabled(enableFields);
        BaseVCWindow.this.controllerIP.setRequired(enableFields);
        BaseVCWindow.this.controllerUser.setEnabled(enableFields);
        BaseVCWindow.this.controllerUser.setRequired(enableFields);
        BaseVCWindow.this.controllerPW.setEnabled(enableFields);
        BaseVCWindow.this.controllerPW.setRequired(enableFields);
        if (!enableFields) {
            this.controllerIP.setValue("");
            this.controllerUser.setValue("");
            this.controllerPW.setValue("");
        }
    }

    private void updateProviderFields() {
        if (BaseVCWindow.this.virtualizationType.getValue().equals(VirtualizationType.OPENSTACK.toString())) {
            // If user does not click advanced Settings we need to populate attributes with default values..
            this.providerAttributes.put(ATTRIBUTE_KEY_HTTPS, DEFAULT_HTTPS);
            this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER, DEFAULT_RABBITMQ_USER);
            this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_PORT, DEFAULT_RABBITMQ_PORT);
            this.providerAttributes.put(ATTRIBUTE_KEY_RABBITMQ_USER_PreplacedWORD, DEFAULT_RABBITMQ_USER_PreplacedWORD);
        }
    }
}

10 Source : LoginComponent.java
with Apache License 2.0
from ijazfx

private Component buildLoginForm(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    final MVerticalLayout loginPanel = new MVerticalLayout().withSpacing(true);
    loginPanel.setSizeUndefined();
    Responsive.makeResponsive(loginPanel);
    loginPanel.addStyleName("login-panel");
    loginPanel.addComponent(buildLabels());
    loginPanel.addComponent(buildFields(userNameField, preplacedwordField, loginButton));
    if (isRememberMeEnabled()) {
        loginPanel.addComponent(new CheckBox("Remember me", true));
    }
    MLabel forgotPreplacedwordLabel = new MLabel();
    forgotPreplacedwordLabel.setValue("Forgot preplacedword? <a href=\"/reset-preplacedword\">Click here!</a> to reset.");
    forgotPreplacedwordLabel.setContentMode(ContentMode.HTML);
    loginPanel.addComponent(forgotPreplacedwordLabel);
    return loginPanel;
}

9 Source : UpdateManagerConnectorWindow.java
with Apache License 2.0
from opensecuritycontroller

@SuppressWarnings("serial")
public clreplaced UpdateManagerConnectorWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    private static final Logger log = LoggerFactory.getLogger(UpdateManagerConnectorWindow.clreplaced);

    protected List<ErrorType> errorTypesToIgnore = new ArrayList<>();

    final String CAPTION = "Edit Manager Connector";

    // current view reference
    private final ManagerConnectorView mcView;

    // form fields
    private TextField name = null;

    private TextField type = null;

    private TextField ip = null;

    private TextField user = null;

    private PreplacedwordField pw = null;

    private PreplacedwordField apiKey = null;

    private final BeanItem<ApplianceManagerConnectorDto> currentMCObject;

    private ArrayList<CertificateResolverModel> certificateResolverModelsList = null;

    private final UpdateApplianceManagerConnectorServiceApi updateMCService;

    private final PluginService pluginService;

    private final ValidationApi validator;

    private final X509TrustManagerApi trustManager;

    private final ServerApi server;

    public UpdateManagerConnectorWindow(ManagerConnectorView mcView, UpdateApplianceManagerConnectorServiceApi updateMCService, PluginService pluginService, ValidationApi validator, X509TrustManagerApi trustManager, ServerApi server) throws Exception {
        this.mcView = mcView;
        this.updateMCService = updateMCService;
        this.pluginService = pluginService;
        this.validator = validator;
        this.trustManager = trustManager;
        this.server = server;
        this.currentMCObject = mcView.getParentContainer().gereplacedem(mcView.getParenreplacedemId());
        createWindow(this.CAPTION);
    }

    @Override
    public void populateForm() throws Exception {
        this.name = new TextField("Name");
        this.name.setImmediate(true);
        this.type = new TextField("Type");
        this.type.setImmediate(true);
        this.type.setEnabled(false);
        this.ip = new TextField("IP");
        this.ip.setImmediate(true);
        this.user = new TextField("UserName");
        this.user.setImmediate(true);
        this.pw = new PreplacedwordField("Preplacedword");
        this.pw.setImmediate(true);
        this.apiKey = new PreplacedwordField("API Key");
        this.apiKey.setVisible(false);
        this.apiKey.setImmediate(true);
        this.apiKey.setRequired(true);
        this.apiKey.setRequiredError("Api Key cannot be empty");
        // filling fields with existing information
        this.name.setValue(this.currentMCObject.gereplacedemProperty("name").getValue().toString());
        this.type.setValue(this.currentMCObject.gereplacedemProperty("managerType").getValue().toString());
        this.ip.setValue(this.currentMCObject.gereplacedemProperty("ipAddress").getValue().toString());
        if (this.pluginService.isKeyAuth(this.currentMCObject.gereplacedemProperty("managerType").getValue().toString())) {
            this.apiKey.setVisible(true);
            this.apiKey.setValue(this.currentMCObject.gereplacedemProperty("apiKey").getValue().toString());
            this.user.setVisible(false);
            this.user.setValue("");
            this.pw.setVisible(false);
            this.pw.setValue("");
        } else {
            this.apiKey.setVisible(false);
            this.user.setVisible(true);
            this.user.setValue(this.currentMCObject.gereplacedemProperty("username").getValue().toString());
            this.pw.setVisible(true);
            this.pw.setValue(this.currentMCObject.gereplacedemProperty("preplacedword").getValue().toString());
        }
        // adding not null constraint
        this.name.setRequired(true);
        this.name.setRequiredError("Name cannot be empty");
        this.type.setRequired(true);
        this.type.setRequiredError("Type cannot be empty");
        this.ip.setRequired(true);
        this.ip.setRequiredError("IP cannot be empty");
        this.user.setRequired(true);
        this.user.setRequiredError("User Name cannot be empty");
        this.pw.setRequired(true);
        this.pw.setRequiredError("Preplacedword cannot be empty");
        this.form.setMargin(true);
        this.form.setSizeUndefined();
        this.form.addComponent(this.name);
        this.form.addComponent(this.type);
        this.form.addComponent(this.ip);
        this.ip.focus();
        this.form.addComponent(this.user);
        this.form.addComponent(this.pw);
        this.form.addComponent(this.apiKey);
    }

    @Override
    public boolean validateForm() {
        try {
            this.name.validate();
            this.type.validate();
            this.ip.validate();
            this.validator.checkValidIpAddress(this.ip.getValue());
            if (this.pluginService.isKeyAuth(this.type.getValue().toString())) {
                this.apiKey.validate();
            } else {
                this.user.validate();
                this.pw.validate();
            }
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @Override
    public void submitForm() {
        try {
            if (validateForm()) {
                createAndSubmitRequest();
            }
        } catch (Exception exception) {
            sslAwareHandleException(exception);
        }
    }

    @SuppressWarnings("unchecked")
    private void createAndSubmitRequest() throws Exception {
        // creating update request with user modified data
        DryRunRequest<ApplianceManagerConnectorRequest> updateRequest = new DryRunRequest<>();
        updateRequest.setDto(new ApplianceManagerConnectorRequest());
        updateRequest.getDto().setId(this.currentMCObject.getBean().getId());
        updateRequest.getDto().setName(this.name.getValue().trim());
        updateRequest.getDto().setManagerType(this.type.getValue().trim());
        updateRequest.getDto().setIpAddress(this.ip.getValue().trim());
        updateRequest.getDto().setUsername(this.user.getValue().trim());
        updateRequest.getDto().setPreplacedword(this.pw.getValue().trim());
        updateRequest.getDto().setApiKey(this.apiKey.getValue().trim());
        HashSet<SslCertificateAttrDto> sslSet = new HashSet<>();
        if (this.certificateResolverModelsList != null) {
            sslSet.addAll(this.certificateResolverModelsList.stream().map(crm -> new SslCertificateAttrDto(crm.getAlias(), crm.getSha1())).collect(Collectors.toList()));
            updateRequest.getDto().setSslCertificateAttrSet(sslSet);
        }
        updateRequest.addErrorsToIgnore(this.errorTypesToIgnore);
        log.debug("Updating manager connector - " + this.name.getValue().trim());
        // no response needed for update request
        BaseJobResponse response = this.updateMCService.dispatch(updateRequest);
        // updating bean in the table container
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "name").setValue(this.name.getValue().trim());
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "managerType").setValue(this.type.getValue().trim());
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "ipAddress").setValue(this.ip.getValue().trim());
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "username").setValue(this.user.getValue().trim());
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "preplacedword").setValue(this.pw.getValue().trim());
        this.mcView.getParentContainer().getContainerProperty(updateRequest.getDto().getId(), "apiKey").setValue(this.apiKey.getValue().trim());
        close();
        ViewUtil.showJobNotification(response.getJobId(), this.server);
    }

    protected void sslAwareHandleException(final Exception originalException) {
        if (originalException instanceof SslCertificatesExtendedException) {
            SslCertificatesExtendedException sslCertificateException = (SslCertificatesExtendedException) originalException;
            ArrayList<CertificateResolverModel> certificateResolverModels = sslCertificateException.getCertificateResolverModels();
            try {
                ViewUtil.addWindow(new AddSSLCertificateWindow(certificateResolverModels, new AddSSLCertificateWindow.SSLCertificateWindowInterface() {

                    @Override
                    public void submitFormAction(ArrayList<CertificateResolverModel> certificateResolverModels) {
                        UpdateManagerConnectorWindow.this.certificateResolverModelsList = certificateResolverModels;
                    }

                    @Override
                    public void cancelFormAction() {
                        handleException(originalException);
                    }
                }, this.trustManager));
            } catch (Exception e) {
                handleException(originalException);
            }
        } else {
            handleException(originalException);
        }
    }

    private void handleException(final Exception originalException) {
        String caption = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_CAPTION);
        String contentText = null;
        final Throwable cause;
        if (originalException instanceof ErrorTypeException) {
            ErrorType errorType = ((ErrorTypeException) originalException).getType();
            cause = originalException.getCause();
            if (errorType == ErrorType.MANAGER_CONNECTOR_EXCEPTION) {
                if (cause instanceof SocketException || cause instanceof SSLException || cause instanceof SocketTimeoutException) {
                    contentText = VmidcMessages.getString(VmidcMessages_.MC_CONFIRM_IP, StringEscapeUtils.escapeHtml(this.name.getValue()));
                } else {
                    handleCatchAllException(new Exception(VmidcMessages.getString(VmidcMessages_.GENERAL_REST_ERROR, this.ip.getValue(), cause.getMessage()), cause));
                    return;
                }
            } else if (errorType == ErrorType.IP_CHANGED_EXCEPTION) {
                contentText = VmidcMessages.getString(VmidcMessages_.MC_WARNING_IPUPDATE);
            }
        } else {
            cause = originalException;
        }
        if (contentText != null) {
            final VmidcWindow<OkCancelButtonModel> alertWindow = WindowUtil.createAlertWindow(caption, contentText);
            alertWindow.getComponentModel().setOkClickedListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    if (validateForm()) {
                        try {
                            if (originalException instanceof ErrorTypeException) {
                                ErrorType errorType = ((ErrorTypeException) originalException).getType();
                                UpdateManagerConnectorWindow.this.errorTypesToIgnore.add(errorType);
                            }
                            createAndSubmitRequest();
                        } catch (Exception e) {
                            handleException(e);
                        }
                    }
                    alertWindow.close();
                }
            });
            ViewUtil.addWindow(alertWindow);
        } else {
            handleCatchAllException(cause);
        }
    }
}

9 Source : BaseDAWindow.java
with Apache License 2.0
from opensecuritycontroller

public abstract clreplaced BaseDAWindow extends CRUDBaseWindow<OkCancelButtonModel> {

    private static final long serialVersionUID = 1L;

    private static final Logger log = LoggerFactory.getLogger(BaseDAWindow.clreplaced);

    // form fields
    protected TextField name = null;

    protected ComboBox managerConnector = null;

    protected ComboBox applianceDefinition = null;

    protected Panel attributePanel = null;

    protected Table attributes = null;

    protected PreplacedwordField sharedKey;

    protected Table vsTable = null;

    protected DistributedApplianceDto currentDAObject = null;

    private final ListApplianceModelSwVersionComboServiceApi listApplianceModelSwVersionComboService;

    private final ListDomainsByMcIdServiceApi listDomainsByMcIdService;

    private final ListEncapsulationTypeByVersionTypeAndModelApi listEncapsulationTypeByVersionTypeAndModel;

    private final ListApplianceManagerConnectorServiceApi listApplianceManagerConnectorService;

    private final ListVirtualizationConnectorBySwVersionServiceApi listVirtualizationConnectorBySwVersionService;

    private final ValidationApi validator;

    public BaseDAWindow(ListApplianceModelSwVersionComboServiceApi listApplianceModelSwVersionComboService, ListDomainsByMcIdServiceApi listDomainsByMcIdService, ListEncapsulationTypeByVersionTypeAndModelApi listEncapsulationTypeByVersionTypeAndModel, ListApplianceManagerConnectorServiceApi listApplianceManagerConnectorService, ListVirtualizationConnectorBySwVersionServiceApi listVirtualizationConnectorBySwVersionService, ValidationApi validator) {
        super();
        this.listApplianceModelSwVersionComboService = listApplianceModelSwVersionComboService;
        this.listDomainsByMcIdService = listDomainsByMcIdService;
        this.listEncapsulationTypeByVersionTypeAndModel = listEncapsulationTypeByVersionTypeAndModel;
        this.listApplianceManagerConnectorService = listApplianceManagerConnectorService;
        this.listVirtualizationConnectorBySwVersionService = listVirtualizationConnectorBySwVersionService;
        this.validator = validator;
    }

    protected Panel getAttributesPanel() {
        this.sharedKey = new PreplacedwordField();
        this.sharedKey.setRequiredError("shared secret key cannot be empty");
        this.sharedKey.setRequired(true);
        // best show/hide this conditionally based on Manager type.
        this.sharedKey.setValue("dummy1234");
        this.attributes = new Table();
        this.attributes.setPageLength(0);
        this.attributes.setSelectable(true);
        this.attributes.setSizeFull();
        this.attributes.setImmediate(true);
        this.attributes.addContainerProperty("Attribute Name", String.clreplaced, null);
        this.attributes.addContainerProperty("Value", PreplacedwordField.clreplaced, null);
        this.attributes.addItem(new Object[] { "Shared Secret key", this.sharedKey }, new Integer(1));
        // creating panel to store attributes table
        this.attributePanel = new Panel("Common Appliance Configuration Attributes:");
        this.attributePanel.addStyleName("form_Panel");
        this.attributePanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
        this.attributePanel.setContent(this.attributes);
        return this.attributePanel;
    }

    /**
     * @return AZ Panel
     */
    @SuppressWarnings("serial")
    protected Panel getVirtualSystemPanel() {
        try {
            this.vsTable = new Table();
            this.vsTable.setPageLength(5);
            this.vsTable.setImmediate(true);
            this.vsTable.addGeneratedColumn("Enabled", new CheckBoxGenerator());
            this.vsTable.addItemClickListener(new ItemClickListener() {

                @Override
                public void itemClick(ItemClickEvent event) {
                    vsTableClicked((Long) event.gereplacedemId());
                }
            });
            // populating VS table
            populateVirtualSystem();
            Panel vsPanel = new Panel("Virtualization System:");
            vsPanel.addStyleName("form_Panel");
            vsPanel.setWidth(100, Sizeable.Unit.PERCENTAGE);
            vsPanel.setContent(this.vsTable);
            return vsPanel;
        } catch (Exception e) {
            log.error("Error while creating DA's VS panel", e);
        }
        return null;
    }

    protected void populateVirtualSystem() throws Exception {
        ApplianceModelSoftwareVersionDto currentAppliance = (ApplianceModelSoftwareVersionDto) this.applianceDefinition.getValue();
        // List VC Service
        ListVirtualizationConnectorBySwVersionRequest vcRequest = new ListVirtualizationConnectorBySwVersionRequest();
        if (currentAppliance != null) {
            vcRequest.setSwVersion(currentAppliance.getSwVersion());
        }
        ListResponse<VirtualizationConnectorDto> vcResponse = this.listVirtualizationConnectorBySwVersionService.dispatch(vcRequest);
        ApplianceManagerConnectorDto currentMC = (ApplianceManagerConnectorDto) this.managerConnector.getValue();
        // creating Virtual System Table
        this.vsTable.addContainerProperty("Enabled", Boolean.clreplaced, false);
        this.vsTable.addContainerProperty("Virtualization Connector", String.clreplaced, null);
        this.vsTable.addContainerProperty("Type", String.clreplaced, null);
        this.vsTable.addContainerProperty("Manager Domain", ComboBox.clreplaced, null);
        this.vsTable.addContainerProperty("Encapsulation Type", ComboBox.clreplaced, null);
        List<DomainDto> dl = getDomainList(currentMC);
        this.vsTable.removeAllItems();
        for (VirtualizationConnectorDto vc : vcResponse.getList()) {
            ComboBox domainComboBox = createDomainComboBox(dl);
            ComboBox encapsulationTypeComboBox = createEncapsulationTypeComboBox(vc.getType(), getEncapsulationType(currentAppliance, vc.getType()));
            // get Encapsulation Type for appliance
            // adding new row to vs table
            this.vsTable.addItem(new Object[] { vc.getName(), vc.getType().toString(), domainComboBox, encapsulationTypeComboBox }, vc.getId());
        }
    }

    private List<TagEncapsulationType> getEncapsulationType(ApplianceModelSoftwareVersionDto currentAppliance, VirtualizationType type) throws Exception {
        ListEncapsulationTypeByVersionTypeAndModelRequest req = new ListEncapsulationTypeByVersionTypeAndModelRequest(currentAppliance.getSwVersion(), currentAppliance.getApplianceModel(), type);
        return this.listEncapsulationTypeByVersionTypeAndModel.dispatch(req).getList();
    }

    protected ComboBox getDomainComboBox(Object id) {
        return (ComboBox) this.vsTable.gereplacedem(id).gereplacedemProperty("Manager Domain").getValue();
    }

    protected ComboBox getEncapsulationTypeComboBox(Object id) {
        return (ComboBox) this.vsTable.gereplacedem(id).gereplacedemProperty("Encapsulation Type").getValue();
    }

    @SuppressWarnings("unchecked")
    private void vsTableClicked(long itemId) {
        if (this.vsTable.getContainerProperty(itemId, "Enabled").getValue().equals(true)) {
            this.vsTable.getContainerProperty(itemId, "Enabled").setValue(false);
        } else {
            this.vsTable.getContainerProperty(itemId, "Enabled").setValue(true);
        }
    }

    /**
     * @return MC ComboBox
     */
    @SuppressWarnings("serial")
    protected ComboBox getManagerConnector() {
        try {
            ListResponse<ApplianceManagerConnectorDto> res = this.listApplianceManagerConnectorService.dispatch(new BaseRequest<>());
            BeanItemContainer<ApplianceManagerConnectorDto> mcList = new BeanItemContainer<ApplianceManagerConnectorDto>(ApplianceManagerConnectorDto.clreplaced, res.getList());
            this.managerConnector = new ComboBox("Manager Connector");
            this.managerConnector.setTextInputAllowed(false);
            this.managerConnector.setNullSelectionAllowed(false);
            this.managerConnector.setContainerDataSource(mcList);
            this.managerConnector.sereplacedemCaptionPropertyId("name");
            if (mcList.size() > 0) {
                this.managerConnector.select(mcList.getIdByIndex(0));
            }
            this.managerConnector.setImmediate(true);
            this.managerConnector.setRequired(true);
            this.managerConnector.setRequiredError("Manager Connector cannot be empty");
            this.managerConnector.addValueChangeListener(new ValueChangeListener() {

                @Override
                public void valueChange(ValueChangeEvent event) {
                    ApplianceManagerConnectorDto mcDto = (ApplianceManagerConnectorDto) BaseDAWindow.this.managerConnector.getValue();
                    updateAppliances();
                    updateDomains(mcDto);
                }
            });
        } catch (Exception e) {
            log.error("Error populating MC combobox", e);
        }
        return this.managerConnector;
    }

    @SuppressWarnings("serial")
    protected void updateAppliances() {
        ApplianceManagerConnectorDto currentMC = (ApplianceManagerConnectorDto) this.managerConnector.getValue();
        if (currentMC != null) {
            ListApplianceModelSwVersionComboRequest adRequest = new ListApplianceModelSwVersionComboRequest();
            adRequest.setType(currentMC.getManagerType());
            ListResponse<ApplianceModelSoftwareVersionDto> adResponse = null;
            try {
                adResponse = this.listApplianceModelSwVersionComboService.dispatch(adRequest);
                BeanItemContainer<ApplianceModelSoftwareVersionDto> adList = new BeanItemContainer<ApplianceModelSoftwareVersionDto>(ApplianceModelSoftwareVersionDto.clreplaced, adResponse.getList());
                this.applianceDefinition.setContainerDataSource(adList);
                this.applianceDefinition.sereplacedemCaptionPropertyId("name");
                if (adList.size() > 0) {
                    this.applianceDefinition.select(adList.getIdByIndex(0));
                }
                this.applianceDefinition.addValueChangeListener(new ValueChangeListener() {

                    @Override
                    public void valueChange(ValueChangeEvent event) {
                        try {
                            populateVirtualSystem();
                        } catch (Exception e) {
                            log.error("Error while populating Virtual System Table ", e);
                        }
                    }
                });
            } catch (Exception e) {
                log.error("Error retrieving appliance list", e);
            }
        }
    }

    @SuppressWarnings("unchecked")
    protected void updateDomains(ApplianceManagerConnectorDto mcDto) {
        List<DomainDto> dl = getDomainList(mcDto);
        for (Object itemId : this.vsTable.gereplacedemIds()) {
            ComboBox domainComboBox = createDomainComboBox(dl);
            Item item = this.vsTable.gereplacedem(itemId);
            item.gereplacedemProperty("Manager Domain").setValue(domainComboBox);
        }
    }

    private ComboBox createDomainComboBox(List<DomainDto> dl) {
        ComboBox domainComboBox = new ComboBox();
        BeanItemContainer<DomainDto> domainContainer = new BeanItemContainer<DomainDto>(DomainDto.clreplaced, dl);
        ApplianceManagerConnectorDto mc = (ApplianceManagerConnectorDto) this.managerConnector.getValue();
        domainComboBox.setContainerDataSource(domainContainer);
        domainComboBox.setTextInputAllowed(false);
        domainComboBox.setNullSelectionAllowed(false);
        domainComboBox.sereplacedemCaptionPropertyId("name");
        domainComboBox.setEnabled(mc.isPolicyMappingSupported());
        if (domainComboBox.gereplacedemIds().size() > 0) {
            domainComboBox.select(domainContainer.getIdByIndex(0));
        }
        return domainComboBox;
    }

    private ComboBox createEncapsulationTypeComboBox(VirtualizationType virtualizationType, List<TagEncapsulationType> types) {
        ComboBox encapsulationType = new ComboBox();
        encapsulationType.setTextInputAllowed(false);
        encapsulationType.setNullSelectionAllowed(true);
        BeanItemContainer<TagEncapsulationType> encapsulationTypeContainer = new BeanItemContainer<TagEncapsulationType>(TagEncapsulationType.clreplaced, types);
        encapsulationType.setContainerDataSource(encapsulationTypeContainer);
        ApplianceManagerConnectorDto currentMc = (ApplianceManagerConnectorDto) this.managerConnector.getValue();
        if (!virtualizationType.isOpenstack() || (currentMc != null && !currentMc.isPolicyMappingSupported())) {
            encapsulationType.setEnabled(false);
        }
        return encapsulationType;
    }

    /**
     * @return AD ComboBox
     */
    protected ComboBox getApplianceDefinition() {
        try {
            this.applianceDefinition = new ComboBox("Service Function Definition");
            this.applianceDefinition.setTextInputAllowed(false);
            this.applianceDefinition.setNullSelectionAllowed(false);
            this.applianceDefinition.setRequired(true);
            this.applianceDefinition.setRequiredError("Service Function Definition cannot be Empty");
            this.applianceDefinition.setWidth(100, Unit.PERCENTAGE);
            updateAppliances();
        } catch (Exception e) {
            log.error("Error populating appliance list combobox", e);
        }
        return this.applianceDefinition;
    }

    protected List<DomainDto> getDomainList(ApplianceManagerConnectorDto mc) {
        if (mc != null) {
            ListResponse<DomainDto> response = new ListResponse<DomainDto>();
            try {
                // List Domains Service
                BaseIdRequest agRequest = new BaseIdRequest();
                agRequest.setId(mc.getId());
                response = this.listDomainsByMcIdService.dispatch(agRequest);
            } catch (Exception e) {
                log.error("Error populating domain combobox", e);
            }
            return response.getList();
        } else {
            return new ArrayList<>();
        }
    }

    @Override
    public boolean validateForm() {
        try {
            this.name.validate();
            if (!this.validator.isValidDaName(this.name.getValue().toString())) {
                ViewUtil.iscNotification("DA name must not exceed 13 characters, must start with a letter,  and can only contain numbers, letters and dash(-).", Notification.Type.ERROR_MESSAGE);
                return false;
            }
            this.managerConnector.validate();
            this.applianceDefinition.validate();
            this.sharedKey.validate();
            int rowCount = 0;
            ApplianceManagerConnectorDto mcDto = (ApplianceManagerConnectorDto) this.managerConnector.getValue();
            for (Object id : this.vsTable.gereplacedemIds()) {
                if (this.vsTable.getContainerProperty(id, "Enabled").getValue().equals(true)) {
                    rowCount++;
                    DomainDto domainDto = (DomainDto) getDomainComboBox(id).getValue();
                    if (domainDto == null && mcDto.isPolicyMappingSupported()) {
                        ViewUtil.iscNotification("Please ensure domain is selected.", Notification.Type.ERROR_MESSAGE);
                        return false;
                    }
                    VirtualizationType vsType = VirtualizationType.fromText((String) this.vsTable.getContainerProperty(id, "Type").getValue());
                    TagEncapsulationType tag = (TagEncapsulationType) getEncapsulationTypeComboBox(id).getValue();
                    if (vsType.isOpenstack() && mcDto.isPolicyMappingSupported()) {
                        if (tag == null) {
                            ViewUtil.iscNotification("Please ensure Encapsulation type is selected.", Notification.Type.ERROR_MESSAGE);
                            return false;
                        }
                    } else {
                        if (tag != null) {
                            ViewUtil.iscNotification("Please ensure Encapsulation type is selected only for Openstack Virtual Systems.", Notification.Type.ERROR_MESSAGE);
                            return false;
                        }
                    }
                }
            }
            if (rowCount <= 0) {
                ViewUtil.iscNotification("Please select one or more Virtualization System for creating this DA.", Notification.Type.ERROR_MESSAGE);
                return false;
            }
            return true;
        } catch (Exception e) {
            ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
        }
        return false;
    }

    @SuppressWarnings("serial")
    private clreplaced CheckBoxGenerator implements Table.ColumnGenerator {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            Property<?> prop = source.gereplacedem(itemId).gereplacedemProperty(columnId);
            return new CheckBox(null, prop);
        }
    }
}

9 Source : LoginComponent.java
with Apache License 2.0
from ijazfx

public Component build(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    MVerticalLayout mainLayout = null;
    if (mainLayout == null) {
        mainLayout = new MVerticalLayout();
        mainLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
        addLoginListener(listener -> {
            UserLoginRequestedEvent userLoginRequestedEvent = new UserLoginRequestedEvent(listener.getLoginParameter(USERNAME), listener.getLoginParameter(PreplacedWORD));
            // clear preplacedword field...
            preplacedwordField.clear();
            preplacedwordField.focus();
            DashboardEventBus.sessionInstance().post(userLoginRequestedEvent);
        });
        setSizeFull();
        Component loginForm = buildLoginForm(userNameField, preplacedwordField, loginButton);
        mainLayout.setSizeFull();
        mainLayout.addComponent(loginForm);
        postBuild();
    }
    return mainLayout;
}

6 Source : VaadinAbstractLoginComponent.java
with Apache License 2.0
from ijazfx

private Component buildFields(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    MHorizontalLayout fields = new MHorizontalLayout();
    fields.addStyleName("fields");
    userNameField.setIcon(FontAwesome.USER);
    userNameField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    preplacedwordField.setIcon(FontAwesome.LOCK);
    preplacedwordField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setClickShortcut(KeyCode.ENTER);
    userNameField.focus();
    fields.addComponents(userNameField, preplacedwordField, loginButton);
    fields.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT);
    // signin.addClickListener(new ClickListener() {
    // @Override
    // public void buttonClick(final ClickEvent event) {
    // DashboardEventBus.sessionInstance().post(new
    // UserLoginRequestedEvent(username.getValue(), preplacedword.getValue()));
    // }
    // });
    return fields;
}

3 Source : LoginComponent.java
with Apache License 2.0
from ijazfx

private Component buildFields(TextField userNameField, PreplacedwordField preplacedwordField, Button loginButton) {
    MHorizontalLayout fields = new MHorizontalLayout().withSpacing(true);
    fields.addStyleName("fields");
    userNameField.setIcon(FontAwesome.USER);
    userNameField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    preplacedwordField.setIcon(FontAwesome.LOCK);
    preplacedwordField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setClickShortcut(KeyCode.ENTER);
    userNameField.focus();
    fields.addComponents(userNameField, preplacedwordField, loginButton);
    fields.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT);
    // signin.addClickListener(new ClickListener() {
    // @Override
    // public void buttonClick(final ClickEvent event) {
    // DashboardEventBus.sessionInstance().post(new
    // UserLoginRequestedEvent(username.getValue(), preplacedword.getValue()));
    // }
    // });
    return fields;
}

0 Source : MainUI.java
with Apache License 2.0
from opensecuritycontroller

private void buildLoginForm() {
    addStyleName("login");
    this.loginLayout = new VerticalLayout();
    this.loginLayout.setSizeFull();
    this.loginLayout.addStyleName("login-layout");
    this.root.addComponent(this.loginLayout);
    final CssLayout loginPanel = new CssLayout();
    loginPanel.addStyleName("login-panel");
    HorizontalLayout labels = new HorizontalLayout();
    labels.setWidth("100%");
    labels.setMargin(true);
    labels.addStyleName("labels");
    loginPanel.addComponent(labels);
    Label product = new Label(this.server.getProductName());
    product.addStyleName("product-label-login");
    labels.addComponent(new Image(null, new ThemeResource("img/logo.png")));
    labels.addComponent(product);
    labels.setComponentAlignment(product, Alignment.MIDDLE_LEFT);
    labels.setExpandRatio(product, 1);
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.setMargin(true);
    fields.addStyleName("fields");
    final TextField username = new TextField("Login ID");
    username.focus();
    username.setImmediate(true);
    username.setRequired(true);
    username.setRequiredError("Login ID or Preplacedword cannot be empty");
    fields.addComponent(username);
    final PreplacedwordField preplacedword = new PreplacedwordField("Preplacedword");
    preplacedword.setRequired(true);
    preplacedword.setImmediate(true);
    preplacedword.setRequiredError("Login ID or Preplacedword cannot be empty");
    fields.addComponent(preplacedword);
    final Button login = new Button("Log In");
    login.addStyleName("default");
    fields.addComponent(login);
    fields.setComponentAlignment(login, Alignment.BOTTOM_LEFT);
    final ShortcutListener enter = new ShortcutListener("Login", KeyCode.ENTER, null) {

        @Override
        public void handleAction(Object sender, Object target) {
            login.click();
        }
    };
    login.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                username.validate();
                preplacedword.validate();
                LoginRequest request = new LoginRequest();
                request.setLoginName(username.getValue().trim());
                request.setPreplacedword(preplacedword.getValue());
                LoginResponse response = MainUI.this.loginService.dispatch(request);
                if (response != null) {
                    login.removeShortcutListener(enter);
                    if (getSession() != null) {
                        getSession().setAttribute("user", username.getValue());
                    }
                    MainUI.this.root.removeComponent(MainUI.this.loginLayout);
                    buildMainView();
                }
            } catch (EmptyValueException e) {
                ViewUtil.iscNotification(e.getMessage() + ".", Notification.Type.ERROR_MESSAGE);
                username.focus();
            } catch (Exception e) {
                username.focus();
                ViewUtil.iscNotification(e.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    login.addShortcutListener(enter);
    loginPanel.addComponent(fields);
    this.loginLayout.addComponent(loginPanel);
    this.loginLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
}