Unable to customize UsernamePasswordCredential class in CAS 7.2.4

133 views
Skip to first unread message

Prakash Thapa

unread,
Sep 2, 2025, 7:03:28 AM (3 days ago) Sep 2
to CAS Community
I am trying to customize the UsernamePasswordCredential class by extending it from the CAS default class. However I am unable to proceed further as I am getting typecast issue in the doAuthentication() of AbstractUsernamePasswordAuthenticationHandler class. I have customized AbstractUsernamePasswordAuthenticationHandler to support the new Custom UsernamePasswordCredential class.

Block of Code:
public abstract class CustomAbstractUsernamePasswordAuthenticationHandler extends AbstractUsernamePasswordAuthenticationHandler {

@Override
protected final AuthenticationHandlerExecutionResult doAuthentication(Credential credential, final Service service) throws Throwable {
final CustomUsernamePasswordCredential originalUserPass = (CustomUsernamePasswordCredential) credential;
......
......
}
}
Error Message: 
  • Cannot cast 'org.apereo.cas.authentication.handler.support.CustomUsernamePasswordCredential' to 'org.apereo.cas.authentication.handler.support.CustomUsernamePasswordCredential'

Prakash Thapa

unread,
Sep 2, 2025, 8:11:10 AM (3 days ago) Sep 2
to CAS Community, Prakash Thapa

This is the code snippe
B652C9E0-946C-4634-B071-B7CD5AEBCE1D.png

Ray Bon

unread,
Sep 2, 2025, 3:46:08 PM (3 days ago) Sep 2
to cas-...@apereo.org
Prakash,

This sounds more like a java problem.
You could check with instanceOf before casting.

Ray

From: cas-...@apereo.org <cas-...@apereo.org> on behalf of Prakash Thapa <thapaprak...@gmail.com>
Sent: September 1, 2025 22:14
To: CAS Community <cas-...@apereo.org>
Subject: [cas-user] Unable to customize UsernamePasswordCredential class in CAS 7.2.4
 
You don't often get email from thapaprak...@gmail.com. Learn why this is important
--
- Website: https://apereo.github.io/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
---
You received this message because you are subscribed to the Google Groups "CAS Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cas-user+u...@apereo.org.
To view this discussion visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/70db0edb-2b5e-4f5d-91b4-f603acae3b01n%40apereo.org.

Prakash Thapa

unread,
Sep 3, 2025, 6:30:32 AM (2 days ago) Sep 3
to CAS Community, Ray Bon
Hi Ray,

The credential instanceof CustomUsernamePasswordCredential returns false. But the credential.getClass() returns the same class i.e. CustomUsernamePasswordCredential, to which I am trying to typecast.

Ray Bon

unread,
Sep 3, 2025, 3:25:10 PM (2 days ago) Sep 3
to CAS Community
Prakash,

Do the full path hierarchies match?
That is, is it possible there is another CustomUsernamePasswordCredential class?

This strange casting problem can occur with multiple class loaders (cast acting in only one loader). How are you running cas?

Ray

From: Prakash Thapa <thapaprak...@gmail.com>
Sent: September 2, 2025 21:01
To: CAS Community <cas-...@apereo.org>
Cc: Ray Bon <rb...@uvic.ca>
Subject: Re: [cas-user] Unable to customize UsernamePasswordCredential class in CAS 7.2.4
 
Reply all
Reply to author
Forward
0 new messages