Properly catch Not Allowed (405) and Unknown Request (501) errors
| | |
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Exception to indicate that the requested action has been disabled on the
|
| | | * Gitblit server.
|
| | | */
|
| | | public static class NotAllowedException extends GitBlitException {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public NotAllowedException(String message) {
|
| | | super(message);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Exception to indicate that the requested action can not be executed by
|
| | | * the server because it does not recognize the request type.
|
| | |
| | | import java.util.Map;
|
| | |
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.GitBlitException.UnknownRequestException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
| | |
|
| | | try {
|
| | | refreshUsers();
|
| | | refreshSettings();
|
| | | allowManagement = true;
|
| | | } catch (UnauthorizedException e) {
|
| | | } catch (ForbiddenException e) {
|
| | | } catch (NotAllowedException e) {
|
| | | } catch (UnknownRequestException e) {
|
| | | } catch (IOException e) {
|
| | | System.err.println(e.getMessage());
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | try {
|
| | | refreshSettings();
|
| | | refreshStatus();
|
| | | allowAdministration = true;
|
| | | } catch (UnauthorizedException e) {
|
| | | } catch (ForbiddenException e) {
|
| | | } catch (NotAllowedException e) {
|
| | | } catch (UnknownRequestException e) {
|
| | | } catch (IOException e) {
|
| | | System.err.println(e.getMessage());
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | import org.eclipse.jgit.util.FS;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | /**
|
| | |
| | | if (cause instanceof ConnectException) {
|
| | | JOptionPane.showMessageDialog(GitblitManager.this, cause.getMessage(),
|
| | | Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
|
| | | } else if (cause instanceof ForbiddenException) {
|
| | | JOptionPane
|
| | | .showMessageDialog(
|
| | | GitblitManager.this,
|
| | | "This Gitblit server does not allow RPC Management or Administration",
|
| | | Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
|
| | | } else {
|
| | | Utils.showException(GitblitManager.this, t);
|
| | | }
|
| | |
| | | dialog.setLocationRelativeTo(GitblitPanel.this);
|
| | | dialog.setUsers(null, gitblit.getUsernames(), null);
|
| | | dialog.setRepositories(gitblit.getRepositories());
|
| | | dialog.setFederationSets(gitblit.getFederationSets(), null);
|
| | | dialog.setVisible(true);
|
| | | final RepositoryModel newRepository = dialog.getRepository();
|
| | | final List<String> permittedUsers = dialog.getPermittedUsers();
|
| | |
| | |
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.GitBlitException.UnknownRequestException;
|
| | |
|
| | | public abstract class GitblitWorker extends SwingWorker<Boolean, Void> {
|
| | |
|
| | |
| | | Utils.explainForbidden(parent, request);
|
| | | } else if (t instanceof UnauthorizedException) {
|
| | | Utils.explainUnauthorized(parent, request);
|
| | | } else if (t instanceof NotAllowedException) {
|
| | | Utils.explainNotAllowed(parent, request);
|
| | | } else if (t instanceof UnknownRequestException) {
|
| | | Utils.explainNotAllowed(parent, request);
|
| | | } else {
|
| | | Utils.showException(parent, t);
|
| | | }
|
| | |
| | | return table;
|
| | | }
|
| | |
|
| | | public static void explainNotAllowed(Component c, RpcRequest request) {
|
| | | String msg = MessageFormat.format("The Gitblit server does not allow the request \"{0}\".",
|
| | | request.name());
|
| | | JOptionPane.showMessageDialog(c, msg, "Not Allowed", JOptionPane.ERROR_MESSAGE);
|
| | | }
|
| | |
|
| | | public static void explainForbidden(Component c, RpcRequest request) {
|
| | | String msg = MessageFormat.format(
|
| | | "The request \"{0}\" has been forbidden by the Gitblit server.", request.name());
|
| | | "The request \"{0}\" has been forbidden for the account by the Gitblit server.",
|
| | | request.name());
|
| | | JOptionPane.showMessageDialog(c, msg, "Forbidden", JOptionPane.ERROR_MESSAGE);
|
| | | }
|
| | |
|
| | |
| | | JOptionPane.showMessageDialog(c, msg, "Unauthorized", JOptionPane.ERROR_MESSAGE);
|
| | | }
|
| | |
|
| | | public static void explainUnknown(Component c, RpcRequest request) {
|
| | | String msg = MessageFormat.format(
|
| | | "The request \"{0}\" is not recognized by the Gitblit server.", request.name());
|
| | | JOptionPane.showMessageDialog(c, msg, "Unknown Request", JOptionPane.ERROR_MESSAGE);
|
| | | }
|
| | |
|
| | | public static void showException(Component c, Throwable t) {
|
| | | StringWriter writer = new StringWriter();
|
| | | t.printStackTrace(new PrintWriter(writer));
|
| | |
| | | import org.eclipse.jgit.util.Base64;
|
| | |
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.GitBlitException.UnknownRequestException;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
| | | } else if (e.getMessage().indexOf("403") > -1) {
|
| | | // requested url is forbidden by the requesting user
|
| | | throw new ForbiddenException(url);
|
| | | } else if (e.getMessage().indexOf("405") > -1) {
|
| | | // requested url is not allowed by the server
|
| | | throw new NotAllowedException(url);
|
| | | } else if (e.getMessage().indexOf("501") > -1) {
|
| | | // requested url is not recognized by the server
|
| | | throw new UnknownRequestException(url);
|
| | | }
|
| | | throw e;
|
| | | }
|
| | |
| | | } else if (e.getMessage().indexOf("403") > -1) {
|
| | | // requested url is forbidden by the requesting user
|
| | | throw new ForbiddenException(url);
|
| | | } else if (e.getMessage().indexOf("405") > -1) {
|
| | | // requested url is not allowed by the server
|
| | | throw new NotAllowedException(url);
|
| | | } else if (e.getMessage().indexOf("501") > -1) {
|
| | | // requested url is not recognized by the server
|
| | | throw new UnknownRequestException(url);
|