Spring Custom User Details from DAL - Casting
===

I'm currently working on a System that makes use of Spring Security. I have the Authentication Provider setup but I'm having a problem creating a custom User Type which would store all the information I need.

In the Authentication Provider, I call a "User Service" which is a DAL to the users in the system. This then returns a "User" object. Which is fine and that's all working.

But I then have a MyCompanyUserDetails object defined which contains all the custom attributes I need. This Class extends the "User" class.

My Problem is I can't cast the User to CompanyUserDetails. Am I missing something here ?

The Custom User Details Type:

    public class CompanyUserDetails extends User {

and in my Authentication Provider:

    // Create / Update the user.
    User raw_user_details = getUser(username_str, groups_of_user);
    			
    // Create our Custom user object filled with the parameters we need for the rest of the system.
    MyCompanyUserDetails details = (MyCompanyUserDetails) raw_user_details;

Any help / guidance would be appreciated...