This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GTNPORTAL-2981 Support for authentication and registration via OAuth …
…(Facebook, Twitter, Google+)
- Loading branch information
Showing
165 changed files
with
9,340 additions
and
796 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
93 changes: 93 additions & 0 deletions
93
component/api/src/main/java/org/gatein/api/oauth/AccessTokenImpl.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,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(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
component/api/src/main/java/org/gatein/api/oauth/BasicOAuthProviderAccessorImpl.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,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; | ||
} | ||
} |
Oops, something went wrong.