Skip to content

Commit

Permalink
Merge pull request #6 from merle-/v2.0
Browse files Browse the repository at this point in the history
update to play-silhouette 2.0
  • Loading branch information
datalek committed May 7, 2015
2 parents 033d1e5 + 173a95a commit e626715
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 95 deletions.
75 changes: 64 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,68 @@
logs
project/project
project/target
target
tmp
# Created by https://www.gitignore.io

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


### Scala ###
*.class
*.log

# sbt specific
.cache
.history
dist
/.idea
/*.iml
/out
/.idea_modules
.lib/
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/

# Scala-IDE specific
.scala_dependencies
.worksheet


### SBT ###
# Simple Build Tool
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control

target/
lib_managed/
src_managed/
project/boot/
.history
.cache


### PlayFramework ###
# Ignore Play! working directory #
bin/
/db
.eclipse
/lib/
/logs/
/modules
/project/project
/project/target
/target
tmp/
test-result
server.pid
*.iml
*.eml
/dist/
.cache


/.classpath
/.project
/RUNNING_PID
/.settings


42 changes: 20 additions & 22 deletions app/controllers/security/rest/RestCredentialsAuthController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import services.UserService
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.concurrent.Execution.Implicits._

import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.exceptions.AuthenticationException
import com.mohiva.play.silhouette.api.exceptions.ConfigurationException
import com.mohiva.play.silhouette.api.services.AuthInfoService
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.util.Credentials

import modules.cake.HeaderEnvironmentModule

import scala.concurrent.{ Future }
Expand Down Expand Up @@ -43,28 +45,24 @@ class RestCredentialsAuthController extends Silhouette[User, JWTAuthenticator]
*
* @return The result to display.
*/
def authenticate = Action.async(parse.json) { implicit request =>
request.body.validate[Credentials].map { credentials =>
(env.providers.get(CredentialsProvider.ID) match {
case Some(p: CredentialsProvider) => p.authenticate(credentials)
case _ => Future.failed(new AuthenticationException(s"Cannot find credentials provider"))
}).flatMap { loginInfo =>
userService.retrieve(loginInfo).flatMap {
case Some(user) => env.authenticatorService.create(user.loginInfo).flatMap { authenticator =>
env.eventBus.publish(LoginEvent(user, request, request2lang))
env.authenticatorService.init(authenticator).flatMap { token =>
env.authenticatorService.embed(token, Future.successful {
Ok(Json.toJson(Token(token = token, expiresOn = authenticator.expirationDate)))
})
}
def authenticate = Action.async(parse.json[Credentials]) { implicit request =>
(env.providers.get(CredentialsProvider.ID) match {
case Some(p: CredentialsProvider) => p.authenticate(request.body)
case _ => Future.failed(new ConfigurationException(s"Cannot find credentials provider"))
}).flatMap { loginInfo =>
userService.retrieve(loginInfo).flatMap {
case Some(user) => env.authenticatorService.create(user.loginInfo).flatMap { authenticator =>
env.eventBus.publish(LoginEvent(user, request, request2lang))
env.authenticatorService.init(authenticator).flatMap { token =>
env.authenticatorService.embed(token, Future.successful {
Ok(Json.toJson(Token(token = token, expiresOn = authenticator.expirationDate)))
})
}
case None =>
Future.failed(new AuthenticationException("Couldn't find user"))
}
}.recoverWith(exceptionHandler)
}.recoverTotal {
case error => Future.successful(BadRequest(Json.obj("message" -> JsError.toFlatJson(error))))
}
case None =>
Future.failed(new IdentityNotFoundException("Couldn't find user"))
}
}.recoverWith(exceptionHandler)
}

}
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/security/rest/RestSocialAuthController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import play.api.libs.json._
import play.api.libs.concurrent.Execution.Implicits._
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.services._
import com.mohiva.play.silhouette.api.exceptions.AuthenticationException
import com.mohiva.play.silhouette.api.exceptions.ConfigurationException
import com.mohiva.play.silhouette.api.services.AuthInfoService
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers._
Expand Down Expand Up @@ -48,7 +48,7 @@ class RestSocialAuthController extends Silhouette[User, JWTAuthenticator] with H
result
}
}
case _ => Future.failed(new AuthenticationException(s"Cannot authenticate with unexpected social provider $provider"))
case _ => Future.failed(new ConfigurationException(s"Cannot authenticate with unexpected social provider $provider"))
}).recoverWith(exceptionHandler)
}

Expand Down Expand Up @@ -96,7 +96,7 @@ class RestSocialAuthController extends Silhouette[User, JWTAuthenticator] with H
case Some(p: OAuth2Provider with CommonSocialProfileBuilder) => //for OAuth2 provider type
val authInfo = OAuth2Info(accessToken = socialAuth.token, expiresIn = socialAuth.expiresIn)
p.retrieveProfile(authInfo).map(profile => (profile, authInfo))
case _ => Future.successful(new AuthenticationException(s"Cannot retrive information with unexpected social provider $provider"))
case _ => Future.successful(new ConfigurationException(s"Cannot retrive information with unexpected social provider $provider"))
}
}

Expand Down
2 changes: 0 additions & 2 deletions app/modules/cake/AuthenticatorServiceModule.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package modules.cake

package modules.cake

import play.api.Play
import play.api.Play.current
/** mohiva module import */
Expand Down
1 change: 0 additions & 1 deletion app/modules/cake/EnvironmentModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.mohiva.play.silhouette.impl.util.SecureRandomIDGenerator
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.api.EventBus
import com.mohiva.play.silhouette.api.util.PlayHTTPLayer
import modules.cake.{ HeaderAuthenticatorServiceModule/*, CookieAuthenticatorServiceModule */}
import models.users.User
import models.daos._

Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := """silhouette-rest-seed"""

version := "2.0-RC1"
version := "2.0"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

Expand All @@ -9,7 +9,8 @@ scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
cache,
ws,
"com.mohiva" %% "play-silhouette" % "2.0-RC1",
"com.mohiva" %% "play-silhouette" % "2.0",
"com.mohiva" %% "play-silhouette-testkit" % "2.0" % "test",
"com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.0"
)

30 changes: 0 additions & 30 deletions test/ApplicationSpec.scala

This file was deleted.

24 changes: 0 additions & 24 deletions test/IntegrationSpec.scala

This file was deleted.

0 comments on commit e626715

Please sign in to comment.