Skip to content

Commit 1103647

Browse files
author
Igor Vinokur
authored
CODENVY-687: Сache svn credentials instead of storing them in credentials provider (eclipse-che#2672)
1 parent 1123da1 commit 1103647

65 files changed

Lines changed: 1135 additions & 1258 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/che-core-api-core/src/main/java/org/eclipse/che/api/core/ErrorCodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private ErrorCodes() {
2323
public static final int NO_COMMITTER_NAME_OR_EMAIL_DEFINED = 15216;
2424
public static final int UNABLE_GET_PRIVATE_SSH_KEY = 32068;
2525
public static final int UNAUTHORIZED_GIT_OPERATION = 32080;
26+
public static final int UNAUTHORIZED_SVN_OPERATION = 32090;
2627
public static final int MERGE_CONFLICT = 32062;
2728
public static final int FAILED_CHECKOUT = 32063;
2829
public static final int FAILED_CHECKOUT_WITH_START_POINT = 32064;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2016 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.ide.api.subversion;
12+
13+
/**
14+
* Credentials object for subversion operations.
15+
*
16+
* @author Igor Vinokur
17+
*/
18+
public class Credentials {
19+
private String username;
20+
private String password;
21+
22+
public Credentials(String username, String password) {
23+
this.username = username;
24+
this.password = password;
25+
}
26+
27+
/**
28+
* Returns user name for authentication.
29+
*/
30+
public String getUsername() {
31+
return username;
32+
}
33+
34+
/**
35+
* Set user name for authentication.
36+
*/
37+
public void setUsername(String username) {
38+
this.username = username;
39+
}
40+
41+
/**
42+
* Returns password for authentication.
43+
*/
44+
public String getPassword() {
45+
return password;
46+
}
47+
48+
/**
49+
* Set password for authentication.
50+
*/
51+
public void setPassword(String password) {
52+
this.password = password;
53+
}
54+
}

plugins/plugin-svn/che-plugin-svn-ext-server/src/main/java/org/eclipse/che/plugin/svn/server/credentials/CredentialsException.java renamed to ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/subversion/SubversionCredentialsDialog.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
* Contributors:
99
* Codenvy, S.A. - initial API and implementation
1010
*******************************************************************************/
11-
package org.eclipse.che.plugin.svn.server.credentials;
11+
//TODO This is used in wizard/ProjectImporter, find a solution to move it to plugin-svn.
12+
package org.eclipse.che.ide.api.subversion;
1213

13-
public class CredentialsException extends Exception {
14+
import org.eclipse.che.api.promises.client.Promise;
1415

15-
private static final long serialVersionUID = 1L;
16-
17-
public CredentialsException(final Throwable e) {
18-
super(e);
19-
}
20-
21-
public CredentialsException(final String message) {
22-
super(message);
23-
}
16+
/**
17+
* Dialog for retrieving credentials for SVN operations.
18+
*
19+
* @author Igor Vinokur
20+
*/
21+
public interface SubversionCredentialsDialog {
2422

23+
/**
24+
* Returns credentials from dialog.
25+
*
26+
* @return {@link Credentials} that contains user name and password
27+
*/
28+
Promise<Credentials> askCredentials();
2529
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporter.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.eclipse.che.ide.api.oauth.OAuth2Authenticator;
3030
import org.eclipse.che.ide.api.oauth.OAuth2AuthenticatorRegistry;
3131
import org.eclipse.che.ide.api.oauth.OAuth2AuthenticatorUrlProvider;
32+
import org.eclipse.che.ide.api.subversion.Credentials;
33+
import org.eclipse.che.ide.api.subversion.SubversionCredentialsDialog;
3234
import org.eclipse.che.ide.api.project.MutableProjectConfig;
3335
import org.eclipse.che.ide.api.project.wizard.ImportProjectNotificationSubscriberFactory;
3436
import org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber;
@@ -45,6 +47,7 @@
4547
import static com.google.common.base.Strings.isNullOrEmpty;
4648
import static org.eclipse.che.api.core.ErrorCodes.UNABLE_GET_PRIVATE_SSH_KEY;
4749
import static org.eclipse.che.api.core.ErrorCodes.UNAUTHORIZED_GIT_OPERATION;
50+
import static org.eclipse.che.api.core.ErrorCodes.UNAUTHORIZED_SVN_OPERATION;
4851
import static org.eclipse.che.api.git.shared.ProviderInfo.AUTHENTICATE_URL;
4952
import static org.eclipse.che.api.git.shared.ProviderInfo.PROVIDER_NAME;
5053
import static org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest;
@@ -60,6 +63,7 @@ public class ProjectImporter extends AbstractImporter {
6063
private final CoreLocalizationConstant localizationConstant;
6164
private final ProjectResolver projectResolver;
6265
private final String restContext;
66+
private final SubversionCredentialsDialog credentialsDialog;
6367
private final OAuth2AuthenticatorRegistry oAuth2AuthenticatorRegistry;
6468

6569

@@ -69,11 +73,13 @@ public ProjectImporter(CoreLocalizationConstant localizationConstant,
6973
AppContext appContext,
7074
ProjectResolver projectResolver,
7175
@RestContext String restContext,
76+
SubversionCredentialsDialog credentialsDialog,
7277
OAuth2AuthenticatorRegistry oAuth2AuthenticatorRegistry) {
7378
super(appContext, subscriberFactory);
7479
this.localizationConstant = localizationConstant;
7580
this.projectResolver = projectResolver;
7681
this.restContext = restContext;
82+
this.credentialsDialog = credentialsDialog;
7783
this.oAuth2AuthenticatorRegistry = oAuth2AuthenticatorRegistry;
7884
}
7985

@@ -136,6 +142,8 @@ public Promise<Project> apply(PromiseError exception) throws FunctionException {
136142
switch (getErrorCode(exception.getCause())) {
137143
case UNABLE_GET_PRIVATE_SSH_KEY:
138144
throw new IllegalStateException(localizationConstant.importProjectMessageUnableGetSshKey());
145+
case UNAUTHORIZED_SVN_OPERATION:
146+
return recallImportWithCredentials(sourceStorage, path);
139147
case UNAUTHORIZED_GIT_OPERATION:
140148
final Map<String, String> attributes = ExceptionUtils.getAttributes(exception.getCause());
141149
final String providerName = attributes.get(PROVIDER_NAME);
@@ -156,6 +164,32 @@ public Promise<Project> apply(PromiseError exception) throws FunctionException {
156164
});
157165
}
158166

167+
private Promise<Project> recallImportWithCredentials(final SourceStorage sourceStorage, final Path path) {
168+
return createFromAsyncRequest(new RequestCall<Project>() {
169+
@Override
170+
public void makeCall(final AsyncCallback<Project> callback) {
171+
credentialsDialog.askCredentials().then(new Operation<Credentials>() {
172+
@Override
173+
public void apply(Credentials credentials) throws OperationException {
174+
sourceStorage.getParameters().put("username", credentials.getUsername());
175+
sourceStorage.getParameters().put("password", credentials.getPassword());
176+
doImport(path, sourceStorage).then(new Operation<Project>() {
177+
@Override
178+
public void apply(Project project) throws OperationException {
179+
callback.onSuccess(project);
180+
}
181+
}).catchError(new Operation<PromiseError>() {
182+
@Override
183+
public void apply(PromiseError error) throws OperationException {
184+
callback.onFailure(error.getCause());
185+
}
186+
});
187+
}
188+
});
189+
}
190+
});
191+
}
192+
159193
private Promise<Project> authUserAndRecallImport(final String providerName,
160194
final String authenticateUrl,
161195
final Path path,

ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public void setUp() {
9595
appContext,
9696
resolver,
9797
null,
98+
null,
9899
null);
99100
}
100101

plugins/plugin-svn/che-plugin-svn-ext-ide/src/main/java/org/eclipse/che/plugin/svn/ide/SubversionClientService.java

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
package org.eclipse.che.plugin.svn.ide;
1212

1313
import org.eclipse.che.api.promises.client.Promise;
14+
import org.eclipse.che.commons.annotation.Nullable;
15+
import org.eclipse.che.ide.api.subversion.Credentials;
1416
import org.eclipse.che.ide.resource.Path;
1517
import org.eclipse.che.plugin.svn.shared.CLIOutputResponse;
1618
import org.eclipse.che.plugin.svn.shared.CLIOutputResponseList;
@@ -84,34 +86,41 @@ Promise<CLIOutputResponse> add(Path project,
8486
* source item path
8587
* @param destination
8688
* destination path
89+
* @param credentials
90+
* {@link Credentials} object that contains user name and password for authentication
8791
*/
88-
Promise<CLIOutputResponse> copy(Path project, Path source, Path destination, String comment);
92+
Promise<CLIOutputResponse> copy(Path project,
93+
Path source,
94+
Path destination,
95+
String comment,
96+
@Nullable Credentials credentials);
8997

9098
/**
9199
* Merge specified URL with target.
92100
*
93101
* @param project
94-
* project path
102+
* project path
95103
* @param target
96-
* target directory
104+
* target directory
97105
* @param sourceUrl
98-
* source URL to merge
106+
* source URL to merge
99107
*/
100108
Promise<CLIOutputResponse> merge(Path project, Path target, Path sourceUrl);
101109

102110
/**
103111
* Retrieves the information about repository item.
104112
*
105113
* @param project
106-
* relative path to the project in local workspace
114+
* relative path to the project in local workspace
107115
* @param target
108-
* target to operate
116+
* target to operate
109117
* @param revision
110-
* revision, use HEAD to specify latest revision
111-
* @param children
112-
* whether list children or not
118+
* revision, use HEAD to specify latest revision
119+
* @param credentials
120+
* {@link Credentials} object that contains user name and password for authentication
113121
*/
114-
Promise<InfoResponse> info(Path project, Path target, String revision, boolean children);
122+
Promise<InfoResponse> info(Path project, Path target, String revision, boolean children, @Nullable Credentials credentials);
123+
115124
Promise<InfoResponse> info(Path project, String target, String revision, boolean children);
116125

117126
/**
@@ -161,12 +170,20 @@ Promise<CLIOutputResponse> status(Path project,
161170
* whether or not to ignore externals (--ignore-externals)
162171
* @param accept
163172
* the accept argument (--accept)
173+
* @param credentials
174+
* {@link Credentials} object that contains user name and password for authentication
164175
*/
165-
Promise<CLIOutputWithRevisionResponse> update(Path project, Path[] paths, String revision, String depth, boolean ignoreExternals, String accept);
176+
Promise<CLIOutputWithRevisionResponse> update(Path project,
177+
Path[] paths,
178+
String revision,
179+
String depth,
180+
boolean ignoreExternals,
181+
String accept,
182+
@Nullable Credentials credentials);
166183

167184
Promise<CLIOutputResponse> showLog(Path project, Path[] paths, String revision);
168185

169-
Promise<CLIOutputResponse> showDiff(Path project, Path[] paths, String revision);
186+
Promise<CLIOutputResponse> showDiff(Path project, Path[] paths, String revision, @Nullable Credentials credentials);
170187

171188
/**
172189
* Locks the given paths.
@@ -178,8 +195,10 @@ Promise<CLIOutputResponse> status(Path project,
178195
* @param force
179196
* if false, will warn if another user already has a lock on a target, leave this target unchanged, and continue.<br>
180197
* if true, will steal the lock from the previous owner instead
198+
* @param credentials
199+
* {@link Credentials} object that contains user name and password for authentication
181200
*/
182-
Promise<CLIOutputResponse> lock(Path project, Path[] paths, boolean force);
201+
Promise<CLIOutputResponse> lock(Path project, Path[] paths, boolean force, @Nullable Credentials credentials);
183202

184203
/**
185204
* Unocks the given paths.
@@ -191,8 +210,10 @@ Promise<CLIOutputResponse> status(Path project,
191210
* @param force
192211
* if false, will warn if another user already has a lock on a target, leave this target unchanged, and continue.<br>
193212
* if true, will unlock anyway
213+
* @param credentials
214+
* {@link Credentials} object that contains user name and password for authentication
194215
*/
195-
Promise<CLIOutputResponse> unlock(Path project, Path[] paths, boolean force);
216+
Promise<CLIOutputResponse> unlock(Path project, Path[] paths, boolean force, @Nullable Credentials credentials);
196217

197218
/**
198219
* Commits the changes in the repository.
@@ -224,19 +245,21 @@ Promise<CLIOutputResponse> status(Path project,
224245

225246
Promise<CLIOutputResponseList> resolve(Path project, Map<String, String> resolutions, String depth);
226247

227-
Promise<Void> saveCredentials(String repositoryUrl, String username, String password);
228-
229248
/**
230249
* Move provided path.
231250
*
232251
* @param project
233252
* the project path
234253
* @param source
235254
* source item path
236-
* @param destination
237-
* destination path
255+
* @param credentials
256+
* {@link Credentials} object that contains user name and password for authentication
238257
*/
239-
Promise<CLIOutputResponse> move(Path project, Path source, Path destination, String comment);
258+
Promise<CLIOutputResponse> move(Path project,
259+
Path source,
260+
Path destination,
261+
String comment,
262+
@Nullable Credentials credentials);
240263

241264
/**
242265
* Set specified property to a path or a target.
@@ -259,17 +282,22 @@ Promise<CLIOutputResponse> status(Path project,
259282
/**
260283
* Get specified property for a path or a target.
261284
*
262-
* @param project the project path
263-
* @param propertyName the property name
264-
* @param path path to which property get
285+
* @param project
286+
* the project path
287+
* @param propertyName
288+
* the property name
289+
* @param path
290+
* path to which property get
265291
*/
266292
Promise<CLIOutputResponse> propertyGet(Path project, String propertyName, Path path);
267293

268294
/**
269295
* Get properties set for a path or a target.
270296
*
271-
* @param project the project path
272-
* @param path path to which property get
297+
* @param project
298+
* the project path
299+
* @param path
300+
* path to which property get
273301
*/
274302
Promise<CLIOutputResponse> propertyList(Path project, Path path);
275303

0 commit comments

Comments
 (0)