在項目中的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