本文整理汇总了Scala中com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Scala IdentityNotFoundException类的具体用法?Scala IdentityNotFoundException怎么用?Scala IdentityNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IdentityNotFoundException类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: authenticate
//设置package包名称以及导入依赖的类
package controllers.security.rest
import scala.concurrent.Future
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.ConfigurationException
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.util.Credentials
import modules.cake.HeaderEnvironmentModule
import security.models._
import models.users.User
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 IdentityNotFoundException("Couldn't find user"))
}
}.recoverWith(exceptionHandler)
}
}
object RestCredentialsAuthController extends RestCredentialsAuthController
开发者ID:Flibberty-GEA,项目名称:silhouette-rest-seed,代码行数:41,代码来源:RestCredentialsAuthController.scala
示例2: Authentication
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.exceptions.ProviderException
import com.mohiva.play.silhouette.api.util.Credentials
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException
import com.mohiva.play.silhouette.impl.providers._
import forms.SignInForm
import models.User
import models.daos.UserDAO
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Action
import scala.concurrent.Future
class Authentication @Inject()(val messagesApi: MessagesApi,
val env: Environment[User, SessionAuthenticator],
userDAO: UserDAO,
credentialsProvider: CredentialsProvider)
extends Silhouette[User, SessionAuthenticator] {
def authenticate = Action.async { implicit request =>
SignInForm.form.bindFromRequest.fold(
form => Future.successful(BadRequest(views.html.signIn(form))),
data => {
val credentials = Credentials(data.email, data.password)
credentialsProvider.authenticate(credentials).flatMap { loginInfo =>
val result = Redirect(routes.Application.dashboard())
userDAO.retrieve(loginInfo).flatMap {
case Some(user) =>
env.authenticatorService.create(loginInfo).flatMap { authenticator =>
env.eventBus.publish(LoginEvent(user, request, request2Messages))
env.authenticatorService.init(authenticator).flatMap { v =>
env.authenticatorService.embed(v, result)
}
}
case None => Future.failed(new IdentityNotFoundException(Messages("user.not_found")))
}
}.recover {
case _: ProviderException =>
Redirect(routes.Application.signIn()).flashing("error" -> Messages("invalid.credentials"))
}
}
)
}
}
开发者ID:wjglerum,项目名称:bamboesmanager,代码行数:51,代码来源:Authentication.scala
注:本文中的com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论