Hi to all,
I'm trying to develope a custom AuthenticatorFactory with a custom
Authenticator.
I would like to inject my custom Authenticator as Spring Bean into my
custom AuthenticatorFactory (because my authenticator should use an existing
spring library).
My authenticator is like:
@Component
public class MyAuthenticator extends AbstractUsernameFormAuthenticator
implements Authenticator {
[.]
To achieve it, I created an ApplicationContextAware bean
@Service
public class BeanUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public BeanUtil() {
}
@Override
public void setApplicationContext(ApplicationContext
applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
public static Authenticator getAuthenticatorBean() {
return applicationContext.getBean(MyAuthenticator.class);
}
}
My factory is:
public class MyAuthenticatorFactory implements AuthenticatorFactory,
ConfigurableAuthenticatorFactory {
public static final String PROVIDER_ID = "aruba-alias-authenticator";
public static final String G_RECAPTCHA_RESPONSE =
"g-recaptcha-response";
public static final String RECAPTCHA_REFERENCE_CATEGORY = "recaptcha";
public static final String SITE_KEY = "site.key";
public static final String NUMBER_KEY = "number.key";
public static final String SITE_SECRET = "secret";
@Override
public String getId() {
return PROVIDER_ID;
}
@Override
public MyAuthenticator create(KeycloakSession session) {
return BeanUtil.AuthenticatorBean();
}
[.]
Keycloak starts up correctly.
When I try to use myAuthenticator, i get:
16:46:48,484 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http
management interface listening on
http://0.0.0.0:9990/management
sia-keycloak | 16:46:48,484 INFO [org.jboss.as] (Controller Boot Thread)
WFLYSRV0051: Admin console listening on
http://0.0.0.0:9990
sia-keycloak | 16:46:48,485 INFO [org.jboss.as] (Controller Boot Thread)
WFLYSRV0025: Keycloak 4.5.0.Final (WildFly Core 5.0.0.Final) started in
23456ms - Started 943 of 1231 services (653 services are lazy, passive or
on-demand)
sia-keycloak | 16:47:12,357 WARN [org.keycloak.services] (default task-3)
KC-SERVICES0013: Failed authentication: java.lang.NullPointerException
sia-keycloak | at
...authenticator.alias.BeanUtil.getArubaAliasAuthenticatorBean(BeanUtil.java
:22)
sia-keycloak | at
..authenticator.alias.AuthenticatorFactory.create(MyAuthenticatorFactory.jav
a:35)
sia-keycloak | at
...authenticator.alias.AuthenticatorFactory.create(MyAuthenticatorFactory.ja
va:1)
The reason in that the Spring Context is null.
Any idea about how to fix this issue?
Many thanks,
Tom