Why won't the Keycloak with Spring Boot tutorial work? - keycloak

I've been trying to follow the Keycloak tutorial from DZone (EDIT: which seems to be a nearly verbatim repost from the tutorial on the official Keycloak blog, apparently by the same author), but I've run into the following problems:
index.html not being found
when clicking on the link to the interior page, the error
We're sorry...
Page not found
on that same page, the error
javax.servlet.ServletException: Circular view path [products]: would dispatch back to the current handler URL [/products] again.
the Keycloak admin panel appearing instead of the sample app
What am I doing wrong?

There are a number of subtle but significant inconsistencies/typos in that tutorial. In order of appearance:
Main tutorial
the location of index.html is given as /src/resources/static. If you are using Spring Initializr, the pre-made code will have both main and test directories under src, so the correct location will instead be src/main/resources/static.
In the code for the controller, line 9 is
return "products";
This tells Spring to use products.html. The actual HTML file will be product, singular, because it is generated from product.ftl. Take the 's' off of the return value.
In the application.properties file, one of the lines given is
keycloak.realm=springboot
Earlier, when in the Keycloak admin panel, the guide suggested naming the realm "SpringBoot". These values need to match, and they are case-sensitive. Change either one.
After setup is complete, the instructions say
Now browse to “http://localhost:8080”
The correct URL is http://localhost:8081, since server.port was set to 8081 in application.properties. Port 8080 should still be in use by the admin console.
With these changes, the test app should load and behave as described.
Adding Spring Security
Be careful not to reintroduce the products/product typo when copying in the new getProducts() method.

Nowadays, to make the official documentation work, you can use the answer from SOLO and complement with the following code:
Add keycloak to POM
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
Add dependency management to POM
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>10.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Change .ftl format to .ftlh and use like this:
<html>
<h2>My products</h2>
<ul>
<#list products as product>
<li>${product}</li>
</#list>
</ul>
<p>
Logout
</p>

Related

What is the use of org.apache.struts.chain.ComposableRequestProcessor in struts and java.nio.charset.IllegalCharsetNameException

We ran into a migration issue where in we are migrating an application from JBoss 4.2.1.GA to JBoss EAP 7.0.0.GA. The exception encountered is as below.
java.lang.RuntimeException: java.nio.charset.IllegalCharsetNameException:
at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:226)
So we have a fix for the same which involves
Adding the below in the struts config.xml file.
this line in config
<controller processorClass="org.apache.struts.chain.ComposableRequestProcessor"
locale="true" nocache="false" contentType="text/html; charset= UTF8">
<set-property property="maxFileSize" value="7M"/>
</controller>
has been changes to
tag from charset= UTF8 to charset= ISO-8859-1"
and an additional property
This has resolved the issue but wants to know what is the proper use of class ComposableRequestProcessor. And why it is helping our solution here.
We don't see a proper document or blog on the net explaining why and when we need to add this configration. What is the advantage of doing so?
Also, we want to know JBoss 4.2.1.GA the page-context encoding was not enforced but in JBoss EAP 7.0.0.GA we need to define it as ISO else it won't work in windows server environment.
We know it has to do with some Undertow implementation over the earlier Apache Tomcat HTTPs implementation framework used by JBoss.
Any help by pointing to right document or information is widely appreciated.

Unexpected element '{urn:jboss:domain:keycloak:1.0}subsystem

Happy New Year to all.
I have a keycloak/wildfly question.
I am attempting to secure my war for WildFly 9.0.2.Final deployment. I follow the directions in section 7.2.1 of http://docs.jboss.org/keycloak/docs/1.0.4.Final/userguide/pdf/keycloak-reference-guide-en-US.pdf
I get the error Unexpected element '{urn:jboss:domain:keycloak:1.0}subsystem
I have carefully followed each step as listed below.
cd $WILDFLY_HOME
unzip keycloak-wildfly-adapter-dist.zip
edit the standalone.xml and add the following:
<server xmlns="urn:jboss:domain:1.4">
<extensions>
<extension module="org.keycloak.keycloak-wildfly-subsystem"/>
...
</extensions>
<profile>
<subsystem xmlns="urn:jboss:domain:keycloak:1.0"/>
...
</profile>
It is the line subsystem xmlns="urn:jboss:domain:keycloak:1.0 that is flagged in the error.
What am I missing? Thank you in advance.
May be it's a little bit too late. I think the problem could be that you forget to merge modules, bins folder from key-cloak into Jboss, so that the container itself doesn't recognize the keycloak.

wso2is custom authenticationendpoint, redirect page not used

