SimplePrincipal with a specified user name not working as expected after login [message #1862343] |
Mon, 27 November 2023 08:28  |
Eclipse User |
|
|
|
Hi there everyone,
The RestCredentialVerifier.java class in my application uses a Subject with a defined SimplePrincipal string. I've seen the same code in some examples on this forum.
subject.getPrincipals().add(new SimplePrincipal("system"));
subject.getPrincipals().add(new SimplePrincipal("access-check-user"));
subject.getPrincipals().add(new SimplePrincipal("user"));
All three variations above work, but it does not seem right to me because it means ALL logged-in users have the same SimplePrincipal profile (I may be wrong here, I'm still trying to figure it all out).
So I decided to replace the variations above with the following:
subject.getPrincipals().add(new SimplePrincipal(username));
However, after logging in successfully, my Desktop is blank (see attached screenshot).
The code in my RestCredentialVerifier.java class is as follows:
public class RestCredentialVerifier implements ICustomCredentialVerifier {
private static final Logger LOG = LoggerFactory.getLogger(RestCredentialVerifier.class);
Map<String, String> mapResult = new HashMap<>();
@Override
public int verify(String username, char[] passwordPlainText) throws IOException {
Subject subject = new Subject();
// Any ONE OF THESE WORK!
// subject.getPrincipals().add(new SimplePrincipal("system"));
// subject.getPrincipals().add(new SimplePrincipal("access-check-user"));
// subject.getPrincipals().add(new SimplePrincipal("user"));
// This DOES NOT WORK PROPERLY!
subject.getPrincipals().add(new SimplePrincipal(username));
subject.setReadOnly();
RunContext runContext =
RunContexts.copyCurrent(true).withSubject(subject);
// Send the authentication details to the database for verification
int result = runContext.call(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
Map<String, String> mapResult = BEANS.get(IRestAuthenticationService.class)
.verify(lowerCaseUsername(username), createHashedPassword(passwordPlainText).toString());
boolean IsAuthenticatedUser =
mapResult.get("message").equals(TEXTS.get("YouAreNowConnectedToTheServer").trim());
return IsAuthenticatedUser ? AUTH_OK : AUTH_FAILED;
}
});
return result;
}
}
My use case is a bit similar to https://www.eclipse.org/forums/index.php/m/1841325/?srch=SimplePrincipal except that I'm not using tokens.
Can anyone please help me resolve this problem?
Cheers,
JD
Attachment: Blank UI.png
(Size: 16.19KB, Downloaded 82 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.65829 seconds