Exemple #1
0
            @Override
            public void config(
                RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
              UserModel user = appRealm.getUser("test-user@localhost");
              ApplicationModel accountApp =
                  appRealm
                      .getApplicationNameMap()
                      .get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
              for (String r : accountApp.getDefaultRoles()) {
                accountApp.grantRole(user, accountApp.getRole(r));
              }

              UserModel user2 = appRealm.addUser("test-user-no-access@localhost");
              user2.setEnabled(true);
              UserCredentialModel creds = new UserCredentialModel();
              creds.setType(CredentialRepresentation.PASSWORD);
              creds.setValue("password");
              appRealm.updateCredential(user2, creds);
            }
  public AddNewModuleDialog(
      final ApplicationModel model,
      final List<String> types,
      final NewModuleCreatedCallback callback,
      final Context errorDisplay) {
    super(false, true);
    okButton = new Button("Ok");
    okButton.addStyleName("btn");
    cancelButton = new Button("Cancel");
    okButton.addStyleName("btn");

    this.errorDisplay = errorDisplay;
    setTitle("Add new module");

    final Panel radioPanel = new HorizontalPanel();

    {
      final Panel daemonPanel;
      daemonPanel = new VerticalPanel();
      boolean wasChecked = false;
      for (final DaemonModel daemonModel : model.getDaemons()) {
        final RadioButton radio =
            new RadioButton("daemonRadioGroup", "Add to " + daemonModel.getName() + " daemon.");
        if (!wasChecked) {
          radio.setValue(true);
          wasChecked = true;
        }
        daemonPanel.add(radio);
        daemonRadios.put(daemonModel, radio);
      }

      if (daemonRadios.size() > 1) {
        radioPanel.add(daemonPanel);
      }
    }

    {
      final Panel typePanel = new VerticalPanel();
      boolean wasChecked = false;
      for (final String type : types) {
        if (!UiBuilderClient.NONE_TYPE.equals(type)) {
          final RadioButton radio =
              new RadioButton("typeRadioGroup", "Create " + type + " module.");
          if (!wasChecked) {
            radio.setValue(true);
            wasChecked = true;
          }
          typePanel.add(radio);
          typeRadios.put(type, radio);
        }
      }

      if (typeRadios.size() > 1) {
        radioPanel.add(typePanel);
      }
    }

    // If the user has no choice, just do the job
    if (skipDisplay()) {
      okClicked(callback);
      return;
    }

    final Panel buttonPanel = new HorizontalPanel();
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);

    okButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(final ClickEvent event) {
            okClicked(callback);
          }
        });

    cancelButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(final ClickEvent event) {
            hide();
          }
        });

    final Panel allPanel = new VerticalPanel();
    allPanel.add(radioPanel);
    allPanel.add(buttonPanel);
    add(allPanel);
  }