在具有OHS的Weblogic 12.2.1上的HTTP Basic身份验证中两次询问用户名和密码

时间:2019-05-20 14:43:02

标签: java jsp authentication weblogic

我有一个使用OHS部署在Weblogic 12.2.1上的基于Java的简单Web应用程序。有一个简单的JSP页面,其中包含一个用于上传文件的servlet。

index.jsp:

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Checklist Administration</title>
    </head>
    <body>
        <h2>Checklist Upload</h2> 
        <fieldset>
            <legend>Upload Checklist (XML)</legend>
            <form action="checklist_upload" method="post" enctype="multipart/form-data">
                <label for="fileName">Select Checklist: </label>
                <input id="checklistFile" type="file" name="checklistFile" accept=".xml"/><br/>            
                <input id="checklistButton" type="submit" value="Upload" disabled />
            </form>
        </fieldset>
    <script type="text/javascript">
    document.getElementById("checklistFile").addEventListener("change", function(){
        if (document.getElementById("checklistFile").files.length == 1) {
            document.getElementById("checklistButton").disabled = false;
        }
    });
    </script>
    </body>
    </html>

应该使用基本HTTP身份验证来访问此页面。在Weblogic和web.xml中将用户和组配置为Realm:

    <servlet>
        <servlet-name>ChecklistUploadServlet</servlet-name>
        <servlet-class>com.teamead.aimsl.wsproxy.checklist.ChecklistUploadServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ChecklistUploadServlet</servlet-name>
        <url-pattern>/checklist/checklist_upload</url-pattern>
    </servlet-mapping>
    <security-constraint>
        <display-name>Preclude access to GET</display-name>
        <web-resource-collection>
            <web-resource-name>Checklist Admin</web-resource-name>
            <url-pattern>/checklist/index.jsp</url-pattern>
            <url-pattern>/checklist/checklist_upload</url-pattern>
            <url-pattern>/checklist/result.jsp</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN_ROLE</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Admin Area</realm-name>
    </login-config>
    <security-role>
        <role-name>ADMIN_ROLE</role-name>
    </security-role>

weblogic.xml:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd 
                        http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.8/weblogic-web-app.xsd">

    <wls:weblogic-version>12.2.1</wls:weblogic-version>
    <wls:virtual-directory-mapping>
        <wls:url-pattern>/xsd/*</wls:url-pattern>
        <wls:url-pattern>/wsdl/*</wls:url-pattern>
    </wls:virtual-directory-mapping>
    <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>

    <wls:security-role-assignment>
        <wls:role-name>ADMIN_ROLE</wls:role-name>
        <wls:principal-name>admin</wls:principal-name>
    </wls:security-role-assignment>
</wls:weblogic-web-app>

该行为非常奇怪。尝试使用URL上传文件时 http://server:7001/checklist/index.jsp 然后要求我提供凭据,并在提供它们后显示JSP页面,但是当我单击“浏览”按钮时,选择一个文件并单击“上传”按钮,然后再次要求我输入用户名和密码。提供所有这些内容后,即使不提供它们,但按Esc键,一切正常,然后收到HTTP错误401-未经授权,然后按F5键重新加载,文件成功上传。知道这里发生了什么吗?

1 个答案:

答案 0 :(得分:0)

这是一个旧帖子,但我遇到了几乎相同的情况。

您需要关闭 enforce-valid-basic-auth-credentials 中的 config.xml 标志。默认情况下,此标志设置为 true,因此您需要将其关闭。

请注意,这是与 WebLogic 域相关的全局设置。

这可以解决您的问题。

材料:

希望这可以帮助人们节省时间。