This is the code to create a Principal object.
List<String> roles = new ArrayList();
roles.add(userRole);
this.principal = new GenericPrincipal(username,"***********",roles);
When I printed the principal object, I got [username(userRole,)]
Getting the name from principal
GenericPrincipal principal = (GenericPrincipal)request.getUserPrincipal();
String name = principal.getName();
Getting the roles from principal
GenericPrincipal principal = (GenericPrincipal)request.getUserPrincipal();
String[] roles = principal.getRoles();
When I printed the principal object, I got [username()]
I'm able to get the name from Principal but not the roles. The length of roles[] is 0.
I even tried getPassword() method. It returns null. Only the getName() method works correctly.
Why is the roles array empty and How do I get the role correctly?