Login Or Sign up

tomcat realm set user roles dynamically

306 Views Asked by At

I am using tomcat security for my application:

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> 
<!--This is only applicable for Tomcat 8.5 and higher version with SQL server authentication-->
    <Realm className="org.apache.catalina.realm.JDBCRealm"
          driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://xxx.xx.xxx.xxx:1433;databaseName=xxxxx" connectionName="xxxx" connectionPassword="xxxx"             roleNameCol="role_name" userCredCol="user_pass" userNameCol="user_name" userRoleTable="user_roles" userTable="users">
        <CredentialHandler algorithm="MD5" className="org.apache.catalina.realm.MessageDigestCredentialHandler"/>
    </Realm>
</Realm>

Now I want to be able to dynamically set new roles to the logged-in user from within the application whatever the authentication datasource may be. I need this to be deployed in an application and the client won't let us have the authentication database details and would prefer to themselves set the realm details. So it should work for all server/database types and hence be generic to the extent as possible.

0

There are 0 best solutions below