How to use security constraints to redirect users to specific pages?

954 Views Asked by At

I have 2 groups ts_admin and ts_users. From the login page, an admin after logging in should go straight to admin view and the user to the user view. I'm not sure how to go about that, I need help. I have loaded an XML page containing security constraints perhaps we could take it from that point further.

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<security-constraint>
    <display-name>timesheet user permission</display-name>
    <web-resource-collection>
        <web-resource-name>timesheet_user_resources</web-resource-name>
        <url-pattern>/index.html</url-pattern>
        <url-pattern>/</url-pattern>
        <url-pattern>/rs/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ts_users</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<security-role>
    <role-name>ts_users</role-name>
</security-role>
<security-role>
    <role-name>ts_admins</role-name>
</security-role>

<security-constraint>
    <display-name>timesheet admin permissions</display-name>
    <web-resource-collection>
        <web-resource-name>timesheet_admin_resources</web-resource-name>
        <url-pattern>/rs/*</url-pattern>

        <url-pattern>/indexAdmin.html</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ts_admins</role-name>
    </auth-constraint>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>MyRealm</realm-name>

    <form-login-config id="FormLoginConfig_1">
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
    </form-login-config>
</login-config>

1

There are 1 best solutions below

0
eldix_ On

The XML file loaded is well set and it doesn't need any alterations. I've created links on both index and indexAdmin page for easy interchange and I've also used the ng-show to only show the links when the system authenticates one as the admin. On the JS page then added $scope.isAdmin = data.data.admin;