[keycloak-user] Provider Dependencies
Ataraxus
atx at binaryninja.de
Mon Nov 23 08:44:29 EST 2015
Hello Erik, Hey Stian,
thanks for clarification. I tried as suggested in the keycloak
documentation, but somehow it didn't worked :(
I'm deploying it by dropping the jar into the providers folder and
restarting jboss.
How can i verify if it was loaded as a module? I'm using EAP 6.4 Overlay
btw.
This is the content of my .jar
MYAPP.authenticator
├── META-INF
│ ├── MANIFEST.MF
│ ├── maven
│ │ └── de.MYAPP.auth
│ │ └── MYAPP.authenticator
│ │ ├── pom.properties
│ │ └── pom.xml
│ └── services
│ └── org.keycloak.authentication.AuthenticatorFactory
├── de
│ └── MYAPP
│ └── auth
│ └── authenticator
│ ├── MYAPPEmailAuthenticator.class
│ ├── MYAPPEmailAuthenticatorFactory.class
│ ├── MYAPPSAPAuthenticator.class
│ ├── MYAPPSAPAuthenticatorFactory.class
│ └── beans
│ └── ProfileBean.class
└── modules
└── de
└── MYAPP
└── auth
└── authenticator
└── module.xml
module.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="de.MYAPP.auth.authenticator">
<resources>
<resource-root path="MYAPP.authenticator.jar"/>
</resources>
<dependencies>
<module name="org.keycloak.keycloak-core"/>
<module name="org.keycloak.keycloak-model-api"/>
<module name="org.keycloak.keycloak-events-api"/>
<module name="org.keycloak.keycloak-services"/>
<module name="org.keycloak.keycloak-services"/>
<module name="org.keycloak.keycloak-login-api"/>
<module name="org.jboss.logging.jboss-logging"/>
<module name="javax.mail.mail"/>
</dependencies>
</module>
Am 23.11.15 um 14:18 schrieb Stian Thorgersen:
> Just look at Keycloak documentation:
> http://keycloak.github.io/docs/userguide/keycloak-server/html/providers.html#d4e458
>
> On 23 November 2015 at 14:07, Erik Mulder
> <erik.mulder at docdatapayments.com
> <mailto:erik.mulder at 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 at binaryninja.de> <mailto:atx at binaryninja.de>
> *To:*"ewjmulder at yahoo.com" <mailto:ewjmulder at yahoo.com>
> <ewjmulder at yahoo.com> <mailto:ewjmulder at 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 list
>> keycloak-user at lists.jboss.org
>> <mailto:keycloak-user at lists.jboss.org>
>> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20151123/88683a23/attachment-0001.html
More information about the keycloak-user
mailing list