Keycloak - Uma Configuration - keycloak

when a try use keycloak java api im getting this error:
Exception in thread "main" java.lang.RuntimeException: Could not obtain configuration from server [http://localhost:8010/auth//realms/BLKRealm/.well-known/uma-configuration].
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:82)
at org.keycloak.authorization.client.AuthzClient.create(AuthzClient.java:56)
at org.keycloak.authorization.client.AuthzClient.create(AuthzClient.java:49)
at KeyCloackApiCaller.Caller.App.someLibraryMethod(App.java:14)
at KeyCloackApiCaller.Caller.App.main(App.java:26)
Caused by: org.keycloak.authorization.client.util.HttpResponseException: Unexpected response from server: 404 / Not Found
at org.keycloak.authorization.client.util.HttpMethod.execute(HttpMethod.java:92)
at org.keycloak.authorization.client.util.HttpMethodResponse$2.execute(HttpMethodResponse.java:48)
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:80)
... 4 more
This is the code that has generated the error:
import org.keycloak.authorization.client.AuthzClient;
import org.keycloak.representations.AccessTokenResponse;
public class App
{
public static boolean someLibraryMethod() {
AuthzClient authzClient = AuthzClient.create();
// send the authorization request to the server in order to
// obtain an access token granted to the user
AccessTokenResponse response = authzClient.obtainAccessToken("*****", "*****");
return true;
}
public static void main(String[] args)
{
someLibraryMethod();
}
}
I understand this error, but I don't understand why i received this error, realm has UMA enabled, my client is properply configurated. Anyone can help me?

You have used the wrong UMA discovery endpoint. It is uma2-configuration, not uma-configuration (it was valid for some older Keycloak versions):
http://${host}:${port}/auth/realms/${realm}/.well-known/uma2-configuration
Doc: https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_authorization_api

This problem was generated, because i use an outdated api.
To solve this, if you are using maven, set the correct version:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-authz-client</artifactId>
<version>8.0.1</version>
</dependency>
Thank you for all help.

I have the same issue, and problem was, i used wrong auth server url.
keycloak.auth-server-url=http://localhost:8080/auth/
To resolve this, i updated the auth URL to
keycloak.auth-server-url=http://localhost:8080/

Related

HelloWorld using Drools Workbench & KIE Server

Have KIE Drools Workbench 6.2.0 Final installed inside a JBoss 7 Application Server local instance and Kie Server 6.2.0 Final inside a local Tomcat 7 instance.
Using the web based KIE Workbench strictly for evaluation purposes (am using it to code generate Java based Maven projects and am not using a particular IDE such as Eclipse or IntelliJ IDEA):
Created a new repository called testRepo
Created a new project called HelloWorld
Created a new Data Object called HelloWorld with a String property called message:
package demo;
/**
* This class was automatically generated by the data modeler tool.
*/
public class HelloWorld implements java.io.Serializable {
static final long serialVersionUID = 1L;
private java.lang.String message;
public HelloWorld()
{
}
public java.lang.String getMessage()
{
return this.message;
}
public void setMessage(java.lang.String message)
{
this.message = message;
}
public HelloWorld(java.lang.String message)
{
this.message = message;
}
}
Created a new DRL containing the following contents:
package demo;
import demo.HelloWorld;
rule "hello"
when
HelloWorld(message == "Joe");
then
System.out.println("Hello Joe!");
end
When I deploy it to my Kie Server under this URL:
http://localhost:8080/kie-server-6.2.0.Final-webc/services/rest/server/containers/helloworld
I get the following response when I copy and paste the above URL in Google Chrome:
<response type="SUCCESS" msg="Info for container hello">
<kie-container container-id="hello" status="STARTED">
<release-id>
<artifact-id>Hello</artifact-id>
<group-id>demo</group-id>
<version>1.0</version>
</release-id>
<resolved-release-id>
<artifact-id>Hello</artifact-id>
<group-id>demo</group-id>
<version>1.0</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</response>
When I try to do a POST using the following payload (using Postman or SoapUI):
<batch-execution lookup="defaultKieSession">
<insert out-identifier="message" return-object="true" entrypoint="DEFAULT">
<demo.HelloWorld>
<message>Joe</message>
<demo.HelloWorld>
</insert>
Received the following:
HTTP Status 415 - Cannot consume content type
type Status report
message Cannot consume content type
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
What am I possibly doing wrong? I went to Deploy -> Rule Deployments and registered my kie-server along with creating a container called helloworld and as one can see from Step # 5, it worked. Perhaps I am not deploying it correctly?
Btw, I used the following Stack Overflow post as a basis (prior to asking this question)...
Most of the search results from Google just explain how to programmatically create Drools projects by setting up Maven based projects. Am evaluating KIE Drools Workbench to see how easily a non-technical person can use KIE Drools Workbench to generate Drools based rules and execute them.
Am I missing a step? Under Tomcat 7, it only contains the following directories under apache-tomcat-7.0.64/webapps/kie-server-6.2.0.Final-webc:
META-INF
WEB-INF
Thanks for taking the time to read this...
What content type are you using in your POST request header?
As far as I remember, that error message happened if you didn't provide a content-type: application/xml in your request's header.
Hope it helps,
are you ok?
The response of Esteban is right, but, you should add a another header, the header that you need to add is "Authorization", and the value of Authorization is the user that you registered to you application realm to your kie-server converted in base64. e.g.:
kieserver:system*01
converted to base64:
a2llc2VydmVyOnN5c3RlbSowMQ==
Anyway, the complete header of my request is like this:
Authorization : Basic a2llc2VydmVyOnN5c3RlbSowMQ==
Content-Type : application/xml
I hope it was helpful.
Sorry for my english! :)
I got it working with using Postman (Chrome app / plugin) with the Authorization tab selected to No Auth. Really cool response!
<response type="SUCCESS" msg="Container helloworld successfully called.">
<results>
<![CDATA[<execution-results>
<result identifier="message">
<demo.HelloWorld>
<message>Joe</message>
</demo.HelloWorld>
</result>
<fact-handle identifier="message" external-form="0:4:1864164041:1864164041:4:DEFAULT:NON_TRAIT"/>
</execution-results>]]>
</results>
</response>