I am developing saml sso using wso2is. I customized the authentication endpoint according the blog post below 1. Basically I just deployed a war on my server and configured application-authenticators.xml to use it:
<Authenticators>
<Authenticator name="BasicAuthenticator" disabled="false" factor="1">
<!-- <Status value="10" loginPage="/authenticationendpoint/login.do" /> -->
<Status value="10" loginPage="https://servlet.example.com/customlogin/login.do" />
</Authenticator>
</Authenticators>
login is working fine, my custom login-page sends a form to "https://servlet.example.com/idp/commonauth" which redirects me to my sp. but I also want to customize the redirect-page after the login. in the custom endpoint there is a file named 'samlsso_redirect.jsp' which looks like it should do the work but its contents are ignored.
strangely 'samlsso_redirect.jsp' the the bundled authentication endpoint is also ignored.
I have also downloaded the sources of wso2is and found org.wso2.carbon.identity.sso.saml.servlet.SAMLSSOProviderServlet hard codes the redirect message in the sendResponse() method.
Does somebody know how it is working and what I am missing here? How can I customize the redirect message?
http://dulanja.blogspot.sk/2014/01/wso2-is-samlsso-customizing-login-page.html
If you are using WSO2IS 5.0.0 version or higher version, You can simplify edit html file which can be found at IS_HOME\repository\resources\security\sso_redirect.html
Following applies to WSO2IS 4.6.0 and older versions
It seems to be that redirect page is can not be customized by using some extension. Please see this jira
However You can do as following if you want to customize it in 4.6.0...
svn checkout https://svn.wso2.org/repos/wso2/carbon/platform/branches/turing/components/identity/org.wso2.carbon.identity.sso.saml/4.2.2
In src/main/java/org/wso2/carbon/identity/sso/saml/servlet/SAMLSSOProviderServlet.java you have to modify the HTML getting printed in sendResponse() method.
Build the component using maven and place as a patch in wso2is-4.6.0/repository/components/patches. Copy jar file into any patch directory
Restart the server
note : The built jar name appears as: org.wso2.carbon.identity.sso.saml-4.2.2.jar. Make sure to rename it to org.wso2.carbon.identity.sso.saml_4.2.2.jar (notice that the dash is replaced by an underscore) before placing in the patch folder.
If you are using IS 5.0 then you need to modify this page:
IS_HOME\repository\resources\security\sso_redirect.html

How to get a stable release of Spring Batch Admin

Here is what I've tried from their getting started page...
The SpringSource Community Download links to a page that has no mention of Spring Batch Admin. Looks like the original link is either dead or now redirects to something else.
I get connection timeouts for the S3Browse App link
The source building process just fails and every fix leads to a new failure. Started with missing artifacts/repositories and now looks to be related to Maven 3 vs Maven 2?
The maven build process seems to pull down a jar instead of a war
Google searches for download links keep referring me back to this page. What am I missing? There has to be some publicly available download page with prebuilts .war somewhere.
If you're looking to just test drive the app as I was, you can follow these steps:
Check out the source from github at https://github.com/spring-projects/spring-batch-admin. Next step is to go to the spring-batch-admin-sample directory and use maven/jetty to run it.
mvn jetty:run
Now in your browser, go to:
http://localhost:8080/spring-batch-admin-sample
My guess is documentation wasn't all updated (sigh).
SNAPSHOT builds aren't something that should be used somewhere serious, apart from no-other-way-out situations. Try either 1.2.2.RELEASE (not on github somewhy) or 1.2.1.RELEASE.
http://mvnrepository.com/artifact/org.springframework.batch/spring-batch-admin-manager/1.2.2.RELEASE
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-admin-manager</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
https://github.com/spring-projects/spring-batch-admin/releases
Disclaimer - too lazy to try it out myself.

GWTTestCase invocation causing ReferenceError

