AuthenticationConfiguration authConfig = AuthenticationConfiguration.empty() //
.useCallbackHandler(new SampleCallbackHandler()) //
.setSaslMechanismSelector(SaslMechanismSelector.fromString("OAUTHBEARER")) //
.useBearerTokenCredential(token);
AuthenticationContext context = AuthenticationContext.empty() //
.with(MatchRule.ALL, authConfig);
The simplest way I am thinking/hoping to get it running is:
- Connect to the EJB (may be with credentials username/password, or without).
- Upon failing authentication, retrieve token from KeyCloak
- Use the token to authenticate
The current setup I have, seems to be missing at least item-2 (retrieving Oauth2 Token from KeyCloak).
I can hardcode/configure keycloak auth-url to retrieve the token, but then this is painful to maintain for
many applications/customers. Additionally, I am missing the part where the AuthenticationClient may connect to KC and obtain a token if it
is not available. At the moment I am hardcoding it "VERY_LONG_STRING_TOKEN_FROM_KEYCLOAK".
Of course callback handler is not being invoked in the above code, as it was earlier at some point. I may need to rectify this if I want to store the token
in secure storage on the client for extended period of time.
I will be trying to recreate my setup and clean prior configurations with virtual-security-domain. It is worth mentioning that at this point, all I need
is to get authentication to work, and understand what is happening. I am less concerned about authorization (to keep it simple).
My questions now, given that:
* We are using WF 26.
* I am concerned only with Authentication using OAuth2.
* A working setup is working for Rest-API.
* The above code are producing the error:
08:09:29,744 TRACE [org.wildfly.security] (default task-1) Handling SecurityIdentityCallback: identity = SecurityIdentity{principal=mansour, securityDomain=org.wildfly.security.auth.server.SecurityDomain@17615f20, authorizationIdentity=EMPTY, realmInfo=RealmInfo{name='oidc-realm', securityRealm=org.wildfly.security.auth.realm.token.TokenSecurityRealm@2d390a84}, creationTime=2024-05-30T12:09:29.734233100Z}
08:09:30,096 TRACE [org.wildfly.security] (default task-1) Principal assigning: [mansour], pre-realm rewritten: [mansour], realm name: [ApplicationRealm], post-realm rewritten: [mansour], realm rewritten: [mansour]
08:09:30,702 INFO [com.somedomain.example.JNDIUtils] (default task-1) Remoting Address set to 'remote+
http://127.0.0.1:8080'
08:09:30,709 INFO [org.wildfly.naming] (default task-1) WildFly Naming version 1.0.15.Final
08:09:30,739 INFO [org.jboss.ejb.client] (default task-1) JBoss EJB Client version 4.0.44.Final
08:09:30,795 TRACE [org.wildfly.security.xml] (default task-1) Fallback to parse legacy configuration.
08:09:30,795 TRACE [org.wildfly.security.xml] (default task-1) No legacy configuration available, using AuthenticationContext.empty()
08:09:30,818 TRACE [org.wildfly.security] (default task-1) getAuthenticationConfiguration uri=remote+
http://127.0.0.1:8080, protocolDefaultPort=-1, abstractType=ejb, abstractTypeAuthority=jboss, MatchRule=[null], AuthenticationConfiguration=[AuthenticationConfiguration:principal=anonymous,set-host=127.0.0.1,set-protocol=remote+http,set-port=8080,providers-supplier=org.wildfly.security.provider.util.ProviderUtil$1@3693b54,mechanism-properties={wildfly.sasl.local-user.quiet-auth=true}]
08:09:30,889 TRACE [org.wildfly.security] (XNIO-1 I/O-1)
Created SaslClient [null] for mechanisms [OAUTHBEARER]08:09:30,897 TRACE [org.wildfly.security.xml] (XNIO-1 task-1) Fallback to parse legacy configuration.
08:09:30,906 TRACE [org.wildfly.security.xml] (XNIO-1 task-1) No legacy configuration available, using AuthenticationContext.empty()
08:09:30,909 ERROR [com.somedomain.example.DBLoaderTest] (default task-1) Error while trying to load db properties: org.jboss.ejb.client.RequestSendFailedException: EJBCLIENT000409: No more destinations are available
at org.jboss....@4.0.44.Final//org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:620)
Which tells me the authentication is NOT working, but the exception is generated somewhere in my code. Not sure yet what to conclude from this, but
I am studying/reviewing the flow to have deeper understanding. Does this mean I need to setup Identity Propagation properly ? If so, how to deal with
virtual security domain through CLI in WF 26 ?
Thank you a lot for your help