RMI using spring. Executing method in server with object as parameter

I am trying to execute a method from client to server using RMI.
As long as the parameters are String, it is getting executed correctly. If I am using object as method parameter.
I am getting following exception :
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.lang.ClassNotFoundException: org.eclipse.persistence.exceptions.DatabaseException (no security manager: RMI class loader disabled)
Server configuration:
#Bean
public RmiServiceExporter getUserService() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setService(userService);
exporter.setServiceName("UserService");
exporter.setServiceInterface(UserService.class);
exporter.setRegistryPort(1192);
exporter.setReplaceExistingBinding(true);
return exporter;
}
Client configuration:
public #Bean RmiProxyFactoryBean getUserService() {
RmiProxyFactoryBean rmi = new RmiProxyFactoryBean();
rmi.setServiceInterface(UserService.class);
rmi.setServiceUrl("rmi://localhost:1192/UserService");
return rmi;
}
Test code :
User user = userService.getUser(String userName);
Works perfectly fine.
userService.save(user);
Save user throws RMI exception.
I made sure that the package name for User object in server and client is same. Still I am getting the exception.
Am I missing any configuration? How can I make RMI server to load the other classes?

Log4j Initialization error JBoss RestEasy

I am using JBoss 6.0. I am running a simple webserver using the jboss.resteasy library to provide simple XML responses to HTTP requests.
I have:
- A server
- A simple Java Client that creates a GET request
Now the thing is, if I use the browser to access the URL, I get the wanted XML. But if I use my Java client, which has the following code:
//Register the fake instrument
GetMethod get = new GetMethod("http:/localhost:8080/"+PROJECT_NAME+"/webserver/registerInstrument/?name=FakeClient&value=0");
HttpClient client = new HttpClient();
try {
int status = client.executeMethod(get);
} catch (HttpException e) {
System.out.println("[FakeClient] HttpException executing AddInstrument GET request: "+e);
} catch (IOException e) {
System.out.println("[FakeClient] IOException executing AddInstrument GET request: "+e);
}
Then I get the following exception:
log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.params.DefaultHttpParams).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: Host name may not be null
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:68)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at client.FakeClient.<init>(FakeClient.java:30)
at client.FakeClient.main(FakeClient.java:22)
At first I thought this could be a problem with the JBoss logging, but if I access the URL through the browser, I obtain the desired XML with no problems.
Is this a problem with the Java client application?
Thank you
The 'log4j:WARN' is just a warning. It has nothing do to with the actual exception being thrown.
The exception message states that 'Host name may not be null'. This clearly indicates that there is something wrong the the hostname. And looking at you code, I can spot one error.
You need to add an extra forward slash:
GetMethod get = new GetMethod("http://localhost:8080/" ...

Problem to use GWT client to call a Restlet web service

I am using Restlet framework, and I want to use GWT as the client side. I have already created some ServerResources in Restlet. Here is the codes for the GWT client:
BookResourceProxy.java
public interface BookResourceProxy extends ClientProxy
{
#Get
public void getBooks(Result callback);
}
The class that use this Proxy:
BookResourceProxy wrp = GWT.create(BookResourceProxy.class);
wrp.getClientResource().setReference("/Books");
wrp.getClientResource().getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JSON));
wrp.getBooks(new Result<String>()
{
public void onFailure(Throwable caught)
{
Window.alert("Fail" + caught.getMessage());
}
public void onSuccess(String json)
{
Window.alert(json);
}
});
When I run the application, I always receive the error:
"No source code is available for type org.restlet.resource.ClientProxy; did you forget to inherit a required module?"
But if I inherit it in the .gwt.xml:
Another error occurs:
Unable to find 'org/restlet/Restlet.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 13: Unexpected exception while processing element 'inherits'
Does anybody know why?
Thanks in advance!
Ike
Make sure you are using the GWT edition of Restlet and that org.restlet.jar is in the GWT compiler's classpath.
In GWT side you'll have to use package org.restlet.client.*, on GAE side you use org.reslet.

