Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show auth window when performing import project from private repo or …
…use factory with private repo Signed-off-by: Max Shaposhnik <mshaposhnik@codenvy.com>
- Loading branch information
1 parent
13f2c56
commit 9465a57
Showing
37 changed files
with
636 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2AuthenticatorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.api.oauth; | ||
|
||
/** | ||
* Authenticators registry. | ||
* | ||
* @author Vitalii Parfonov | ||
*/ | ||
public interface OAuth2AuthenticatorRegistry { | ||
|
||
void registerAuthenticator(String providerName, OAuth2Authenticator oAuth2Authenticator); | ||
|
||
OAuth2Authenticator getAuthenticator(String providerName); | ||
} |
48 changes: 48 additions & 0 deletions
48
...e-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2AuthenticatorUrlProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.api.oauth; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.gwt.user.client.Window; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Constructs URL's to OAUth authentication depending on current host and rest context. | ||
* | ||
* @author Vitalii Parfonov | ||
*/ | ||
public class OAuth2AuthenticatorUrlProvider { | ||
|
||
private final static String oAuthServicePath = "/oauth/authenticate"; | ||
|
||
public static String get(String restContext, String authenticatePath) { | ||
return restContext + authenticatePath + "&redirect_after_login=" + redirect(); | ||
} | ||
|
||
|
||
public static String get(String restContext, String providerName, String userId, List<String> scopes) { | ||
final String scope = Joiner.on(',').join(scopes); | ||
|
||
return restContext + oAuthServicePath + "?oauth_provider=" + providerName + | ||
"&scope=" + scope + | ||
"&userId=" + userId + | ||
"&redirect_after_login=" + redirect(); | ||
} | ||
|
||
private static String redirect() { | ||
return Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/ws/"; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...e-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.oauth; | ||
|
||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.google.inject.Inject; | ||
|
||
import org.eclipse.che.ide.CoreLocalizationConstant; | ||
import org.eclipse.che.ide.api.oauth.OAuth2Authenticator; | ||
import org.eclipse.che.ide.ui.dialogs.CancelCallback; | ||
import org.eclipse.che.ide.ui.dialogs.ConfirmCallback; | ||
import org.eclipse.che.ide.ui.dialogs.DialogFactory; | ||
import org.eclipse.che.security.oauth.JsOAuthWindow; | ||
import org.eclipse.che.security.oauth.OAuthCallback; | ||
import org.eclipse.che.security.oauth.OAuthStatus; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* Default implementation of authenticator, used when no provider-specific one is present. | ||
* | ||
* @author Max Shaposhnik | ||
*/ | ||
public class DefaultOAuthAuthenticatorImpl implements OAuth2Authenticator, OAuthCallback { | ||
AsyncCallback<OAuthStatus> callback; | ||
|
||
private final DialogFactory dialogFactory; | ||
private final CoreLocalizationConstant localizationConstant; | ||
private String authenticationUrl; | ||
|
||
@Inject | ||
public DefaultOAuthAuthenticatorImpl(DialogFactory dialogFactory, | ||
CoreLocalizationConstant localizationConstant) { | ||
this.dialogFactory = dialogFactory; | ||
this.localizationConstant = localizationConstant; | ||
} | ||
|
||
@Override | ||
public void authorize(String authenticationUrl, @NotNull final AsyncCallback<OAuthStatus> callback) { | ||
this.authenticationUrl = authenticationUrl; | ||
this.callback = callback; | ||
showDialog(); | ||
} | ||
|
||
private void showDialog() { | ||
dialogFactory.createConfirmDialog(localizationConstant.authorizationDialogTitle(), localizationConstant.authorizationDialogText(), new ConfirmCallback() { | ||
@Override | ||
public void accepted() { | ||
showAuthWindow(); | ||
} | ||
}, new CancelCallback() { | ||
@Override | ||
public void cancelled() { | ||
callback.onSuccess(OAuthStatus.NOT_PERFORMED); | ||
} | ||
}).show(); | ||
} | ||
|
||
@Override | ||
public String getProviderName() { | ||
return "default"; | ||
} | ||
|
||
|
||
@Override | ||
public void onAuthenticated(OAuthStatus authStatus) { | ||
callback.onSuccess(authStatus); | ||
} | ||
|
||
private void showAuthWindow() { | ||
JsOAuthWindow authWindow; | ||
authWindow = new JsOAuthWindow(authenticationUrl, "error.url", 500, 980, this); | ||
authWindow.loginWithOAuth(); | ||
} | ||
} |
Oops, something went wrong.