1st step OAuth Authorization completed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/social-profile@99245 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-08-08 15:11:25 +00:00
parent 349622c790
commit 3d5a1c88e5
12 changed files with 151 additions and 51 deletions

View File

@ -4,15 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<dependent-module archiveName="wsmail-widget-1.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/wsmail-widget/wsmail-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-0.2.5-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="workspace-light-tree-2.13.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-light-tree/workspace-light-tree">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="social-profile"/>
</wb-module>

View File

@ -98,6 +98,12 @@
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>

View File

@ -0,0 +1,13 @@
<!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:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
Hello,
<g:Button styleName="{style.important}" ui:field="button" />
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -4,6 +4,8 @@ import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portlets.user.socialprofile.client.ui.DisplayProfile;
import org.gcube.portlets.user.socialprofile.client.ui.DisplaySummary;
import org.gcube.portlets.user.socialprofile.client.ui.ErrorAlert;
import org.gcube.portlets.user.socialprofile.client.ui.OkAlert;
import org.gcube.portlets.user.socialprofile.shared.UserContext;
import com.google.gwt.core.client.EntryPoint;
@ -17,12 +19,16 @@ import com.google.gwt.user.client.ui.VerticalPanel;
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class SocialProfile implements EntryPoint {
private final SocialServiceAsync socialService = GWT.create(SocialService.class);
private VerticalPanel mainPanel = new VerticalPanel();
private DisplayProfile dispProfile = new DisplayProfile();
public void onModuleLoad() {
if (isUserAuthZFromLinkedIn()) {
checkLinkedInAuthZ();
}
socialService.getUserContext(getUserToShowId(), new AsyncCallback<UserContext>() {
@Override
public void onSuccess(UserContext result) {
@ -43,6 +49,18 @@ public class SocialProfile implements EntryPoint {
RootPanel.get("SocialProfileDiv").add(mainPanel);
}
private void checkLinkedInAuthZ() {
if (Window.Location.getParameter("error") != null) {
mainPanel.add(new ErrorAlert());
} else {
String code = Window.Location.getParameter("code");
String controlSequence = Window.Location.getParameter("state");
GWT.log("key="+code+" state="+controlSequence);
GWT.log("state="+controlSequence);
mainPanel.add(new OkAlert());
}
}
/**
* decode the userid from the location param
* @return the decoded (base64) userid
@ -54,4 +72,13 @@ public class SocialProfile implements EntryPoint {
String encodedUserId = Window.Location.getParameter(encodedOid);
return Encoder.decode(encodedUserId);
}
/**
*
* @return true if either the user
*/
private boolean isUserAuthZFromLinkedIn() {
if (Window.Location.getParameter("error") != null || Window.Location.getParameter("code") != null)
return true;
return false;
}
}

View File

@ -17,6 +17,7 @@ import com.google.gwt.event.dom.client.ClickHandler;
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.Random;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -66,6 +67,8 @@ public class DisplayProfile extends Composite {
@UiField Button messageButton;
@UiField Button editButton;
@UiField Button importButton;
private String currHeadLine;
private String currInstitution;
@ -122,6 +125,22 @@ public class DisplayProfile extends Composite {
}
});
importButton.setVisible(true);
importButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String OAUTH2_SERVICE = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code";
String D4S_APP_ID = "77n7r4c9nwuwk2";
String controlSequence = getRandomString();
String url = OAUTH2_SERVICE + ""
+ "&client_id="+D4S_APP_ID
+ "&state="+controlSequence
+ "&redirect_uri="+Location.getHref();
Location.assign(url);
}
});
} else { //its someone else
String head = (result.getHeadline() == null || result.getHeadline().compareTo("") == 0) ? "" : result.getHeadline();
String isti = (result.getInstitution() == null || result.getInstitution().compareTo("") == 0) ? "" : result.getInstitution();
@ -293,4 +312,13 @@ public class DisplayProfile extends Composite {
}
private String getRandomString() {
StringBuilder sb = new StringBuilder();
for (int i=0;i<20;i++) {
sb.append('a'+Random.nextInt(26));
}
return sb.toString();
}
}

View File

@ -60,7 +60,8 @@
</div>
<div class="user-details">
<g:Button ui:field="messageButton" visible="false">Private Message</g:Button>
<g:Button ui:field="editButton" visible="false">Edit Professional Background</g:Button>
<g:Button ui:field="importButton" visible="false">Import from LinkedIn</g:Button>
<g:Button ui:field="editButton" visible="false">Edit Profile Manually</g:Button>
</div>
</td>
</tr>

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.socialprofile.client.ui;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class ErrorAlert extends Composite {
private static ErrorAlertUiBinder uiBinder = GWT
.create(ErrorAlertUiBinder.class);
interface ErrorAlertUiBinder extends UiBinder<Widget, ErrorAlert> {
}
public ErrorAlert() {
initWidget(uiBinder.createAndBindUi(this));
}
public ErrorAlert(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
}
}

View File

@ -0,0 +1,17 @@
<!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:style>
.alert {
border: 1px solid #EBCCD1;
border-radius: 4px;
margin: 20px;
padding: 15px;
background-color: #F2DEDE;
color: #A94440;
}
</ui:style>
<g:HTMLPanel styleName="{style.alert}">
<span style="font-weight: bold;"> Import Error:</span> it seems you denied our request to import from LinkedIn. If this is not the case please report the issue.
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -0,0 +1,19 @@
package org.gcube.portlets.user.socialprofile.client.ui;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class OkAlert extends Composite {
private static OkAlertUiBinder uiBinder = GWT.create(OkAlertUiBinder.class);
interface OkAlertUiBinder extends UiBinder<Widget, OkAlert> {
}
public OkAlert() {
initWidget(uiBinder.createAndBindUi(this));
}
}

View File

@ -0,0 +1,17 @@
<!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:style>
.alert {
border: 1px solid #D6E9C6;
border-radius: 4px;
margin: 20px;
padding: 15px;
background-color: #DFF0D8;
color: #3C763D;
}
</ui:style>
<g:HTMLPanel styleName="{style.alert}">
Import operation completed successfully.
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -3,7 +3,7 @@
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<!-- To Comment out -->
<set-property name="user.agent" value="gecko1_8" />
<!-- <set-property name="user.agent" value="gecko1_8" /> -->
<!-- Other module inherits -->
<!-- inherits GCUBE Widgets -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />

View File

@ -1,40 +0,0 @@
package org.gcube.portlets.user.socialprofile.client;
import com.google.gwt.junit.client.GWTTestCase;
/**
* GWT JUnit <b>integration</b> tests must extend GWTTestCase.
* Using <code>"GwtTest*"</code> naming pattern exclude them from running with
* surefire during the test phase.
*
* If you run the tests using the Maven command line, you will have to
* navigate with your browser to a specific url given by Maven.
* See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
* for details.
*/
public class GwtTestSocialProfile extends GWTTestCase {
/**
* Must refer to a valid module that sources this class.
*/
public String getModuleName() {
return "org.gcube.portlets.user.socialprofile.SocialProfileJUnit";
}
/**
* Tests the FieldVerifier.
*/
public void testFieldVerifier() {
}
/**
* This test will send a request to the server using the greetServer method in
* GreetingService and verify the response.
*/
public void testGreetingService() {
}
}