NameNotFoundException when calling a EJB in Weblogic 10.3

First of all, I'd like to underline that I've already read other posts in StackOverflow (example) with similar questions, but unfortunately I didn't manage to solve this problem with the answers I saw on those posts. I have no intention to repost a question that has already been answered, so if that's the case, I apologize and I'd be thankful to whom points out where the solution is posted.
Here is my question:
I'm trying to deploy an EJB in WebLogic 10.3.2. The purpose is to use a specific WorkManager to execute work produced in the scope of this component.
With this in mind, I've set up a WorkManager (named ResponseTimeReqClass-0) on my WebLogic configuration, using the web-based interface (Environment > Work Managers > New). Here is a screenshot:
Here is my session bean definition and descriptors:
OrquestratorRemote.java
package orquestrator;
import javax.ejb.Remote;
#Remote
public interface OrquestratorRemote {
public void initOrquestrator();
}
OrquestratorBean.java
package orquestrator;
import javax.ejb.Stateless;
import com.siemens.ecustoms.orchestration.eCustomsOrchestrator;
#Stateless(name = "OrquestratorBean", mappedName = "OrquestratorBean")
public class OrquestratorBean implements OrquestratorRemote {
public void initOrquestrator(){
eCustomsOrchestrator orquestrator = new eCustomsOrchestrator();
orquestrator.run();
}
}
META-INF\ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?>
<ejb-jar xmlns='http://java.sun.com/xml/ns/javaee'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
metadata-complete='true'>
<enterprise-beans>
<session>
<ejb-name>OrquestradorEJB</ejb-name>
<mapped-name>OrquestratorBean</mapped-name>
<business-remote>orquestrator.OrquestratorRemote</business-remote>
<ejb-class>orquestrator.OrquestratorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
</ejb-jar>
META-INF\weblogic-ejb-jar.xml
(I've placed work manager configuration in this file, as I've seen on a tutorial on the internet)
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>OrquestratorBean</ejb-name>
<jndi-name>OrquestratorBean</jndi-name>
<dispatch-policy>ResponseTimeReqClass-0</dispatch-policy>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
I've compiled this into a JAR and deployed it on WebLogic, as a library shared by administrative server and all cluster nodes on my solution (it's in "Active" state).
As I've seen in several tutorials and examples, I'm using this code on my application, in order to call the bean:
InitialContext ic = null;
try {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(env);
}
catch(Exception e) {
System.out.println("\n\t Didn't get InitialContext: "+e);
}
//
try {
Object obj = ic.lookup("OrquestratorBean");
OrquestratorRemote remote =(OrquestratorRemote)obj;
System.out.println("\n\n\t++ Remote => "+ remote.getClass());
System.out.println("\n\n\t++ initOrquestrator()");
remote.initOrquestrator();
}
catch(Exception e) {
System.out.println("\n\n\t WorkManager Exception => "+ e);
e.printStackTrace();
}
Unfortunately, this don't work. It throws an exception on runtime, as follows:
WorkManager Exception =>
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '' [Root exception is
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '']; remaining name
'OrquestratorBean'
After seeing this, I've even tried changing this line
Object obj = ic.lookup("OrquestratorBean");
to this:
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorBean");
but the result was the same runtime exception.
Can anyone please help me detecting what am I doing wrong here? I'm having a bad time debugging this, as I don't know how to check out what may be causing this issue...
Thanks in advance for your patience and help.
Your EJB gets bound under the following JNDI name (when deployed as EJB module):
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorRemote");
Note that I deployed your code (without the weblogic-ejb-jar.xml) as an EJB module, not as a shared library.
seems like your mapped-name in ejb-jar.xml "Orquestrator" may be overriding the mappedName=OrquestratorBean setting of the Bean.
Have you tried ic.lookup for "Orquestrator" ?