summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/commandLine/AuthenticationCallback.java
blob: 11fb831803bba21b1984db220e9df6b68483f5c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.svn.commandLine;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.dialogs.SimpleCredentialsDialog;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.SVNAuthentication;

import java.io.File;
import java.net.PasswordAuthentication;

/**
 * Passed for authentication purpose to SvnLineCommand
 * Called when svn command indicates that it needs credentials. It also means that credential was not found in standard place
 * (Subversion config directory)
 *
 * Implementations should 1) ask credential from user or take it from any other storage (memory, for instance)
 * 2) write credential in Subversion standard form into
 * a) standard config directory if user allowed to save *all* credentials
 * b) TMP directory and return path to the directory from getSpecialConfigDir() - if user rejected at least one credential storing
 *
 * Please note that several credentials could be asked during the command and therefore implementation class is used as
 * keeping its state, and that TMP directory should be reused for all written credentials
 *
 * User: Irina.Chernushina
 * Date: 2/26/13
 * Time: 1:05 PM
 */
public interface AuthenticationCallback {
  /**
   * Authenticate for realm and base file belonging to corresponding working copy
   *
   * @param realm           - realm that should be used for credential retrieval/storage.
   * @param repositoryUrl
   * @param previousFailed  - whether previous credentials were correct
   * @param passwordRequest - if true, password should be asked. Otherwise that may be a certificate (determined by the protocol)
   * @return false if authentication canceled or was unsuccessful
   */
  boolean authenticateFor(@Nullable String realm, SVNURL repositoryUrl, boolean previousFailed, boolean passwordRequest);

  /**
   * Provides authentication information to access given url by authentication protocol identified by type.
   * For instance, username/password for http/svn protocols. SSL client certificate for two way SSL protocol.
   *
   * @param repositoryUrl
   * @param type          authentication protocol type with svn specific values, like "svn.simple" for http.
   * @return
   */
  @Nullable
  SVNAuthentication requestCredentials(SVNURL repositoryUrl, String type);

  /**
   * @return config directory if TMP was created
   */
  @Nullable
  File getSpecialConfigDir();

  @Nullable
  String requestSshCredentials(@NotNull String realm,
                               @NotNull SimpleCredentialsDialog.Mode mode,
                               @NotNull String key);

  /**
   * Ask user or read from memory storage whether server certificate should be accepted
   *
   * @param repositoryUrl
   * @param realm         - realm that should be used for credential retrieval/storage.
   * @return true is certificate was accepted
   */
  boolean acceptSSLServerCertificate(SVNURL repositoryUrl, final String realm);

  /**
   * Clear credentials stored anywhere - in case they were not full, wrong or anything else
   *
   * @param realm         - required that credential
   * @param repositoryUrl
   * @param password      - whether password credential should be deleted or certificate, if protocol might demand certificate
   */
  void clearPassiveCredentials(String realm, SVNURL repositoryUrl, boolean password);

  /**
   * @return true if there's something from IDEA config that should be persisted into Subversion tmp config directory
   * for successful call
   * (now it's IDEA proxy settings)
   */
  boolean haveDataForTmpConfig();

  @Nullable
  PasswordAuthentication getProxyAuthentication(@NotNull SVNURL repositoryUrl);

  void reset();
}