美文网首页
web http basic authentication

web http basic authentication

作者: 义焃 | 来源:发表于2020-09-18 16:57 被阅读0次
    在项目中的web.xml文件中添加如下代码:

    <security-constraint>
    <web-resource-collection>
    <web-resource-name>Monitor Page</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
    <role-name>admin</role-name>
    </auth-constraint>
    </security-constraint>
    <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>monitor</realm-name>
    </login-config>
    <security-role>
    <role-name>admin</role-name>
    </security-role>

    在jetty.xml文件中添加:

    <Call name="addBean">
    <Arg>
    <New class="org.eclipse.jetty.security.HashLoginService">
    <Set name="name">monitor</Set>
    <Set name="config"><Property name="jetty.home" default="."/>/appconfig/realm.properties</Set>
    <Set name="refreshInterval">5</Set>
    </New>
    </Arg>
    </Call>

    在appconfig文件夹下创建realm.properties属性文件,并添加如下内容:

    realm账号形式:# <username>: <password>[,<rolename> ...]

    The format is

    <username>: <password>[,<rolename> ...]

    Passwords may be clear text, obfuscated or checksummed. The class

    org.eclipse.util.Password should be used to generate obfuscated

    passwords or password checksums

    If DIGEST Authentication is used, the password must be in a recoverable

    format, either plain text or OBF:.

    jetty: MD5:164c88b302622e17050af52c89945d44,user
    admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user
    other: OBF:1xmk1w261u9r1w1c1xmq,user
    plain: plain,admin

    使用curl命令的访问方式

    curl -k -u user:password https://192.168.10.74:8843/barometer/toPages/toHostList.action

    curl -k -u user:password https://192.168.10.74:8843/barometer/monitorIndexAction/toMonitorPage.action?ip=192.168.187.45

    相关文章

      网友评论

          本文标题:web http basic authentication

          本文链接:https://www.haomeiwen.com/subject/acvjyktx.html