Package com.gitblit.transport.ssh

Examples of com.gitblit.transport.ssh.SshKey


      List<SshKey> keys = keyManager.getKeys(username);
      if (index > keys.size()) {
        throw new UnloggedFailure(1"Invalid key index!");
      }

      SshKey key = keys.get(index - 1);
      AccessPermission permission = AccessPermission.fromCode(value);
      if (permission.exceeds(AccessPermission.NONE)) {
        try {
          key.setPermission(permission);
        } catch (IllegalArgumentException e) {
          throw new Failure(1, e.getMessage());
        }
      }
      if (keyManager.addKey(username, key)) {
View Full Code Here


    final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<SshKey> item) {
        final SshKey key = item.getModelObject();
        item.add(new Label("comment", key.getComment()));
        item.add(new Label("fingerprint", key.getFingerprint()));
        item.add(new Label("permission", key.getPermission().toString()));
        item.add(new Label("algorithm", key.getAlgorithm()));

        AjaxLink<Void> delete = new AjaxLink<Void>("delete") {

          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            if (app().keys().removeKey(user.username, key)) {
              // reset the keys list
              keys.clear();
              keys.addAll(app().keys().getKeys(user.username));

              // update the panel
              target.addComponent(SshKeysPanel.this);
            }
          }
        };
        item.add(delete);
      }
    };
    add(keysView);

    Form<Void> addKeyForm = new Form<Void>("addKeyForm");

    final IModel<String> keyData = Model.of("");
    addKeyForm.add(new TextAreaOption("addKeyData",
        getString("gb.key"),
        null,
        "span5",
        keyData));

    final IModel<AccessPermission> keyPermission = Model.of(AccessPermission.PUSH);
    addKeyForm.add(new ChoiceOption<AccessPermission>("addKeyPermission",
        getString("gb.permission"),
        getString("gb.sshKeyPermissionDescription"),
        keyPermission,
        Arrays.asList(AccessPermission.SSHPERMISSIONS)));

    final IModel<String> keyComment = Model.of("");
    addKeyForm.add(new TextOption("addKeyComment",
        getString("gb.comment"),
        getString("gb.sshKeyCommentDescription"),
        "span5",
        keyComment));

    addKeyForm.add(new AjaxButton("addKeyButton") {

      private static final long serialVersionUID = 1L;

      @Override
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

        UserModel user = GitBlitWebSession.get().getUser();
        String data = keyData.getObject();
        if (StringUtils.isEmpty(data)) {
          // do not submit empty key
          return;
        }

        SshKey key = new SshKey(data);
        try {
          key.getPublicKey();
        } catch (Exception e) {
          // failed to parse the key
          return;
        }

        AccessPermission permission = keyPermission.getObject();
        key.setPermission(permission);

        String comment  = keyComment.getObject();
        if (!StringUtils.isEmpty(comment)) {
          key.setComment(comment);
        }

        if (app().keys().addKey(user.username, key)) {
          // reset add key fields
          keyData.setObject("");
View Full Code Here

TOP

Related Classes of com.gitblit.transport.ssh.SshKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.