使用JDBCREALM基于表格的身份验证



我正在实现表单身份验证。我已经在server.xml文件中编辑了Realm标签。我还更改了Web.xml文件。但是,当我运行Web应用程序并尝试获取SQL Server的连接时,会引发异常。

> om.microsoft.sqlserver.jdbc.SQLServerException: This driver is not
> configured for integrated authentication.
> ClientConnectionId:9a62dffc-956c-49e6-b3b4-0911fab60562   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2399)
>   at
> com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:68)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3131)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:42)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3122)
>   at
> com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2444)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1980)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1627)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1458)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:772)
>   at
> com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
>   at java.sql.DriverManager.getConnection(DriverManager.java:664)     at
> java.sql.DriverManager.getConnection(DriverManager.java:270)  at
> Database.DAO.<clinit>(DAO.java:31)    at
> classes.Job.loadJobs(Job.java:129)    at
> Controllers.ContextListerner.contextInitialized(ContextListerner.java:16)
>   at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4717)
>   at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
>   at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
>   at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
>   at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
>   at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
>   at
> org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)     at
> org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
>   at
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
>   at
> com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
>   at
> org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482)
>   at
> org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)     at
> org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
>   at
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
>   at
> com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
>   at
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
>   at
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
>   at
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
>   at
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
>   at
> javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)     at
> sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324)
>   at sun.rmi.transport.Transport$1.run(Transport.java:200)    at
> sun.rmi.transport.Transport$1.run(Transport.java:197)     at
> java.security.AccessController.doPrivileged(Native Method)    at
> sun.rmi.transport.Transport.serviceCall(Transport.java:196)   at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
>   at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
>   at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
>   at java.security.AccessController.doPrivileged(Native Method)   at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
>   at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>   at java.lang.Thread.run(Thread.java:745) Caused by:
> java.lang.UnsatisfiedLinkError: Native Library C:Program
> FilesJavaapache-tomcat-9.0.0.M13binsqljdbc_auth.dll already loaded
> in another classloader
> 
> 
> Blockquote

我已经发送了web.xml和server.xml文件的代码。再加上我试图获得数据库连接的代码。server.xml

<Realm className="org.apache.catalina.realm.JDBCRealm"
       driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
   connectionURL="jdbc:sqlserver://DESKTOP-ND3EINKSQLEXPRESS;databaseName=HRSystem;integratedSecurity=true"
       userTable="HR.users" userNameCol="user_name" userCredCol="user_pass"
   userRoleTable="HR.user_roles" roleNameCol="role_name"/>

web.xml

    <display-name>SecurityConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>HRPmain</web-resource-name>
        <url-pattern>/HRPmain.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>HRPersonnel</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method> FORM</auth-method>
    <realm-name>org.apache.catalina.realm.JDBCRealm</realm-name>
    <form-login-config>
        <form-login-page>/login2.xhtml</form-login-page>
        <form-error-page>/error.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <role-name>HRPersonnel</role-name>
</security-role>

发生例外的代码

   static{
            try{
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                con = DriverManager.getConnection("jdbc:sqlserver://DESKTOP-ND3EINK\SQLEXPRESS;databaseName=HRSystem;integratedSecurity=true");

            }
 catch (Exception e){
        e.printStackTrace();
    }
}

而不是集成安全性,我给出了一个用户名和密码。它起作用了。

相关内容

  • 没有找到相关文章

最新更新