web http basic authentication

在項目中的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文件夾下創(chuàng)建realm.properties屬性文件,并添加如下內(nèi)容:

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。