本文整理汇总了Scala中com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator类的典型用法代码示例。如果您正苦于以下问题:Scala CookieAuthenticator类的具体用法?Scala CookieAuthenticator怎么用?Scala CookieAuthenticator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CookieAuthenticator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AuthenticatorQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import jdub.async.{ Statement, Row, FlatSingleRowQuery }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
object AuthenticatorQueries extends BaseQueries[CookieAuthenticator] {
override protected val tableName = "session_info"
override protected val columns = Seq("id", "provider", "key", "last_used", "expiration", "fingerprint", "created")
override protected val searchColumns = Seq("id::text", "key")
val insert = Insert
val getById = GetById
val removeById = RemoveById
case class FindSessionInfoByLoginInfo(l: LoginInfo) extends FlatSingleRowQuery[CookieAuthenticator] {
override val sql = getSql(Some("provider = ? and key = ?"))
override val values = Seq(l.providerID, l.providerKey)
override def flatMap(row: Row) = Some(fromRow(row))
}
case class UpdateAuthenticator(ca: CookieAuthenticator) extends Statement {
override val sql = updateSql(Seq("provider", "key", "last_used", "expiration", "fingerprint"))
override val values = Seq(
ca.loginInfo.providerID,
ca.loginInfo.providerKey,
ca.lastUsedDateTime.toLocalDateTime,
ca.expirationDateTime.toLocalDateTime,
ca.fingerprint,
ca.id
)
}
override protected def fromRow(row: Row) = {
val id = row.as[String]("id")
val provider = row.as[String]("provider")
val key = row.as[String]("key")
val lastUsed = row.as[LocalDateTime]("last_used").toDateTime
val expiration = row.as[LocalDateTime]("expiration").toDateTime
val idleTimeout = None
val cookieMaxAge = None
val fingerprint = row.asOpt[String]("fingerprint")
CookieAuthenticator(id, LoginInfo(provider, key), lastUsed, expiration, idleTimeout, cookieMaxAge, fingerprint)
}
override protected def toDataSeq(ca: CookieAuthenticator) = Seq(
ca.id,
ca.loginInfo.providerID,
ca.loginInfo.providerKey,
ca.lastUsedDateTime.toLocalDateTime,
ca.expirationDateTime.toLocalDateTime,
ca.fingerprint,
new LocalDateTime()
)
}
示例2: BaseController
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import org.joda.time.LocalDateTime
import play.api.i18n.I18nSupport
import services.user.AuthenticationEnvironment
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import models.user.{ Role, User }
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{ AnyContent, Result }
import scala.concurrent.Future
abstract class BaseController() extends Silhouette[User, CookieAuthenticator] with I18nSupport {
def env: AuthenticationEnvironment
def withAdminSession(block: (SecuredRequest[AnyContent]) => Future[Result]) = SecuredAction.async { implicit request =>
if (request.identity.roles.contains(Role.Admin)) {
block(request)
} else {
Future.successful(NotFound("404 Not Found"))
}
}
def withSession(block: (SecuredRequest[AnyContent]) => Future[Result]) = UserAwareAction.async { implicit request =>
val response = request.identity match {
case Some(user) =>
val secured = SecuredRequest(user, request.authenticator.getOrElse(throw new IllegalStateException()), request)
block(secured).map { r =>
r
}
case None =>
val user = User(
id = UUID.randomUUID(),
username = None,
profiles = Nil,
created = new LocalDateTime()
)
for {
user <- env.userService.save(user)
authenticator <- env.authenticatorService.create(LoginInfo("anonymous", user.id.toString))
value <- env.authenticatorService.init(authenticator)
result <- block(SecuredRequest(user, authenticator, request))
authedResponse <- env.authenticatorService.embed(value, result)
} yield {
env.eventBus.publish(SignUpEvent(user, request, request2Messages))
env.eventBus.publish(LoginEvent(user, request, request2Messages))
authedResponse
}
}
response
}
}
示例3: CoinController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import forms.CoinAddForm
import models.User
import models.coin.{Person, WorkEntry}
import models.common.Pagination
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class CoinController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator]
) extends Silhouette[User, CookieAuthenticator] {
val itemsPerPage = 9
def remove(id: Long): Action[AnyContent] = SecuredAction.async { implicit request =>
WorkEntry.remove(id)
Future.successful(Redirect(routes.CoinController.landing()))
}
}
示例4: JSONCtrl
//设置package包名称以及导入依赖的类
package controllers.io
import javax.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import controllers.{ResultFormat, ViewContext}
import models.{PCMAPIUtils, User}
import org.opencompare.api.java.impl.io.KMFJSONExporter
import org.opencompare.formalizer.extractor.CellContentInterpreter
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{AnyContent, Request, Result}
class JSONCtrl @Inject() (
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator],
val pcmAPIUtils : PCMAPIUtils) extends IOCtrl("json") {
val jsonExporter = new KMFJSONExporter()
val formalizer = new CellContentInterpreter
val outputParametersForm = Form(
mapping(
"file" -> text
)(JSONExportParameters.apply)(JSONExportParameters.unapply)
)
override def importPCMs(format: ResultFormat)(implicit request: Request[AnyContent], viewContext: ViewContext): Result = {
NotFound("JSON import is not implemented yet")
}
override def exportPCM(implicit request: Request[AnyContent]): Result = {
val parameters = outputParametersForm.bindFromRequest.get
val pcmJSON = Json.parse(parameters.pcm)
val container = pcmAPIUtils.parsePCMContainers(pcmJSON).head
formalizer.interpretCells(container.getPcm)
val json = jsonExporter.export(container)
Ok(json)
}
case class JSONExportParameters(pcm : String)
}
示例5: OAuth2Controller
//设置package包名称以及导入依赖的类
package controllers
import play.api._
import play.api.mvc._
import play.api.i18n.{Messages, MessagesApi}
//import play.api.Play.current
//import play.api.i18n.Messages.Implicits._
import play.api.libs.json.Json
//import scala.concurrent.ExecutionContext
import play.api.libs.concurrent.Execution.Implicits._
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import daos.{OauthClientDao, OauthCodeDao}
import models.{OauthCode, User}
import scalaoauth2.provider.OAuth2Provider
import oauth2server._
import scala.concurrent.Future
class OAuth2Controller @Inject() (
oauthCodeDao: OauthCodeDao,
oauthClientDao: OauthClientDao,
oauthDataHandler: OAuthDataHandler,
val messagesApi: MessagesApi,
val env:Environment[User,CookieAuthenticator]
) extends Silhouette[User,CookieAuthenticator] with OAuth2Provider {
override val tokenEndpoint = new DropsTokenEndpoint()
def accessToken = UserAwareAction.async { implicit request =>
issueAccessToken(oauthDataHandler)
}
def getCode(clientId : String) = SecuredAction.async { implicit request =>
oauthClientDao.find(clientId, None, "authorization_code").flatMap(_ match {
case Some(client) => oauthCodeDao.save(OauthCode(request.identity, client)).map(
code => code.client.redirectUri.map( (uri) => Redirect( uri + code.code)).getOrElse(
BadRequest(Messages("oauth2server.clientHasNoRedirectURI"))
)
)
case _ => Future.successful(BadRequest(Messages("oauth2server.clientId.notFound")))
})
}
}
示例6: WithRole
//设置package包名称以及导入依赖的类
package utils
import com.mohiva.play.silhouette.api.Authorization
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import models.{Role, User}
import play.api.i18n._
import play.api.mvc.{Request, RequestHeader}
import scala.concurrent.Future
case class WithRole(role: Role) extends Authorization[User,CookieAuthenticator] {
def isAuthorized[B](user: User, authenticator: CookieAuthenticator)(implicit request : Request[B], messages: Messages) =
user.roles match {
case list: Set[Role] => Future.successful(list.contains(role))
case _ => Future.successful(false)
}
}
case class WithAlternativeRoles(role: Role*) extends Authorization[User, CookieAuthenticator] {
override def isAuthorized[B](identity: User, authenticator: CookieAuthenticator)(implicit request: Request[B], messages: Messages): Future[Boolean] =
Future.successful(role.foldLeft[Boolean](false)((contains, r) => identity.roles.contains(r) || contains))
}
示例7: messagesApi
//设置package包名称以及导入依赖的类
package com.github.jacobono.modules
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.Clock
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import com.mohiva.play.silhouette.impl.providers.{ CredentialsProvider, SocialProviderRegistry }
import com.softwaremill.macwire._
import play.api.Configuration
import play.api.i18n.MessagesApi
import com.github.jacobono.controllers._
import com.github.jacobono.models.User
import com.github.jacobono.models.services.UserService
import com.github.jacobono.utils.CSRFHelper
trait ControllerModule {
def messagesApi: MessagesApi
def silhouetteEnvironment: Environment[User, CookieAuthenticator]
def socialProviderRegistry: SocialProviderRegistry
def csrfHelper: CSRFHelper
def userService: UserService
def authInfoRepository: AuthInfoRepository
def credentialsProvider: CredentialsProvider
def configuration: Configuration
def clock: Clock
def avatarService: AvatarService
def passwordHasher: PasswordHasher
lazy val applicationController: Application = wire[Application]
lazy val credentialsAuthController: CredentialsAuthController = wire[CredentialsAuthController]
lazy val signUpController: SignUpController = wire[SignUpController]
lazy val socialAuthController: SocialAuthController = wire[SocialAuthController]
}
示例8: CookieCredentialsTestController
//设置package包名称以及导入依赖的类
package controllers.authentication
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{ Environment, LogoutEvent, Silhouette }
import com.mohiva.play.silhouette.impl.authenticators.{JWTAuthenticator, CookieAuthenticator}
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import models.tenant.AuthCrewUser
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class CookieCredentialsTestController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[AuthCrewUser, CookieAuthenticator],
socialProviderRegistry: SocialProviderRegistry
)
extends Silhouette[AuthCrewUser, CookieAuthenticator]
{
def index: Action[AnyContent] = SecuredAction.async { implicit request =>
Future.successful(Ok(Json.obj("message" -> Messages("authentication.successful"))))
}
}