Just look at Keycloak documentation:
http://keycloak.github.io/docs/userguide/keycloak-server/html/providers.h...
On 23 November 2015 at 14:07, Erik Mulder <erik.mulder(a)docdatapayments.com>
wrote:
Hi Ataraxus,
I think the way to solve this is 'tapping in' to the Wildfly module
system. You need to add a module.xml to your provider jar under
src/main/resources/modules/some/module/name/module.xml and include a
reference to the java mail api there. That way you can tell Wildfly to
include that on the classpath when it's loading your provider classes.
I'm sorry, but I'm not sure how exactly this works in detail with path
names and module.xml contents. You can look at the keycloak sources for
module.xml examples, read the Wildfly module system documentation or maybe
someone else on the mailing list can answer you in more detail. Good luck!
------------------------------
*From:* Ataraxus <atx(a)binaryninja.de> <atx(a)binaryninja.de>
*To:* "ewjmulder(a)yahoo.com" <ewjmulder(a)yahoo.com>
<ewjmulder(a)yahoo.com>
<ewjmulder(a)yahoo.com>
*Sent:* Monday, November 23, 2015 1:57 PM
*Subject:* Re: [keycloak-user] Provider Dependencies
Here is the code and the stacktrace just in case, maybe there is a better
way to send email:
private void send(UserModel user, AuthenticationFlowContext context,
String subject, String textBody, String htmlBody) throws EmailException {
try {
String address = user.getEmail();
Map<String, String> config =
context.getRealm().getSmtpConfig();
Properties props = new Properties();
props.setProperty("mail.smtp.host", config.get("host"));
boolean auth = "true".equals(config.get("auth"));
boolean ssl = "true".equals(config.get("ssl"));
boolean starttls =
"true".equals(config.get("starttls"));
if (config.containsKey("port")) {
props.setProperty("mail.smtp.port",
config.get("port"));
}
if (auth) {
props.put("mail.smtp.auth", "true");
}
if (ssl) {
props.put("mail.smtp.socketFactory.port",
config.get("port"));
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
}
if (starttls) {
props.put("mail.smtp.starttls.enable", "true");
}
String from = config.get("from");
Session session = Session.getInstance(props);
Multipart multipart = new MimeMultipart("alternative");
if (textBody != null) {
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(textBody, "UTF-8");
multipart.addBodyPart(textPart);
}
if (htmlBody != null) {
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody, "text/html; charset=UTF-8");
multipart.addBodyPart(htmlPart);
}
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setHeader("To", address);
msg.setSubject(subject);
msg.setContent(multipart);
msg.saveChanges();
msg.setSentDate(new Date());
Transport transport = session.getTransport("smtp");
if (auth) {
transport.connect(config.get("user"),
config.get("password"));
} else {
transport.connect();
}
transport.sendMessage(msg, new InternetAddress[]{new
InternetAddress(address)});
} catch (Exception e) {
throw new EmailException(e);
}
}
connect/auth
JBWEB000309: type JBWEB000066: Exception report
JBWEB000068: message request path:
/auth/realms/MYAPP/protocol/openid-connect/auth
JBWEB000069: description JBWEB000145: The server encountered an internal
error that prevented it from fulfilling this request.
JBWEB000070: exception
java.lang.RuntimeException: request path:
/auth/realms/MYAPP/protocol/openid-connect/auth
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:75)
JBWEB000071: root cause
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError:
javax/mail/Multipart
org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:364)
org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:232)
org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:208)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:556)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)
JBWEB000071: root cause
java.lang.NoClassDefFoundError: javax/mail/Multipart
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:27)
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:19)
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:124)
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:97)
org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:650)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.browserAuthentication(AuthorizationEndpoint.java:315)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:265)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:123)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168)
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:158)
org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:106)
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:153)
org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:91)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)
JBWEB000071: root cause
java.lang.ClassNotFoundException: javax.mail.Multipart
java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java.net.URLClassLoader$1.run(URLClassLoader.java:355)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
java.lang.ClassLoader.loadClass(ClassLoader.java:425)
java.lang.ClassLoader.loadClass(ClassLoader.java:358)
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:27)
de.MYAPP.auth.authenticator.MYAPPEmailAuthenticatorFactory.create(MYAPPEmailAuthenticatorFactory.java:19)
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:124)
org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:97)
org.keycloak.authentication.AuthenticationProcessor.authenticate(AuthenticationProcessor.java:650)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.browserAuthentication(AuthorizationEndpoint.java:315)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.buildAuthorizationCodeAuthorizationResponse(AuthorizationEndpoint.java:265)
org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint.build(AuthorizationEndpoint.java:123)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168)
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:158)
org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:106)
org.jboss.resteasy.core.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:153)
org.jboss.resteasy.core.ResourceLocator.invoke(ResourceLocator.java:91)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)
Am 23.11.15 um 13:32 schrieb Ataraxus:
Hey,
I'm writing my custum login provider which works great so far, but i
stumbled upon a dependency issue:
I wan't to use mail in my authenticator, but when the authenticator gets
actually loaded I get an class not found exception.
Somehow is java.mail.* not available in the classpath of providers which
are dropped in the configuration/providers path.
How can i use these dependencies? I could include them into my jar, but
i guess thats not the "right" way.
Thanks
_______________________________________________
keycloak-user mailing
listkeycloak-user@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/keycloak-user