【问题标题】:jdbc kerberos oracle authenticationjdbc kerberos oracle 身份验证
【发布时间】:2017-07-13 23:06:21
【问题描述】:

使用这个例子,几乎可以让我的连接正常工作

http://blogs.nologin.es/rickyepoderi/index.php?/archives/105-Oracle-Driver-and-Kerberos.html

但在启用 kerberos 缓存和调试后,它会正确获取我的主体名称并且凭据成功,但出现与票证相关的错误。

ticket 使用 okinit (oracle kinit from oracle 12) 生成

线程“main”java.sql.SQLRecoverableException 中的异常:E/S 错误:不支持进程中的服务。 GSS-API 级别未指定故障(机制级别:一般错误(电子文本中的描述)(60) - ASN.1 意外字段编号) 在 oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743) 在 oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666) 在 oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) 在 oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566) 在 java.sql.DriverManager.getConnection(DriverManager.java:571) 在 java.sql.DriverManager.getConnection(DriverManager.java:187) 在 JdbcThin.main(JdbcThin.java:39) 原因:oracle.net.ns.NetException:不支持正在处理的服务。 GSS-API 级别未指定故障(机制级别:一般错误(电子文本中的描述)(60) - ASN.1 意外字段编号) 在 oracle.net.ano.AuthenticationService.run(未知来源) 在 java.security.AccessController.doPrivileged(本机方法) 在 javax.security.auth.Subject.doAs(Subject.java:415) 在 oracle.net.ano.AuthenticationService.e(未知来源) 在 oracle.net.ano.Ano.negotiation(未知来源) 在 oracle.net.ns.NSProtocol.connect(NSProtocol.java:293) 在 oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452) 在 oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496) ... 6 更多 原因:GSSException:在 GSS-API 级别未指定故障(机制级别:一般错误(电子文本中的描述)(60)-ASN.1 意外字段编号) 在 sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:710) 在 sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:248) 在 sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179) ... 14 更多 原因:KrbException: Generic error (description in e-text) (60) - ASN.1 unexpected field number 在 sun.security.krb5.KrbApRep.(KrbApRep.java:126) 在 sun.security.krb5.KrbApRep.(KrbApRep.java:102) 在 sun.security.krb5.KrbApRep.(KrbApRep.java:75) 在 sun.security.jgss.krb5.AcceptSecContextToken.(AcceptSecContextToken.java:89) 在 sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:696) ... 16 更多 原因:KrbException:标识符与预期值不匹配 (906) 在 sun.security.krb5.internal.APRep.init(APRep.java:92) 在 sun.security.krb5.internal.APRep.(APRep.java:75) 在 sun.security.krb5.KrbApRep.(KrbApRep.java:116) ... 20 更多

我使用的是 java 7,但使用另一个没有问题。有没有办法使用 jvm 正确读取票证(请参阅 jdk 的 kinit 也不要创建正确的票证)

【问题讨论】:

    标签: java oracle kerberos


    【解决方案1】:

    我正在分享这段一直为我工作的代码。你设置好kerberos缓存文件的位置了吗?

    OracleDriver driver = new OracleDriver();
    Properties prop = new Properties();
    
    prop.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_NET_AUTHENTICATION_SERVICES,
      "("+AnoServices.AUTHENTICATION_KERBEROS5+")");  
    prop.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_NET_AUTHENTICATION_KRB5_MUTUAL,
      "true");    
    
    /* If you get the following error [Unable to obtain Principal Name for 
     * authentication] although you know that you have the right TGT in your
     * credential cache, then it's probably because the JVM can't locate your
     * cache.
     * For example, here my credential cache is
     *        C:\Documents and Settings\Jean de Lavarene\krb5cc
     * because when I run klist I get the following:
     *   > ./klist
     *   Ticket cache: FILE:C:\Documents and Settings\Jean de Lavarene\krb5cc
     *   Default principal: client@US.ORACLE.COM
     *
     *   Valid starting     Expires            Service principal
     *   06/21/16 13:23:02  06/21/16 23:23:02  krbtgt/US.ORACLE.COM@US.ORACLE.COM
     *   renew until 06/21/16 13:23:02
     * This isn't the default location, so I need to provide the location. Note
     * that the default location on windows is "C:\Documents and Settings\krb5cc_username".
     */
    prop.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_NET_AUTHENTICATION_KRB5_CC_NAME,
      "C:\\Documents and Settings\\Jean de Lavarene\\krb5cc");
    Connection conn  = driver.connect(url,prop);
    String auth = ((OracleConnection)conn).getAuthenticationAdaptorName();
    System.out.println("Authentication adaptor="+auth);
    

    【讨论】:

    • 我添加了缓存(正如我所说,它正确地从中读取凭据)您是否将此代码用于 oracle 11 或更低版本? oracle 12 出现问题,需要自己实现 kinit (okinit)
    • 这是 11.2 版本的 Oracle 数据库。我会用 12 试试看。
    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 2018-03-21
    • 2017-06-28
    相关资源
    最近更新 更多