web http basic authentication

2020-09-18  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读