FX-HAO / keycloak-phone-authenticator

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

java.lang.NoClassDefFoundError: Failed to link com/hfx/keycloak/spi/ResetCredentialWithPhone #1

Closed myxzjie closed 4 years ago

myxzjie commented 4 years ago

ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar\" Caused by: java.lang.NoClassDefFoundError: Failed to link com/hfx/keycloak/spi/ResetCredentialWithPhone (Module \"deployment.keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar\" from Service Module Loader): org/keycloak/authentication/authenticators/resetcred/ResetCredentialChooseUser"}}

FX-HAO commented 4 years ago

Sorry, could you post more details? It works on my machine. FYI, this library cannot work alone without an SMS implementation (i.e. 云通讯短信). If you are lucky to use the same SMS provider as i do, you can use keycloak-phone-authenticator-yuntongxun-sms, or else you need to implement your own one.

A Dockerfile example as below:

FROM maven:3.6.2-jdk-8 AS builder
WORKDIR /app/
COPY keycloak-phone-authenticator/ keycloak-phone-authenticator/
RUN mvn clean install -f keycloak-phone-authenticator
COPY yuntongxun4j/ yuntongxun4j/
RUN mvn clean install -f yuntongxun4j
COPY keycloak-phone-authenticator-yuntongxun-sms/ keycloak-phone-authenticator-yuntongxun-sms/
RUN mvn clean install -f keycloak-phone-authenticator-yuntongxun-sms/

FROM jboss/keycloak:8.0.1
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 cli/ cli/
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 --from=builder /app/keycloak-phone-authenticator/target/classes/theme-resources/templates/ $JBOSS_HOME/themes/base/login/
COPY keycloak-phone-authenticator/messages/ messages/
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
tianxdy commented 4 years ago

Excuse me, I can't run this plug-in, is it because I need to import any resources? Or say the configuration is wrong, may I ask you?

FX-HAO commented 4 years ago

As I mentioned above, you need to implement your own SMS provider implementation and register your libraries using wildfly modules.

Executioner1939 commented 4 years ago

Hi, I am using Keycloak 9.0.2 and had to make the following changes to get rid of the java.lang.NoClassDefFoundError: Failed to link com/hfx/keycloak/spi/ResetCredentialWithPhone exception.

I had to remove:

com.hfx.keycloak.spi.ResetCredentialWithPhone
com.hfx.keycloak.spi.ResetCredentialEmailWithPhone

From the /src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory service file.

I then created two new service files, with names and contents as below:

org.keycloak.authentication.authenticators.resetcred.ResetCredentialChooseUser
    com.hfx.keycloak.spi.ResetCredentialWithPhone
org.keycloak.authentication.authenticators.resetcred.ResetCredentialEmail
    com.hfx.keycloak.spi.ResetCredentialEmailWithPhone

While this fixes the exception mentioned in this issue, I can't seem to get the new flows added, I come from a Scala / SBT background and am not sure how I could fix this.

FX-HAO commented 4 years ago

@Executioner1939 If you remove ResetCredentialWithPhone and ResetCredentialEmailWithPhone, then you can't reset credentials with verification codes. Is this what you want? If so, you just DO NOT update the Reset Credentials authentication flow, nothing needed to be done. Or you just had some problems that caused keycloak unable to start? This library enables you to login with verification codes and reset credentials with verification codes, which requires you to modify Direct Grant Flow and Reset Credentials Under Authentication > Bindings. And they're both optional.

Executioner1939 commented 4 years ago

Yeah, I had to add them back to the org.keycloak.authentication.AuthenticatorFactory. The problems I had were the same as above.

Caused by: java.lang.NoClassDefFoundError: Failed to link com/hfx/keycloak/spi/ResetCredentialWithPhone (Module "deployment.keycloak-phone-authenticator-1.0.0-SNAPSHOT.jar" from Service Module Loader): org/keycloak/authentication/authenticators/resetcred/ResetCredentialChooseUser"}}
FX-HAO commented 4 years ago

Here I added an example shows how to build this into keycloak using docker. https://github.com/FX-HAO/keycloak-phone-authenticator/blob/master/examples/README.md

Executioner1939 commented 4 years ago

@FX-HAO thank you, I have managed to get the code to work with Twilio.

Executioner1939 commented 4 years ago

I think this issue can be closed now.

FX-HAO commented 4 years ago

close since no more information was added