2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.cvsSupport2
.connections
.ssh
;
18 import com
.intellij
.openapi
.util
.io
.FileUtil
;
19 import com
.trilead
.ssh2
.Connection
;
20 import org
.netbeans
.lib
.cvsclient
.connection
.AuthenticationException
;
23 import java
.io
.IOException
;
25 public class SshPublicKeyAuthentication
implements SshAuthentication
{
26 private final String myLogin
;
27 private final File myFile
;
28 private final SSHPasswordProvider myPasswordProvider
;
29 private final String myCvsRootAsString
;
31 public SshPublicKeyAuthentication(final File file
, final String login
, final SSHPasswordProvider passwordProvider
,
32 final String cvsRootAsString
) {
35 myPasswordProvider
= passwordProvider
;
36 myCvsRootAsString
= cvsRootAsString
;
39 public void authenticate(final Connection connection
) throws AuthenticationException
, SolveableAuthenticationException
{
42 keyChars
= FileUtil
.loadFileText(myFile
);
44 catch (IOException e
) {
45 throw new SolveableAuthenticationException("Cannot load public key file.");
49 final String password
= myPasswordProvider
.getPPKPasswordForCvsRoot(myCvsRootAsString
);
50 if (! connection
.authenticateWithPublicKey(myLogin
, keyChars
, password
)) {
51 throw new SolveableAuthenticationException("Authentication rejected.");
54 catch (IOException e
) {
55 throw new SolveableAuthenticationException(e
.getMessage(), e
);