Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2981 Support for authentication and registration via OAuth …
Browse files Browse the repository at this point in the history
…(Facebook, Twitter, Google+)
  • Loading branch information
mposolda committed May 7, 2013
2 parents d582144 + 9aa0a39 commit 5ee6bf6
Show file tree
Hide file tree
Showing 165 changed files with 9,340 additions and 796 deletions.
10 changes: 10 additions & 0 deletions component/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.web.controller</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.web.oauth-common</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.web.resources</artifactId>
Expand Down Expand Up @@ -99,6 +103,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.web.oauth-common</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
12 changes: 11 additions & 1 deletion component/api/src/main/java/org/gatein/api/PortalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.gatein.api.internal.StringJoiner;
import org.gatein.api.navigation.Navigation;
import org.gatein.api.navigation.NavigationImpl;
import org.gatein.api.oauth.OAuthProvider;
import org.gatein.api.oauth.OAuthProviderAccessor;
import org.gatein.api.page.Page;
import org.gatein.api.page.PageId;
import org.gatein.api.page.PageImpl;
Expand Down Expand Up @@ -97,10 +99,12 @@ public class PortalImpl implements Portal {
private final Authenticator authenticator;
private final IdentityRegistry identityRegistry;
private final UserPortalConfigService userPortalConfigService;
private final OAuthProviderAccessor oauthProviderAccessor;

public PortalImpl(DataStorage dataStorage, PageService pageService, NavigationService navigationService,
DescriptionService descriptionService, ResourceBundleManager bundleManager, Authenticator authenticator,
IdentityRegistry identityRegistry, UserACL acl, UserPortalConfigService userPortalConfigService) {
IdentityRegistry identityRegistry, UserACL acl, UserPortalConfigService userPortalConfigService,
OAuthProviderAccessor oauthProviderAccessor) {
this.dataStorage = dataStorage;
this.pageService = pageService;
this.navigationService = navigationService;
Expand All @@ -110,6 +114,7 @@ public PortalImpl(DataStorage dataStorage, PageService pageService, NavigationSe
this.identityRegistry = identityRegistry;
this.acl = acl;
this.userPortalConfigService = userPortalConfigService;
this.oauthProviderAccessor = oauthProviderAccessor;
}

@Override
Expand Down Expand Up @@ -388,6 +393,11 @@ public boolean hasPermission(User user, Permission permission) {
}
}

@Override
public OAuthProvider getOAuthProvider(String oauthProviderKey) {
return oauthProviderAccessor.getOAuthProvider(oauthProviderKey);
}

private static <T> void filter(List<T> list, Filter<T> filter) {
if (filter == null)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* JBoss, a division of Red Hat
* Copyright 2013, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.api.oauth;

import org.exoplatform.commons.utils.Safe;
import org.gatein.api.internal.Parameters;
import org.gatein.security.oauth.spi.AccessTokenContext;

/**
* Implementation of {@link AccessToken}. It's simply wrapper around {@link AccessTokenContext} object
*
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class AccessTokenImpl implements AccessToken {

private static final long serialVersionUID = -7034897192745766943L;

private final AccessTokenContext internalAccessTokenContext;

public AccessTokenImpl(AccessTokenContext internalAccessTokenContext) {
Parameters.requireNonNull(internalAccessTokenContext, "internalAccessTokenContext");
this.internalAccessTokenContext = internalAccessTokenContext;
}

public AccessTokenContext getAccessTokenContext() {
return internalAccessTokenContext;
}

@Override
public String getAvailableScopes() {
return internalAccessTokenContext.getScopesAsString();
}

@Override
public boolean isScopeAvailable(String scope) {
return internalAccessTokenContext.isScopeAvailable(scope);
}

@Override
public String getAccessToken() {
return internalAccessTokenContext.getAccessToken();
}

@Override
public int hashCode() {
return internalAccessTokenContext.hashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}

if (!(obj.getClass().equals(AccessTokenImpl.class))) {
return false;
}

AccessTokenImpl that = (AccessTokenImpl)obj;
return Safe.equals(this.internalAccessTokenContext, that.getAccessTokenContext());
}

@Override
public String toString() {
return new StringBuilder("AccessTokenImpl [ internalAccessTokenContext=")
.append(internalAccessTokenContext)
.append(" ]").toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* JBoss, a division of Red Hat
* Copyright 2013, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.api.oauth;

import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.security.oauth.spi.AccessTokenContext;
import org.gatein.security.oauth.spi.OAuthProviderType;
import org.gatein.security.oauth.spi.SocialNetworkService;
import org.gatein.security.oauth.spi.OAuthProviderTypeRegistry;

/**
* Basic implementation of OAuth provider accessor
*
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class BasicOAuthProviderAccessorImpl implements OAuthProviderAccessor {

private final OAuthProviderTypeRegistry oauthProviderTypeRegistry;
private final SocialNetworkService socialNetworkService;

protected final Logger log = LoggerFactory.getLogger(getClass());

public BasicOAuthProviderAccessorImpl(OAuthProviderTypeRegistry oauthProviderTypeRegistry, SocialNetworkService socialNetworkService) {
this.oauthProviderTypeRegistry = oauthProviderTypeRegistry;
this.socialNetworkService = socialNetworkService;
}

@Override
public OAuthProvider getOAuthProvider(String oauthProviderKey) {
OAuthProviderType<?> internalOAuthProvider = getInternalOAuthProvider(oauthProviderKey);
if (internalOAuthProvider == null) {
return null;
} else {
return new BasicOAuthProviderImpl(internalOAuthProvider, socialNetworkService);
}
}

protected OAuthProviderType<?> getInternalOAuthProvider(String oauthProviderKey) {
OAuthProviderType<?> oauthProviderType = oauthProviderTypeRegistry.getOAuthProvider(oauthProviderKey, AccessTokenContext.class);
if (oauthProviderType == null && log.isTraceEnabled()) {
log.trace("OAuthProvider '" + oauthProviderKey + "' not found");
}
return oauthProviderType;
}

protected SocialNetworkService getSocialNetworkService() {
return socialNetworkService;
}
}

0 comments on commit 5ee6bf6

Please sign in to comment.