FX-HAO / keycloak-phone-authenticator

Obtain token and reset password via SMS
130 stars 43 forks source link

Failed to define class com.hfx.keycloak.spi.ResetCredentialWithPhone in Module "deployment.phone.jar" #7

Closed SlausB closed 3 years ago

SlausB commented 3 years ago

Hello! When I try to add this add-on, Keycloak gives error on startup: Failed to define class com.hfx.keycloak.spi.ResetCredentialWithPhone in Module "deployment.phone.jar" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link com/hfx/keycloak/spi/ResetCredentialWithPhone (Module "deployment.phone.jar" from Service Module Loader): org/keycloak/authentication/authenticators/resetcred/ResetCredentialChooseUser

My set up:

What could be the problem? Thanks in advance!

FX-HAO commented 3 years ago

You cannot put your jar into the standalone/deployments folder, it's called hot deployment. you need to register it using Modules. Or you can take at look at my example Dockerfile.

My example Dockerfile:

# base image
FROM jboss/keycloak:9.0.2

# copy the jars into the current folder
COPY --from=builder /app/keycloak-phone-authenticator/target/keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar .
COPY --from=builder /app/keycloak-phone-authenticator-yuntongxun-sms/target/keycloak-phone-authenticator-yuntongxun-sms-1.0.0-SNAPSHOT.jar .
COPY --from=builder /app/yuntongxun4j/target/yuntongxun4j-1.0-SNAPSHOT.jar .
COPY examples/cli/ cli/

# register the jars
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=cli/keycloak-phone-authenticator-yuntongxun-sms-config.cli
RUN $JBOSS_HOME/bin/jboss-cli.sh --file=cli/module-add.cli

# copy the resource files into the current folder
COPY --from=builder /app/keycloak-phone-authenticator/target/classes/theme-resources/templates/ $JBOSS_HOME/themes/base/login/
COPY ./messages/ messages/

# fix a bug
RUN rm -rf /opt/jboss/keycloak/standalone/configuration/standalone_xml_history/current

# register the resource files
RUN cat messages/messages_en.properties >> $JBOSS_HOME/themes/base/login/messages/messages_en.properties && \
    cat messages/messages_zh_CN.properties >> $JBOSS_HOME/themes/base/login/messages/messages_zh_CN.properties && \
    cat messages/messages_en.properties >> $JBOSS_HOME/themes/base/account/messages/messages_en.properties && \
    cat messages/messages_zh_CN.properties >> $JBOSS_HOME/themes/base/account/messages/messages_zh_CN.properties

6 is related to this and can answer your questions.

SlausB commented 3 years ago

Thank you for the instant response! Seems I managed to adapt Dockerfile to my Keycloak setup, but on user login page An internal server error has occurred message shown and Keycloak outputs to console:

  | 12:44:41,754 ERROR [freemarker.runtime] (default task-2) Error executing FreeMarker template: freemarker.core._MiscTemplateException: Macro "registrationLayout" has no parameter with name "displayWide".
  | 
  | ----
  | FTL stack trace ("~" means nesting-related):
  |      - Failed at: #macro registrationLayout bodyClass="...  [in template "template.ftl" in macro "registrationLayout" at line 1, column 1]
  |      - Reached through: @layout.registrationLayout displayInf...  [in template "login-with-phone.ftl" at line 2, column 1]
  | ----
  |      at org.freemarker@2.3.29//freemarker.core.Environment.setMacroContextLocalsFromArguments(Environment.java:921)
  |      at org.freemarker@2.3.29//freemarker.core.Environment.invokeMacroOrFunctionCommonPart(Environment.java:854)
  |      at org.freemarker@2.3.29//freemarker.core.Environment.invokeMacro(Environment.java:809)
  |      at org.freemarker@2.3.29//freemarker.core.UnifiedCall.accept(UnifiedCall.java:83)
  |      at org.freemarker@2.3.29//freemarker.core.Environment.visit(Environment.java:331)
  |      ...

I have everything set up for version keycloak/keycloak:13.0.0. Maybe keycloak-phone-authenticator not supposed to work with version 13? Or I am doing something wrong? Thanks in advance.

FX-HAO commented 3 years ago

I haven't tried this with Keycloak 13. When I tried to build keycloak 13.0.1 locally, I got some errors like this. Hmmm... I haven't fixed it, let me try it tomorrow.

FX-HAO commented 3 years ago

Hi, I just released a new version to support Keycloak 13. Could you please test if it solves your problems? Let me know if anything wrong. thank you.

SlausB commented 3 years ago

It worked! Thank you very much!