mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-15 16:51:07 +00:00
refactoring of the OAuthLoginPanel to be UI-Binder based
This commit is contained in:
1 parent
6b31d79f88
commit
cff05a49fe
13 files changed
+306
-307
No files matched your search
+156
@@ -0,0 +1,156 @@
|
||||
package com.sap.sse.security.ui.client.shared.oauthlogin;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sse.security.ui.oauth.client.CredentialDTO;
|
||||
import com.sap.sse.security.ui.oauth.client.util.ClientUtils;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public class OAuthLogin extends Composite {
|
||||
private static OAuthLoginUiBinder uiBinder = GWT.create(OAuthLoginUiBinder.class);
|
||||
|
||||
interface OAuthLoginUiBinder extends UiBinder<Widget, OAuthLogin> {
|
||||
}
|
||||
|
||||
private static final String SAP_SAILING_OAUTH_WINDOW = "sap_sailing_oauth_verification_window";
|
||||
|
||||
@UiField Anchor facebookAnchor;
|
||||
@UiField Anchor googleAnchor;
|
||||
@UiField Anchor twitterAnchor;
|
||||
@UiField Anchor linkedinAnchor;
|
||||
@UiField Anchor yahooAnchor;
|
||||
@UiField Anchor vimeoAnchor;
|
||||
@UiField Anchor githubAnchor;
|
||||
@UiField Anchor instagramAnchor;
|
||||
@UiField Anchor flickrAnchor;
|
||||
@UiField Anchor liveAnchor;
|
||||
@UiField Anchor tumblrAnchor;
|
||||
@UiField Anchor foursquareAnchor;
|
||||
|
||||
public static OAuthLoginResources images = OAuthLoginResources.INSTANCE;
|
||||
|
||||
private UserManagementServiceAsync userManagementService;
|
||||
|
||||
public OAuthLogin(UserManagementServiceAsync userManagementService) {
|
||||
this.userManagementService = userManagementService;
|
||||
|
||||
OAuthLoginResources.INSTANCE.css().ensureInjected();
|
||||
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
}
|
||||
|
||||
private void retreiveAndStoreAuthorizationUrl(final int authProvider) {
|
||||
// String authProviderName = ClientUtils.getAuthProviderName(authProvider);
|
||||
final String callbackUrl = ClientUtils.getCallbackUrl();
|
||||
GWT.log("Getting authorization url");
|
||||
final CredentialDTO credential = new CredentialDTO();
|
||||
credential.setRedirectUrl(callbackUrl);
|
||||
credential.setAuthProvider(authProvider);
|
||||
userManagementService.getAuthorizationUrl(credential, new AsyncCallback<String>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
ClientUtils.handleException(caught);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
String authorizationUrl = result;
|
||||
GWT.log("Authorization url: " + authorizationUrl);
|
||||
|
||||
// clear all cookies first
|
||||
ClientUtils.clearCookies();
|
||||
|
||||
// save the auth provider to cookie
|
||||
ClientUtils.saveAuthProvider(authProvider);
|
||||
|
||||
// save the redirect url to a cookie as well
|
||||
// we need to redirect there after logout
|
||||
ClientUtils.saveRediretUrl(callbackUrl);
|
||||
|
||||
Window.open(authorizationUrl, SAP_SAILING_OAUTH_WINDOW, "status=no,toolbar=no,location=no,menubar=no,width=640px,height=480px");
|
||||
// popupFrame.setUrl(authorizationUrl);
|
||||
// popupPanel.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiHandler("facebookAnchor")
|
||||
void facebookAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Facebook");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("googleAnchor")
|
||||
void googleAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Google");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("twitterAnchor")
|
||||
void twitterAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Twitter");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("yahooAnchor")
|
||||
void yahooAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Yahoo!");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("linkedinAnchor")
|
||||
void linkedinAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Linkedin");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("instagramAnchor")
|
||||
void instagramAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Instagram");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("vimeoAnchor")
|
||||
void vimeoAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Vimeo");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("githubAnchor")
|
||||
void githubAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("github");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("flickrAnchor")
|
||||
void flickrAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("flickr");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("liveAnchor")
|
||||
void liveAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Windows Live");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("tumblrAnchor")
|
||||
void tumblrAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("tumblr.");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
|
||||
@UiHandler("foursquareAnchor")
|
||||
void foursquareAnchorClicked(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("foursquare");
|
||||
retreiveAndStoreAuthorizationUrl(authProvider);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
<ui:with field="i18n" type="com.sap.sse.security.ui.client.StringMessages"/>
|
||||
<ui:with field="local_res" type="com.sap.sse.security.ui.client.shared.oauthlogin.OAuthLoginResources" />
|
||||
<g:HTMLPanel>
|
||||
<div>
|
||||
<ui:text from='{i18n.signInWith}'/>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="facebookAnchor">
|
||||
<img src="{local_res.facebookIcon.getSafeUri}" title="facebook" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="googleAnchor">
|
||||
<img src="{local_res.googleIcon.getSafeUri}" title="Google"/>
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="twitterAnchor">
|
||||
<img src="{local_res.twitterIcon.getSafeUri}" title="Twitter" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="linkedinAnchor">
|
||||
<img src="{local_res.linkedinIcon.getSafeUri}" title="LinkedIn" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="yahooAnchor">
|
||||
<img src="{local_res.yahooIcon.getSafeUri}" title="Yahoo" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="vimeoAnchor">
|
||||
<img src="{local_res.vimeoIcon.getSafeUri}" title="Vimeo" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="githubAnchor">
|
||||
<img src="{local_res.githubIcon.getSafeUri}" title="github" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="instagramAnchor">
|
||||
<img src="{local_res.instagramIcon.getSafeUri}" title="Instagram" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="flickrAnchor">
|
||||
<img src="{local_res.flickrIcon.getSafeUri}" title="flickr" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="liveAnchor">
|
||||
<img src="{local_res.liveIcon.getSafeUri}" title="Windows Live" />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="tumblrAnchor">
|
||||
<img src="{local_res.tumblrIcon.getSafeUri}" title="tumblr." />
|
||||
</g:Anchor>
|
||||
<g:Anchor href="javascript:;" styleName="{local_res.css.oauthLogo}" ui:field="foursquareAnchor">
|
||||
<img src="{local_res.foursquareIcon.getSafeUri}" title="foursquare" />
|
||||
</g:Anchor>
|
||||
</div>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
.panel {
|
||||
}
|
||||
|
||||
.oauthLogo {
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.sap.sse.security.ui.client.shared.oauthlogin;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.CssResource;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
|
||||
public interface OAuthLoginResources extends ClientBundle {
|
||||
public static final OAuthLoginResources INSTANCE = GWT.create(OAuthLoginResources.class);
|
||||
|
||||
@Source("com/sap/sse/security/ui/client/shared/oauthlogin/OAuthLoginResources.css")
|
||||
LocalCss css();
|
||||
|
||||
public interface LocalCss extends CssResource {
|
||||
String oauthLogo();
|
||||
}
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/facebook.png")
|
||||
public ImageResource facebookIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/flickr.png")
|
||||
public ImageResource flickrIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/github.png")
|
||||
public ImageResource githubIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/google.png")
|
||||
public ImageResource googleIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/linkedin.png")
|
||||
public ImageResource linkedinIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/twitter.png")
|
||||
public ImageResource twitterIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/vimeo.png")
|
||||
public ImageResource vimeoIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/wordpress.png")
|
||||
public ImageResource wordpressIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/yahoo.png")
|
||||
public ImageResource yahooIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/instagram.png")
|
||||
public ImageResource instagramIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/imgur.png")
|
||||
public ImageResource imgurIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/live32.png")
|
||||
public ImageResource liveIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/tumblr.png")
|
||||
public ImageResource tumblrIcon();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/foursquare.png")
|
||||
public ImageResource foursquareIcon();
|
||||
}
|
||||
+4
-3
@@ -19,10 +19,9 @@ import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sse.gwt.client.async.MarkedAsyncCallback;
|
||||
import com.sap.sse.security.shared.UserManagementException;
|
||||
import com.sap.sse.security.ui.client.EntryPointLinkFactory;
|
||||
import com.sap.sse.security.ui.client.Resources;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.client.shared.oauthlogin.OAuthLogin;
|
||||
import com.sap.sse.security.ui.shared.SuccessInfo;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
@@ -46,12 +45,14 @@ public class LoginView extends Composite {
|
||||
this.userManagementService = userManagementService;
|
||||
this.userService = userService;
|
||||
|
||||
LoginViewResources.INSTANCE.css().ensureInjected();
|
||||
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
||||
String registrationLink = EntryPointLinkFactory.createRegistrationLink(Collections.<String, String> emptyMap());
|
||||
signUpAnchor.setHref(registrationLink);
|
||||
|
||||
oAuthPanel.add(new OAuthLoginPanel(userManagementService, Resources.INSTANCE.css()));
|
||||
oAuthPanel.add(new OAuthLogin(userManagementService));
|
||||
|
||||
userNameTextBox.setFocus(true);
|
||||
}
|
||||
|
||||
+14
-10
@@ -2,15 +2,19 @@
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
<ui:with field="i18n" type="com.sap.sse.security.ui.client.StringMessages"/>
|
||||
<ui:with field="locaL_res" type="com.sap.sse.security.ui.login.LoginViewResources" />
|
||||
<g:HTMLPanel styleName="{locaL_res.css.centerForm}">
|
||||
<div><ui:text from='{i18n.username}'/></div>
|
||||
<div><g:TextBox ui:field="userNameTextBox" /></div>
|
||||
<div><ui:text from='{i18n.password}'/></div>
|
||||
<div><g:PasswordTextBox ui:field="passwordTextBox" /></div>
|
||||
<g:Button ui:field="loginButton" text="{i18n.signIn}" />
|
||||
<g:Button ui:field="passwordResetButton" text="{i18n.resetPassword}" />
|
||||
<g:Anchor ui:field="signUpAnchor" text="{i18n.signUp}" />
|
||||
<g:HTMLPanel ui:field="oAuthPanel" />
|
||||
<ui:with field="local_res" type="com.sap.sse.security.ui.login.LoginViewResources" />
|
||||
<g:HTMLPanel styleName="{local_res.css.login}">
|
||||
<div class="{local_res.css.centered}">
|
||||
<div class="{local_res.css.form}">
|
||||
<div><ui:text from='{i18n.username}'/></div>
|
||||
<div><g:TextBox ui:field="userNameTextBox" /></div>
|
||||
<div><ui:text from='{i18n.password}'/></div>
|
||||
<div><g:PasswordTextBox ui:field="passwordTextBox" /></div>
|
||||
<g:Button ui:field="loginButton" text="{i18n.signIn}" />
|
||||
<g:Button ui:field="passwordResetButton" text="{i18n.resetPassword}" />
|
||||
<g:Anchor ui:field="signUpAnchor" text="{i18n.signUp}" />
|
||||
<g:HTMLPanel ui:field="oAuthPanel" />
|
||||
</div>
|
||||
</div>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
||||
+9
-1
@@ -1,4 +1,12 @@
|
||||
.centerForm {
|
||||
.centered {
|
||||
margin: 0 auto;
|
||||
width:60%;
|
||||
}
|
||||
|
||||
.login {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form {
|
||||
border: 1px solid black;
|
||||
}
|
||||
+3
-1
@@ -11,6 +11,8 @@ public interface LoginViewResources extends ClientBundle {
|
||||
LocalCss css();
|
||||
|
||||
public interface LocalCss extends CssResource {
|
||||
String centerForm();
|
||||
String login();
|
||||
String centered();
|
||||
String form();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -21,7 +21,7 @@ import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.client.UserStatusEventHandler;
|
||||
import com.sap.sse.security.ui.client.component.AbstractUserDialog.UserData;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.client.shared.oauthlogin.OAuthLogin;
|
||||
import com.sap.sse.security.ui.shared.SuccessInfo;
|
||||
import com.sap.sse.security.ui.shared.UserDTO;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
@@ -38,7 +38,7 @@ public class LoginPanel extends HorizontalPanel implements UserStatusEventHandle
|
||||
private final Anchor signUpLink;
|
||||
private final Label welcomeMessage;
|
||||
|
||||
private final OAuthLoginPanel oAuthPanel;
|
||||
private final OAuthLogin oAuthPanel;
|
||||
|
||||
public LoginPanel(final Css css, final UserService userService) {
|
||||
this.userManagementService = userService.getUserManagementService();
|
||||
@@ -118,7 +118,7 @@ public class LoginPanel extends HorizontalPanel implements UserStatusEventHandle
|
||||
add(signInLink);
|
||||
add(signUpLink);
|
||||
add(signOutLink);
|
||||
oAuthPanel = new OAuthLoginPanel(userManagementService, css);
|
||||
oAuthPanel = new OAuthLogin(userManagementService);
|
||||
add(oAuthPanel);
|
||||
userService.addUserStatusEventHandler(this);
|
||||
updateStatus();
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.component.AbstractUserDialog;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.client.shared.oauthlogin.OAuthLogin;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public class SignInDialog extends AbstractUserDialog {
|
||||
@@ -23,7 +23,7 @@ public class SignInDialog extends AbstractUserDialog {
|
||||
result.setWidget(0, 1, getNameBox());
|
||||
result.setWidget(1, 0, new Label(getStringMessages().password()));
|
||||
result.setWidget(1, 1, getPwBox());
|
||||
result.setWidget(2, 0, new OAuthLoginPanel(getUserManagementService(), css));
|
||||
result.setWidget(2, 0, new OAuthLogin(getUserManagementService()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -14,11 +14,10 @@ import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sse.gwt.client.EntryPointHelper;
|
||||
import com.sap.sse.security.ui.client.RemoteServiceMappingConstants;
|
||||
import com.sap.sse.security.ui.client.Resources;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.client.UserChangeEventHandler;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.oauth.client.component.OAuthLoginPanel;
|
||||
import com.sap.sse.security.ui.client.shared.oauthlogin.OAuthLogin;
|
||||
import com.sap.sse.security.ui.oauth.client.util.ClientUtils;
|
||||
import com.sap.sse.security.ui.shared.UserDTO;
|
||||
import com.sap.sse.security.ui.shared.UserManagementService;
|
||||
@@ -28,9 +27,8 @@ public class OAuthLoginEntryPoint implements EntryPoint, UserChangeEventHandler
|
||||
private final UserManagementServiceAsync userManagementService = GWT.create(UserManagementService.class);
|
||||
private final StringMessages stringMessages = GWT.create(StringMessages.class);
|
||||
private final UserService userService = new UserService(userManagementService);
|
||||
private final Resources resources = GWT.create(Resources.class);
|
||||
|
||||
private OAuthLoginPanel loginScreen = new OAuthLoginPanel(userManagementService, resources.css());
|
||||
private OAuthLogin loginScreen = new OAuthLogin(userManagementService);
|
||||
private FlowPanel content = new FlowPanel();
|
||||
|
||||
public void onModuleLoad() {
|
||||
|
||||
-231
@@ -1,231 +0,0 @@
|
||||
package com.sap.sse.security.ui.oauth.client.component;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.sap.sse.security.ui.client.StringMessages;
|
||||
import com.sap.sse.security.ui.loginpanel.Css;
|
||||
import com.sap.sse.security.ui.oauth.client.CredentialDTO;
|
||||
import com.sap.sse.security.ui.oauth.client.resources.ImageResources;
|
||||
import com.sap.sse.security.ui.oauth.client.util.ClientUtils;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public class OAuthLoginPanel extends HorizontalPanel {
|
||||
private static final StringMessages stringMessages = GWT.create(StringMessages.class);
|
||||
private static final String SAP_SAILING_OAUTH_WINDOW = "sap_sailing_oauth_verification_window";
|
||||
|
||||
private Image facebookImage;
|
||||
private Image googleImage;
|
||||
private Image twitterImage;
|
||||
private Image linkedinImage;
|
||||
private Image yahooImage;
|
||||
private Image vimeoImage;
|
||||
private Image githubImage;
|
||||
private Image instagramImage;
|
||||
private Image flickrImage;
|
||||
private Image liveImage;
|
||||
private Image tumblrImage;
|
||||
private Image foursquareImage;
|
||||
|
||||
public static ImageResources images = ImageResources.INSTANCE;
|
||||
|
||||
private UserManagementServiceAsync userManagementService;
|
||||
|
||||
public OAuthLoginPanel(UserManagementServiceAsync userManagementService, Css css) {
|
||||
this.userManagementService = userManagementService;
|
||||
Label signInWithLabel = new Label(stringMessages.signInWith());
|
||||
signInWithLabel.setWordWrap(false);
|
||||
add(signInWithLabel);
|
||||
|
||||
facebookImage = new Image(images.facebookIconImageData().getSafeUri());
|
||||
addProviderImage(facebookImage, "Facebook", css);
|
||||
|
||||
googleImage = new Image(images.googleIconImageData().getSafeUri());
|
||||
addProviderImage(googleImage, "Google", css);
|
||||
|
||||
twitterImage = new Image(images.twitterIconImageData().getSafeUri());
|
||||
addProviderImage(twitterImage, "Twitter", css);
|
||||
|
||||
yahooImage = new Image(images.yahooIconImageData().getSafeUri());
|
||||
addProviderImage(yahooImage, "Yahoo", css);
|
||||
|
||||
linkedinImage = new Image(images.linkedinIconImageData().getSafeUri());
|
||||
addProviderImage(linkedinImage, "LinkedIn", css);
|
||||
|
||||
instagramImage = new Image(images.instagramIconImageData().getSafeUri());
|
||||
addProviderImage(instagramImage, "Instagram", css);
|
||||
|
||||
vimeoImage = new Image(images.vimeoIconImageData().getSafeUri());
|
||||
addProviderImage(vimeoImage, "Vimeo", css);
|
||||
|
||||
githubImage = new Image(images.githubIconImageData().getSafeUri());
|
||||
addProviderImage(githubImage, "Github", css);
|
||||
|
||||
flickrImage = new Image(images.flickrIconImageData().getSafeUri());
|
||||
addProviderImage(flickrImage, "Flickr", css);
|
||||
|
||||
liveImage = new Image(images.liveIconImageData().getSafeUri());
|
||||
addProviderImage(liveImage, "Live", css);
|
||||
|
||||
tumblrImage = new Image(images.tumblrIconImageData().getSafeUri());
|
||||
addProviderImage(tumblrImage, "Tumblr", css);
|
||||
|
||||
foursquareImage = new Image(images.foursquareIconImageData().getSafeUri());
|
||||
addProviderImage(foursquareImage, "Foursquare", css);
|
||||
|
||||
setupLoginScreenHandlers();
|
||||
}
|
||||
|
||||
private void addProviderImage(Image image, String title, Css css) {
|
||||
image.setHeight("1.5em");
|
||||
image.setTitle(title);
|
||||
image.getElement().addClassName(css.providerIcon());
|
||||
add(image);
|
||||
}
|
||||
|
||||
private void getAuthorizationUrl(final int authProvider) {
|
||||
// String authProviderName = ClientUtils.getAuthProviderName(authProvider);
|
||||
final String callbackUrl = ClientUtils.getCallbackUrl();
|
||||
GWT.log("Getting authorization url");
|
||||
final CredentialDTO credential = new CredentialDTO();
|
||||
credential.setRedirectUrl(callbackUrl);
|
||||
credential.setAuthProvider(authProvider);
|
||||
userManagementService.getAuthorizationUrl(credential, new AsyncCallback<String>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
ClientUtils.handleException(caught);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
String authorizationUrl = result;
|
||||
GWT.log("Authorization url: " + authorizationUrl);
|
||||
|
||||
// clear all cookes first
|
||||
ClientUtils.clearCookies();
|
||||
|
||||
// save the auth provider to cookie
|
||||
ClientUtils.saveAuthProvider(authProvider);
|
||||
|
||||
// save the redirect url to a cookie as well
|
||||
// we need to redirect there after logout
|
||||
ClientUtils.saveRediretUrl(callbackUrl);
|
||||
|
||||
// Window.alert("Redirecting to: " + authorizationUrl);
|
||||
Window.open(authorizationUrl, SAP_SAILING_OAUTH_WINDOW, "status=no,toolbar=no,location=no,menubar=no,width=640px,height=480px");
|
||||
// popupFrame.setUrl(authorizationUrl);
|
||||
// popupPanel.show();
|
||||
// openInNewTab(authorizationUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static native String openInNewTab(String url)/*-{
|
||||
return $wnd.open(url,
|
||||
'target=_blank')
|
||||
}-*/;
|
||||
|
||||
private void setupLoginScreenHandlers() {
|
||||
facebookImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Facebook");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
googleImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Google");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
twitterImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Twitter");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
yahooImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Yahoo!");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
linkedinImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Linkedin");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
instagramImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Instagram");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
vimeoImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Vimeo");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
githubImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("github");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
flickrImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("flickr");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
liveImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("Windows Live");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
tumblrImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("tumblr.");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
foursquareImage.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final int authProvider = ClientUtils.getAuthProvider("foursquare");
|
||||
getAuthorizationUrl(authProvider);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.sap.sse.security.ui.oauth.client.resources;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.DataResource;
|
||||
|
||||
public interface ImageResources extends ClientBundle {
|
||||
|
||||
public static final ImageResources INSTANCE = GWT.create(ImageResources.class);
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/facebook.png")
|
||||
public DataResource facebookIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/flickr.png")
|
||||
public DataResource flickrIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/github.png")
|
||||
public DataResource githubIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/google.png")
|
||||
public DataResource googleIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/linkedin.png")
|
||||
public DataResource linkedinIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/twitter.png")
|
||||
public DataResource twitterIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/vimeo.png")
|
||||
public DataResource vimeoIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/wordpress.png")
|
||||
public DataResource wordpressIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/yahoo.png")
|
||||
public DataResource yahooIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/instagram.png")
|
||||
public DataResource instagramIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/imgur.png")
|
||||
public DataResource imgurIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/live32.png")
|
||||
public DataResource liveIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/tumblr.png")
|
||||
public DataResource tumblrIconImageData();
|
||||
|
||||
@Source("com/sap/sse/security/ui/oauth/images/foursquare.png")
|
||||
public DataResource foursquareIconImageData();
|
||||
}
|
||||
Reference in new issue
Block a user