2016-07-18 33 views
1

Ich bin ein Anfänger, der formularbasierte Authentifizierung lernt. Bis jetzt habe ich meine "admin" Benutzer/Rolle und es funktioniert perfekt, aber jetzt möchte ich eine andere Rolle mit eingeschränkten Privilegien hinzufügen. Ich habe online gesucht, aber die Tutorials haben nur die Admin-Rolle. Wo würde ich die Rolle in der web.xml-Datei hinzufügen?Eine weitere Rolle in der formularbasierten Authentifizierung hinzufügen

Aktuelle 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> 

Würde ich fügen Sie eine weitere Sicherheitszwang und andere sicherheits Rolle-Tag, oder, um es hinzuzufügen, oder etwas anderes?

Antwort

0

Ich habe eine andere

<security-constraint> Tag einen anderen geschützten Bereich zu spezifizieren, sowie eine weitere

<security-role> die Rolle angeben. Siehe unten:

<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>