[keycloak-user] KeycloakPrincipal ClassCastException in JSF custom component

Brent Vaughn Vaughn at climatecontrolgroup.com
Thu Mar 9 18:46:00 EST 2017


Using KeyCloak 2.5.4 and Wildfly 10.1.0


I am attempting to create a JSF component that involves Keycloak.  I am getting this exception:


java.lang.ClassCastException: org.keycloak.KeycloakPrincipal cannot be cast to org.keycloak.KeycloakPrincipal



Below is the line of code that throws the exception.


public void encodeBegin(FacesContext context) {

..........

KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) context.getExternalContext().getUserPrincipal();

..........

}



Funny thing is this.  The exception is only thrown when the JSF Component is in a separate jar and then added to the project.  If I put the code in question directly in the project, it doesn't throw the exception.


Can anyone help me with this?



More information about the keycloak-user mailing list