Java 以前使用证书身份验证的servlet已更改,现在正在引发异常

Java 以前使用证书身份验证的servlet已更改,现在正在引发异常,java,servlets,Java,Servlets,Java servlet应用程序已更改,因此不再需要证书身份验证。 那部分工作正常。但是,应用程序不再连接到数据库,并引发以下异常: > REMOTE USER IS null MY URL is 0:0:0:0:0:0:0:1 NULL GENERICPRINCIPAL > Apr 01, 2021 12:43:11 PM org.apache.catalina.core.StandardWrapperValve > invoke SEVERE: Servlet.servic

Java servlet应用程序已更改,因此不再需要证书身份验证。 那部分工作正常。但是,应用程序不再连接到数据库,并引发以下异常:

> REMOTE USER IS null MY URL is 0:0:0:0:0:0:0:1 NULL GENERICPRINCIPAL
> Apr 01, 2021 12:43:11 PM org.apache.catalina.core.StandardWrapperValve
> invoke SEVERE: Servlet.service() for servlet
> [com.harris.cpd.resource.ApplicationConfig] in context with path
> [/cpd] threw exception [java.lang.NullPointerException] with root
> cause java.lang.NullPointerException  at
> com.harris.cpd.resource.CPDResource.getTomcatUserRole(CPDResource.java:116)
下面是web.xml,注释中显示了更改

 <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
        <display-name>cpd</display-name>
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>chemicals.html</welcome-file>
        </welcome-file-list>
    
    <!-- THIS IS NEW CODE -->
        <filter>
            <filter-name>CPDAuthenticationFilter</filter-name>
            <filter-class>com.harris.cpd.filter.CPDAuthenticationFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>CPDAuthenticationFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
     
        
    <!--  THIS SECTION IS NEW CODE -->
        <servlet>
            <servlet-name>cpd</servlet-name>
        </servlet>
        <servlet-mapping>
            <servlet-name>cpd</servlet-name>
            <url-pattern>/cpd/*</url-pattern>
        </servlet-mapping>
      
<!-- THIS SECTION IS NOW COMMENTED OUT
        <security-constraint>
            <web-resource-collection>
                <web-resource-name>BasicSecurity</web-resource-name>
                <url-pattern>/*</url-pattern>
                <http-method>GET</http-method>
                <http-method>POST</http-method>
                <http-method>DELETE</http-method>
                <http-method>PUT</http-method>
            </web-resource-collection>
            <auth-constraint>
                <description>Authorized role is librarian</description>
                <role-name>DOMAIN_LIBRARIAN</role-name>
            </auth-constraint>
        </security-constraint>
        <security-constraint>
            <web-resource-collection>
                <web-resource-name>BasicSecurity</web-resource-name>
                <url-pattern>/*</url-pattern>
                <http-method>GET</http-method>
                <http-method>PUT</http-method>
                <http-method>POST</http-method>
                <http-method>DELETE</http-method>
            </web-resource-collection>
            <auth-constraint>
                <description>Authorized role is guest and librarian</description>
                <role-name>DOMAIN_LIBRARIAN</role-name>
                <role-name>DOMAIN_GUEST</role-name>
            </auth-constraint>
        </security-constraint> -->
        
    <!-- THIS IS NEW CODE AND PROVIDES THE BASIC LOGIN -->
        <login-config>
            <auth-method>BASIC</auth-method>
            <realm-name>Login</realm-name>
        </login-config>
    
<!-- THIS CODE IS NOW COMMENTED OUT
        <login-config>
          <auth-method>CLIENT-CERT</auth-method>
          <realm-name>IAASecurityRealm</realm-name>
       </login-config> -->
    
      
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>DOMAIN_GUEST</role-name>
      </security-role>
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>DOMAIN_LIBRARIAN</role-name>
      </security-role>
     
     <!--  
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>GUEST</role-name>
      </security-role>
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>LIBRARIAN</role-name>
      </security-role>
    -->
    
    </web-app>
客户端Chrome调试工具上显示的错误:

-- LOADING APP (index.html) --
:8080/cpd/resources/categories:1 Failed to load resource: the server responded with a status of 500 ()
angular.js:14516 -- db: getProcessCategories url:http://localhost:8080/cpd/resources/categories procCats 500  failed --
因此,问题表现为servlet错误,数据库没有连接,返回任何内容,只是我上面所示的更改。

我认为这个异常与数据库连接无关。 根据你所面临的例外情况。 getTomcatUserRole(CPDResource.java:116)

我认为还有另一个类,如CPDResource.java,受到了这种更改的影响

  <!--  
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>GUEST</role-name>
      </security-role>
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>LIBRARIAN</role-name>
      </security-role>
    -->

您应该将其设置为硬代码,而不是像以前那样从角色获取

  <!--  
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>GUEST</role-name>
      </security-role>
      <security-role>
        <description>A Guest User in the system</description>
        <role-name>LIBRARIAN</role-name>
      </security-role>
    -->