【问题标题】:Play Framework trying to access DB with windows usernamePlay Framework 尝试使用 Windows 用户名访问数据库
【发布时间】:2015-07-24 02:04:49
【问题描述】:

我在 conf 文件夹中有一个如下所示的 db.conf:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://62.210.145.112/babybets"
db.default.username=postgres
db.default.password="my_password"

它包含在 application.conf 中:

include "db.conf"

信息绝对正确,因为我使用这个相同的 jdbc 连接字符串,用户/密码将 Intellij DB 视图连接到数据库。

当我尝试访问任何页面时,我得到一个错误:

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.10-2.3.8.jar:2.3.8]
    at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.10-2.3.8.jar:2.3.8]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "John"
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:293) ~[postgresql-9.1-901-1.jdbc4.jar:na]
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) ~[postgresql-9.1-901-1.jdbc4.jar:na]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901-1.jdbc4.jar:na]
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901-1.jdbc4.jar:na]
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901-1.jdbc4.jar:na]

在上面您可以看到它尝试使用我的 Windows 登录名“John”连接到数据库。

我与代理 Ransack 一起完成了该项目,并尝试了以下(不区分大小写)正则表达式:

[^\\]john[^\\]

它只匹配上面的错误日志。

问题:为什么玩用我的windows登录连接DB?如何预防?

仅供参考,我的 build.sbt 如下所示:

name := "babyBets2"

version := "1.0"

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

scalaVersion := "2.10.5"

libraryDependencies ++= Seq( cache , ws )

libraryDependencies ++= Seq("postgresql" % "postgresql" % "9.1-901-1.jdbc4",
  "com.typesafe.play" %% "play-slick" % "0.8.0",
  "ws.securesocial" %% "securesocial" % "2.1.4" )

unmanagedResourceDirectories in Test <+=  baseDirectory ( _ /"target/web/public/test" )  

【问题讨论】:

    标签: postgresql playframework playframework-2.0 slick-2.0 play-slick


    【解决方案1】:

    好吧,这太疯狂了,Play 版本之间存在差异:

    https://www.playframework.com/documentation/2.4.x/ScalaDatabase https://www.playframework.com/documentation/2.3.x/ScalaDatabase

    db.default.username=postgres
    

    db.default.user=postgres
    

    显然,如果没有提供用户,play 将不会显示任何有用的错误消息,并尝试将您连接到 windows 登录!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-02
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多