Skip to content

Commit

Permalink
- Renamed class name UserId to IdentityId (breaks backwards compatibi…
Browse files Browse the repository at this point in the history
…lity)

- Renamed id field in UserId to userId (breaks backwards compatibility)
- Renamed id field in Identity to identityId (breaks backwards compatibility)
  • Loading branch information
Jorge committed Aug 8, 2013
1 parent 596829e commit b568bc2
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 65 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2.1.1 - 2013-08-08
- Renamed class name UserId to IdentityId (breaks backwards compatibility)
- Renamed id field in UserId to userId (breaks backwards compatibility)
- Renamed id field in Identity to identityId (breaks backwards compatibility)
2.1.0 - 2013-08-08
- Upgraded to Play 2.1.3
- Added a enableRefererAsOriginalUrl property to enable/disable the use of the referer as the originalUrl
Expand Down
3 changes: 2 additions & 1 deletion docs/src/manual/data/versions.yml
@@ -1,2 +1,3 @@
ss2: 2.0.12
ss21: 2.1.0
ss2: 2.0.13
ss1: 0.2.6
4 changes: 2 additions & 2 deletions docs/src/manual/source/guide/authorization.md
Expand Up @@ -21,7 +21,7 @@ This is a sample implementation that only grants acccess to users that logged in
:::scala
case class WithProvider(provider: String) extends Authorization {
def isAuthorized(user: Identity) = {
user.id.providerId == provider
user.identityId.providerId == provider
}
}

Expand All @@ -46,7 +46,7 @@ This is an equivalent implementation to the Scala sample:
:::java
public class WithProvider implements Authorization {
public boolean isAuthorized(Identity user, String params[]) {
return user.id().providerId().equals(params[0]);
return user.identityId().providerId().equals(params[0]);
}
}

Expand Down
25 changes: 25 additions & 0 deletions docs/src/manual/source/guide/changelog.md
Expand Up @@ -5,6 +5,31 @@ file: changelog

*This is the change log for the SecureSocial 2 version. Check the [1.x](https://github.com/jaliss/securesocial/tree/1.x) branch if you're interested in SecureSocial 1.*

**2.1.1 - 2013-08-08**

- Renamed class name UserId to IdentityId (breaks backwards compatibility)
- Renamed id field in UserId to userId (breaks backwards compatibility)
- Renamed id field in Identity to identityId (breaks backwards compatibility)

**2.1.0 - 2013-08-08**

- Upgraded to Play 2.1.3
- Added a enableRefererAsOriginalUrl property to enable/disable the use of the referer as the originalUrl
since this was causing issues for some people (defaults to false). This is a temporary until a final
solution is developed.
- Use referer if originalUrl is not available when the login/signup page is hit (thanks @magro)
- Fixed: Facebook login error when using the publish_stream scope (thanks @fedefrappi)
- Fixed: make minimum default password length to 8 (thanks @wsargent)
- Fixed: ClassCastException on application reload (dev mode) when using Events (thanks @magro)
- Added: Serve the login page using SSL (thanks @magro)
- Fixed: Do not prevent login on missing google profile info (thanks @chazmcgarvey)
- Fixed: NoSuchElementException in FoursquareProvider (thanks @thesmith)
- Moved RequestWithUser outside the SecureSocial controller
- Allow overriding Registration step redirect targets. (thanks @magro)
- Added the email to the flash messages in Registration.handleStartSignUp (thanks @magro)
- Added support for plain text, html and multipart emails in TemplatesPlugin (thanks @magro)
- Made SecureSocial compatible with Play 2.1 [master branch, 2.0.x branch is for Play 2.0 versions now].

**2.0.12 - 2013-02-25**

- clean securesocial values after login from the session
Expand Down
4 changes: 2 additions & 2 deletions docs/src/manual/source/guide/securing.md
Expand Up @@ -64,7 +64,7 @@ The current user (always present for `SecuredAction`) is available in the reques

The `Identity` is defined using a trait (traits are similar to Java interfaces). The following attributes are defined in this trait:

- `id`: a `UserId` object that stores the user `id` within the provider used to authenticate the user (eg: the twitter id) and the `providerId`.
- `identityId`: a `IdentityId` object that stores the user `userId` within the provider used to authenticate the user (eg: the twitter id) and the `providerId`.
- `firstName`, `lastName` and `fullName`: The user's names.
- `email`: The user email address (available if the external service provides it). Eg: Twitter does not expose email addresses.
- `avatarUrl`: The url that points to the user image in the authenticating service.
Expand Down Expand Up @@ -102,4 +102,4 @@ For example:
if ( user.oAuth1Info().isDefined() ) {
// there is a value
OAuth1Info info = user.oAuth1Info().get()
}
}
6 changes: 3 additions & 3 deletions docs/src/manual/source/guide/user-service.md
Expand Up @@ -49,7 +49,7 @@ For Scala you need to extend the `UserServicePlugin`. For example:
* @param id the user id
* @return an optional user
*/
def find(id: UserId):Option[Identity] = {
def find(id: IdentityId):Option[Identity] = {
// implement me
}

Expand Down Expand Up @@ -154,7 +154,7 @@ For Java, you need to extend the `BaseUserService` class.
* @return an Identity instance or null if no user matches the specified id
*/
@Override
public Identity doFind(UserId userId) {
public Identity doFind(IdentityId id) {
// implement me
}

Expand Down Expand Up @@ -225,4 +225,4 @@ For Java, you need to extend the `BaseUserService` class.

# Important

Note that the `Token` class is implemented in Scala and Java. Make sure you import the one that matches the language you are using in your `UserService` implementation.
Note that the `Token` class is implemented in Scala and Java. Make sure you import the one that matches the language you are using in your `UserService` implementation.
2 changes: 1 addition & 1 deletion module-code/app/securesocial/controllers/LoginPage.scala
Expand Up @@ -69,7 +69,7 @@ object LoginPage extends Controller
val to = Play.configuration.getString(onLogoutGoTo).getOrElse(RoutesHelper.login().absoluteURL(IdentityProvider.sslEnabled))
val user = for (
authenticator <- SecureSocial.authenticatorFromRequest ;
user <- UserService.find(authenticator.userId)
user <- UserService.find(authenticator.identityId)
) yield {
Authenticator.delete(authenticator.id)
user
Expand Down
8 changes: 4 additions & 4 deletions module-code/app/securesocial/controllers/Registration.scala
Expand Up @@ -31,7 +31,7 @@ import org.joda.time.DateTime
import play.api.i18n.Messages
import securesocial.core.providers.Token
import scala.Some
import securesocial.core.UserId
import securesocial.core.IdentityId


/**
Expand Down Expand Up @@ -81,7 +81,7 @@ object Registration extends Controller {
val formWithUsername = Form[RegistrationInfo](
mapping(
UserName -> nonEmptyText.verifying( Messages(UserNameAlreadyTaken), userName => {
UserService.find(UserId(userName,providerId)).isEmpty
UserService.find(IdentityId(userName,providerId)).isEmpty
}),
FirstName -> nonEmptyText,
LastName -> nonEmptyText,
Expand Down Expand Up @@ -221,9 +221,9 @@ object Registration extends Controller {
},
info => {
val id = if ( UsernamePasswordProvider.withUserNameSupport ) info.userName.get else t.email
val userId = UserId(id, providerId)
val identityId = IdentityId(id, providerId)
val user = SocialUser(
userId,
identityId,
info.firstName,
info.lastName,
"%s %s".format(info.firstName, info.lastName),
Expand Down
6 changes: 3 additions & 3 deletions module-code/app/securesocial/core/Authenticator.scala
Expand Up @@ -29,12 +29,12 @@ import play.api.mvc.{DiscardingCookie, Cookie}
* An authenticator tracks an authenticated user.
*
* @param id The authenticator id
* @param userId The user id
* @param identityId The user id
* @param creationDate The creation timestamp
* @param lastUsed The last used timestamp
* @param expirationDate The expiration time
*/
case class Authenticator(id: String, userId: UserId, creationDate: DateTime,
case class Authenticator(id: String, identityId: IdentityId, creationDate: DateTime,
lastUsed: DateTime, expirationDate: DateTime)
{

Expand Down Expand Up @@ -211,7 +211,7 @@ object Authenticator {
val id = use[IdGenerator].generate
val now = DateTime.now()
val expirationDate = now.plusMinutes(absoluteTimeout)
val authenticator = Authenticator(id, user.id, now, now, expirationDate)
val authenticator = Authenticator(id, user.identityId, now, now, expirationDate)
val r = use[AuthenticatorStore].save(authenticator)
val result = r.fold( e => Left(e), _ => Right(authenticator) )
result
Expand Down
2 changes: 1 addition & 1 deletion module-code/app/securesocial/core/OAuth1Provider.scala
Expand Up @@ -74,7 +74,7 @@ abstract class OAuth1Provider(application: Application) extends IdentityProvider
Cache.set(cacheKey, "", 1)
Right(
SocialUser(
UserId("", id), "", "", "", None, None, authMethod,
IdentityId("", id), "", "", "", None, None, authMethod,
oAuth1Info = Some(OAuth1Info(token.token, token.secret))
)
)
Expand Down
2 changes: 1 addition & 1 deletion module-code/app/securesocial/core/OAuth2Provider.scala
Expand Up @@ -107,7 +107,7 @@ abstract class OAuth2Provider(application: Application) extends IdentityProvider
val oauth2Info = Some(
OAuth2Info(accessToken.accessToken, accessToken.tokenType, accessToken.expiresIn, accessToken.refreshToken)
)
SocialUser(UserId("", id), "", "", "", None, None, authMethod, oAuth2Info = oauth2Info)
SocialUser(IdentityId("", id), "", "", "", None, None, authMethod, oAuth2Info = oauth2Info)
}
if ( Logger.isDebugEnabled ) {
Logger.debug("[securesocial] user = " + user)
Expand Down
8 changes: 4 additions & 4 deletions module-code/app/securesocial/core/SecureSocial.scala
Expand Up @@ -79,7 +79,7 @@ trait SecureSocial extends Controller {

val result = for (
authenticator <- SecureSocial.authenticatorFromRequest ;
user <- UserService.find(authenticator.userId)
user <- UserService.find(authenticator.identityId)
) yield {
touch(authenticator)
if ( authorize.isEmpty || authorize.get.isAuthorized(user)) {
Expand Down Expand Up @@ -169,7 +169,7 @@ trait SecureSocial extends Controller {
implicit request => {
val user = for (
authenticator <- SecureSocial.authenticatorFromRequest ;
user <- UserService.find(authenticator.userId)
user <- UserService.find(authenticator.identityId)
) yield {
touch(authenticator)
user
Expand Down Expand Up @@ -228,7 +228,7 @@ object SecureSocial {
def currentUser[A](implicit request: RequestHeader):Option[Identity] = {
for (
authenticator <- authenticatorFromRequest ;
user <- UserService.find(authenticator.userId)
user <- UserService.find(authenticator.identityId)
) yield {
user
}
Expand All @@ -241,7 +241,7 @@ object SecureSocial {
* @return an optional service info
*/
def serviceInfoFor(user: Identity): Option[ServiceInfo] = {
Registry.providers.get(user.id.providerId) match {
Registry.providers.get(user.identityId.providerId) match {
case Some(p: OAuth1Provider) if p.authMethod == AuthenticationMethod.OAuth1 => Some(p.serviceInfo)
case _ => None
}
Expand Down
10 changes: 5 additions & 5 deletions module-code/app/securesocial/core/SocialUser.scala
Expand Up @@ -30,7 +30,7 @@ package securesocial.core
*
*/
trait Identity {
def id: UserId
def identityId: IdentityId
def firstName: String
def lastName: String
def fullName: String
Expand All @@ -45,7 +45,7 @@ trait Identity {
/**
* An implementation of Identity. Used by SecureSocial to gather user information when users sign up and/or sign in.
*/
case class SocialUser(id: UserId, firstName: String, lastName: String, fullName: String, email: Option[String],
case class SocialUser(identityId: IdentityId, firstName: String, lastName: String, fullName: String, email: Option[String],
avatarUrl: Option[String], authMethod: AuthenticationMethod,
oAuth1Info: Option[OAuth1Info] = None,
oAuth2Info: Option[OAuth2Info] = None,
Expand All @@ -54,7 +54,7 @@ case class SocialUser(id: UserId, firstName: String, lastName: String, fullName:
object SocialUser {
def apply(i: Identity): SocialUser = {
SocialUser(
i.id, i.firstName, i.lastName, i.fullName,
i.identityId, i.firstName, i.lastName, i.fullName,
i.email, i.avatarUrl, i.authMethod, i.oAuth1Info,
i.oAuth2Info, i.passwordInfo
)
Expand All @@ -64,10 +64,10 @@ object SocialUser {
/**
* The ID of an Identity
*
* @param id the id on the provider the user came from (eg: twitter, facebook)
* @param userId the user id on the provider the user came from (eg: twitter, facebook)
* @param providerId the provider used to sign in
*/
case class UserId(id: String, providerId: String)
case class IdentityId(userId: String, providerId: String)

/**
* The OAuth 1 details
Expand Down
4 changes: 2 additions & 2 deletions module-code/app/securesocial/core/UserService.scala
Expand Up @@ -35,7 +35,7 @@ trait UserService {
* @param id the user id
* @return an optional user
*/
def find(id: UserId):Option[Identity]
def find(id: IdentityId):Option[Identity]

/**
* Finds a Social user by email and provider id.
Expand Down Expand Up @@ -151,7 +151,7 @@ object UserService {
delegate = Some(service)
}

def find(id: UserId):Option[Identity] = {
def find(id: IdentityId):Option[Identity] = {
delegate.map( _.find(id) ).getOrElse {
notInitialized()
None
Expand Down
6 changes: 3 additions & 3 deletions module-code/app/securesocial/core/java/BaseUserService.java
Expand Up @@ -20,7 +20,7 @@
import play.libs.Scala;
import scala.Option;
import securesocial.core.Identity;
import securesocial.core.UserId;
import securesocial.core.IdentityId;

import java.lang.reflect.Field;

Expand Down Expand Up @@ -56,7 +56,7 @@ public BaseUserService(Application application) {
* @return an optional user
*/
@Override
public Option<securesocial.core.Identity> find(securesocial.core.UserId id) {
public Option<securesocial.core.Identity> find(IdentityId id) {
Identity identity = doFind(id);
return Scala.Option(identity);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public void deleteExpiredTokens() {
* Finds the user in the backing store.
* @return an Identity instance or null if no user matches the specified id
*/
public abstract Identity doFind(UserId userId);
public abstract Identity doFind(IdentityId identityId);

/**
* Finds a token
Expand Down
2 changes: 1 addition & 1 deletion module-code/app/securesocial/core/java/SecureSocial.java
Expand Up @@ -138,7 +138,7 @@ private static Identity currentUser(Authenticator authenticator) {
Identity result = null;

if ( authenticator != null ) {
Option<Identity> optionalIdentity = UserService$.MODULE$.find(authenticator.userId());
Option<Identity> optionalIdentity = UserService$.MODULE$.find(authenticator.identityId());
result = Scala.orNull(optionalIdentity);

}
Expand Down
Expand Up @@ -79,7 +79,7 @@ class FacebookProvider(application: Application) extends OAuth2Provider(applicat
val email = ( me \ Email).as[String]

user.copy(
id = UserId(userId, id),
identityId = IdentityId(userId, id),
firstName = firstName,
lastName = lastName,
fullName = name,
Expand Down
Expand Up @@ -18,7 +18,7 @@ package securesocial.core.providers

import securesocial.core._
import play.api.{Logger, Application}
import securesocial.core.UserId
import securesocial.core.IdentityId
import securesocial.core.SocialUser
import play.api.libs.ws.WS
import securesocial.core.AuthenticationException
Expand Down Expand Up @@ -75,7 +75,7 @@ class FoursquareProvider(application: Application) extends OAuth2Provider(applic
val email = (me \ Response \ User \ Contact \ Email).asOpt[String].filter( !_.isEmpty )

user.copy(
id = UserId(userId.get , id),
identityId = IdentityId(userId.get , id),
lastName = lastName,
firstName = firstName,
fullName = firstName + " " + lastName,
Expand Down
Expand Up @@ -19,7 +19,7 @@ package securesocial.core.providers
import securesocial.core._
import play.api.{Logger, Application}
import play.api.libs.ws.WS
import securesocial.core.UserId
import securesocial.core.IdentityId
import securesocial.core.SocialUser
import play.api.libs.ws.Response
import securesocial.core.AuthenticationException
Expand Down Expand Up @@ -73,7 +73,7 @@ class GitHubProvider(application: Application) extends OAuth2Provider(applicatio
val avatarUrl = (me \ AvatarUrl).asOpt[String]
val email = (me \ Email).asOpt[String].filter( !_.isEmpty )
user.copy(
id = UserId(userId.toString, id),
identityId = IdentityId(userId.toString, id),
fullName = displayName,
avatarUrl = avatarUrl,
email = email
Expand Down
Expand Up @@ -62,7 +62,7 @@ class GoogleProvider(application: Application) extends OAuth2Provider(applicatio
val avatarUrl = ( me \ Picture).asOpt[String]
val email = ( me \ Email).asOpt[String]
user.copy(
id = UserId(userId, id),
identityId = IdentityId(userId, id),
firstName = firstName.getOrElse(""),
lastName = lastName.getOrElse(""),
fullName = fullName.getOrElse(""),
Expand Down
Expand Up @@ -19,7 +19,7 @@ package securesocial.core.providers
import securesocial.core._
import play.api.{Logger, Application}
import play.api.libs.ws.WS
import securesocial.core.UserId
import securesocial.core.IdentityId
import securesocial.core.SocialUser
import securesocial.core.AuthenticationException
import scala.Some
Expand Down Expand Up @@ -67,7 +67,7 @@ class InstagramProvider(application: Application) extends OAuth2Provider(applica
val avatarUrl = ( me \ Data \ ProfilePic ).asOpt[String]

user.copy(
id = UserId(userId , id),
identityId = IdentityId(userId , id),
fullName = fullName,
avatarUrl = avatarUrl
)
Expand Down
Expand Up @@ -58,7 +58,7 @@ class LinkedInProvider(application: Application) extends OAuth1Provider(applicat
val avatarUrl = (me \ PictureUrl).asOpt[String]

SocialUser(user).copy(
id = UserId(userId, id),
identityId = IdentityId(userId, id),
firstName = firstName,
lastName = lastName,
fullName= fullName,
Expand Down

0 comments on commit b568bc2

Please sign in to comment.