Case
i'm trying to write a GWTTestCase for a certain class, used as a presenter for a history-browsing toolbar component i'm building.
Problem
one (or more) of the scripts apparently not being loaded for the jUnit testing environment. it all works fine when running the application (development mode), but when i try to run the test case, the application (web server as well as user agent) fails to load, and the following exception arouses (stacktrace is shortened for simplicity):
com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxFunction_write at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:499) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595) ... 41 more
...
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "Raphael" is not defined. (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/dracula/dracula_graffle.js#18) (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/com.gigaspaces.admin.webui.Gs_webui.JUnit.nocache.js#16) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)
Relevant sources
here is the (ridiculously simple) GWTTestCase used:
public class HistoryBrowserTest extends GWTTestCase {
#Override
public String getModuleName() {
return "com.gigaspaces.admin.webui.Gs_webui";
}
public void testHistoryBrowser() {
assertTrue(true);
}
}
Dependencies / context information
jUnit 4.10 is used as an external jar - and referenced successfully by the classpath and the .gwt.xml file is inheriting jUnit from GWT (<inherits name="com.google.gwt.junit.JUnit" />) the jUnit module is no longer inherited as the GWT team instructs not to - extending GWTTestCase will inherit it automatically.
i am using Raphael-GWT as a separate module. this module is also referenced in the main module's .gwt.xml file, and running fine under all other circumstances (development / production mode).
What have i tried
simplifying the case, e.g. stripping down the test case as seen above.
verifying inherited modules in the deployment descriptors.
varying jUnit's version, i.e. running both under V3 or V4, and manually compiled on each change.
looked up on google, as well as here on stackoverflow, with no avail.
More relevant information
Raphael lib is being used for a GWT wrapper i wrote for Dracula (a JS graph visualization library) so dracula_graffle.js originates there. enclosed is the .gwt.xml file source for a reference:
<module rename-to="gs_webui">
<inherits name="com.google.gwt.user.User" />
<!-- Other module inherits -->
<inherits name="com.extjs.gxt.ui.GXT" />
<inherits name="org.highchartsgwt.HighCharts" />
<inherits name="gwtupload.GWTUpload" />
<inherits name="com.hydro4ge.raphaelgwt.RaphaelGWT" />
<inherits name="com.gigaspaces.gauge.Gs_gauges" />
<inherits name="com.gigaspaces.graphs.Gs_graphs" />
<inherits name="com.gigaspaces.svgcomponents.Gs_svg_components" />
<inherits name="com.javaconstructors.colorpalette.Color_palette" />
<inherits name="com.gigaspaces.jquerywidgets.Gs_jquery_widgets" />
<inherits name="com.gigaspaces.codemirror_gwt.CodeMirror_GWT"/>
<inherits name="com.google.gwt.i18n.I18N"/>
<inherits name="com.google.gwt.query.Query" />
<!-- I18N stuff, log configurations, and so forth... -->
<entry-point class="com.gigaspaces.admin.webui.client.Gs_webui" />
<!-- further source folder inherits... -->
</module>
How is Raphael loaded? It could be that the js file is never being pulled in to the html page being run in htmlunit.
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "Raphael" is not defined. (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/dracula/dracula_graffle.js#18) (http://192.168.10.32:3692/com.gigaspaces.admin.webui.Gs_webui.JUnit/com.gigaspaces.admin.webui.Gs_webui.JUnit.nocache.js#16)
This file doesn't appear to be used by RaphaelGWT, as it is not listed in their module file (seen here http://code.google.com/p/raphaelgwt/source/browse/trunk/src/com/hydro4ge/raphaelgwt/RaphaelGWT.gwt.xml).
This seems to be the source of your error - dracula_graffle.js (either line 18, or this is the 18th file loaded) cannot find the symbol Raphael, and since it is somehow required by your module, the app (in this case test) can't load without it. My quick guess is that it is either an HtmlUnit issue (HtmlUnit is what the gwt test cases run in, and only simulates a real browser) - you might try running this same test in a real browser, see http://code.google.com/webtoolkit/doc/latest/DevGuideTesting.html#Manual_Mode for more info. If that fails, then perhaps your app normally loads into an html page where some JS files have already been loaded, so this doesnt happen - those need to be loaded when testing the app as well, either using ScriptInjector in a setup method, or by adding them to your module file.
(After edits, comments)
Since the error occurred in manual mode as well, there isn't an error with htmlunit, but with dependencies in your code. From what appears to be a copy of dracula_graffle.js at http://code.google.com/p/synoptic/source/browse/synopticgwt/war/dracula_graffle.js?spec=svn2164f4b075bb0ed77f7b008bd113e04831196fec&r=2164f4b075bb0ed77f7b008bd113e04831196fec, line 18 is the first reference to Raphael, which should have defined when the raphael js file was loaded, which implies that it wasn't.
Running in manual mode with Firebug or the like running should show you an error in the console. Based on this, I think it is safe to say that something is different about the test case than the standard entrypoint+html page. The question is, what is different.
Are there any JS files, or script tags that run when the html page loads? GWTTestCases always run with just a very simple html page, and only load scripts defined in the module that you actually name in your .gwt.xml file. Are there any setup functions that are run as part of the entrypoint? Have you tried making a new, very simple html page, and writing a new, very simple EntryPoint for the module and using that instead? In the course of testing these things, I believe you will find some difference that is important in how your app works from how your test works.
If there isn't... the next annoying step is to run in manual mode again, with your app compiled in production model (see the same link, it should give details on how that might be done). Set firebug (or whatever tool you prefer) to stop on exceptions in Js, or simple set a breakpoint on line 18, when Raphael is used for the first time in dracula_graffle.js to see what scripts have loaded, and why Raphael isn't yet defined.