【问题标题】:Rest Webservice Basic AuthorizationRest Webservice 基础授权
【发布时间】:2017-06-08 14:29:16
【问题描述】:

我正在尝试为我的 Rest 网络服务添加基本授权。在 weblogic 上,我在默认安全领域下创建了相同的用户。当我在未通过授权的情况下执行我的休息客户端时,它返回 HTTP 200 意味着应用程序正在使用该请求。但是,如果我通过授权,它会验证用户名密码。我希望我的服务仅在授权下工作。有人可以让我知道我错过了什么或者我做错了什么吗? 在 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"
        id="WebApp_ID" version="3.0">
        <display-name>PP</display-name>
        <servlet>
            <servlet-name>jersey-servlet</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>com.sun.jersey.config.property.packages</param-name>
                <param-value>com.att.eddpp.preprocessing</param-value>
            </init-param>
            <init-param>
                <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
                <param-value>true</param-value>
            </init-param>
            <init-param>
            <param-name>wl-dispatch-policy</param-name>
            <param-value>PP-work-manager</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>jersey-servlet</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
        <security-constraint>
            <web-resource-collection>
                <web-resource-name>PP</web-resource-name>
                <url-pattern>/PP/*</url-pattern>
                <http-method>POST</http-method>

            </web-resource-collection> 
        <auth-constraint>
        <role-name>PPRST</role-name>

        </auth-constraint>
        </security-constraint>
        <login-config>
                  <auth-method>BASIC</auth-method>
                  <realm-name>default</realm-name>
              </login-config>
               <security-role>
                   <role-name>PPRST</role-name>
               </security-role>


    </web-app>


    in weblogic.xml i have added 

    <?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/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
        <wls:weblogic-version>12.1.3</wls:weblogic-version>
        <wls:context-root>PP</wls:context-root>

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

【问题讨论】:

    标签: rest restful-authentication


    【解决方案1】:

    您的约束是针对 /PP/* 但您的球衣资源在 /* 下。我认为这就是问题所在。

    【讨论】:

    • 我也厌倦了这个。还是没有运气。
    猜你喜欢
    • 2022-08-17
    • 2012-02-10
    • 2020-09-23
    • 2018-09-06
    • 2016-12-10
    • 2019-10-29
    • 1970-01-01
    • 2015-12-10
    • 2011-07-26
    相关资源
    最近更新 更多