• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala CookieAuthenticator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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()
  )
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:58,代码来源:AuthenticatorQueries.scala


示例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
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:57,代码来源:BaseController.scala


示例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()))
  }
} 
开发者ID:wirvomgut,项目名称:curo,代码行数:30,代码来源:CoinController.scala


示例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)
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:50,代码来源:JSONCtrl.scala


示例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")))
    })
  }
} 
开发者ID:Viva-con-Agua,项目名称:drops,代码行数:50,代码来源:OAuth2Controller.scala


示例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))
} 
开发者ID:Viva-con-Agua,项目名称:drops,代码行数:24,代码来源:WithRole.scala


示例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]
} 
开发者ID:jacobono,项目名称:silhouette-macwire,代码行数:39,代码来源:ControllerModule.scala


示例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"))))
  }
} 
开发者ID:ShaneRich5,项目名称:hello-jenkins,代码行数:26,代码来源:CookieCredentialsTestController.scala



注:本文中的com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ContentTypes类代码示例发布时间:2022-05-23
下一篇:
Scala Scanner类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap