2016-07-18 7 views
1

私はフォームベース認証を学習する初心者です。これまでのところ、私は "admin"ユーザ/ロールを持っていて、完璧に動作しますが、今では限られた権限を持つ別のロールを追加したいと思っています。私はオンラインで検索しましたが、チュートリアルには管理者の役割しかありません。 web.xmlファイルのどこにロールを追加しますか?フォームベースの認証で別の役割を追加する

web.xml電流:

<security-constraint> 
    <display-name>Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name> 
     <url-pattern>/protected/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>manager</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>Form-Based Authentication Area</realm-name> 
    <form-login-config> 
     <form-login-page>/login.jsp</form-login-page> 
     <form-error-page>/error.jsp</form-error-page> 
    </form-login-config> 
</login-config> 
<security-role> 
    <description> An administrator </description> 
    <role-name>manager</role-name> 
</security-role> 

私は別のセキュリティ制約および他のセキュリティ・ロールのタグを追加する、またはそれに追加する、または何か他のものでしょうか?

答えて

0

I役割を指定するために、異なる保護領域、ならびに他

<security-role>を指定する別の

<security-constraint>タグを追加しました。以下を参照してください:

<security-constraint> 
    <display-name>Admin Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Admin Area</web-resource-name> 
     <url-pattern>/protected/*</url-pattern> 
     <url-pattern>/admin/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>manager</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

<security-constraint> 
    <display-name>Regular User Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name> 
     <url-pattern>/protected/*</url-pattern> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>employee</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>Form-Based Authentication Area</realm-name> 
    <form-login-config> 
     <form-login-page>/login.jsp</form-login-page> 
     <form-error-page>/error.jsp</form-error-page> 
    </form-login-config> 
</login-config> 
<security-role> 
    <description> An administrator </description> 
    <role-name>manager</role-name> 
</security-role> 
<security-role> 
    <description> A regular user </description> 
    <role-name>employee</role-name> 
</security-role> 

関連する問題