Custom JWT Generation Gives Exception in WSO2 3.2.0 - jwt

I’m trying to add custom roles to the existing JWT token by using CustomGatewayJWTGenerator as described here:
https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/passing-end-user-attributes-to-the-backend/passing-enduser-attributes-to-the-backend-using-jwt/
But unfortunately I’m getting a nullpointer error as shown below (wso2am-3.2.0):
java.lang.NullPointerException: null
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.generateAndRetrieveJWTToken_aroundBody2(JWTValidator.java:214) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.generateAndRetrieveJWTToken(JWTValidator.java:195) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.authenticate_aroundBody0(JWTValidator.java:181) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.jwt.JWTValidator.authenticate(JWTValidator.java:111) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
at org.wso2.carbon.apimgt.gateway.handlers.security.oauth.OAuthAuthenticator.authenticate_aroundBody4(OAuthAuthenticator.java:300) ~[org.wso2.carbon.apimgt.gateway_6.7.206.jar:?]
Also here is my relevant enabled attributes in the deployment.toml
[apim.jwt]
enable = true
[apim.jwt.gateway_generator]
impl = "org.wso2.carbon.test.CustomGatewayJWTGenerator"
Thanks

As per the shared information, the built JAR artifact has been placed inside the <apim>/repository/components/lib directory.
Perform the following steps to overcome the behavior
Go to <apim>/repository/components/lib directory and remove the custom JWT Generator JAR
Move to <apim>/repository/components/dropins directory and remove the custom JWT Generator bundle JAR (this is an OSGi bundle that is created during the startup for the JAR that is placed under the /lib directory)
Place the built JAR artifact only inside the <apim>/repository/components/dropins and restart the API Manager server
After restart, try invoking the API.

Related

keycloak 8.0.1 , example app-authz-photoz failing on "import a resource server configuration"

I am using keycloak 8.0.1, and trying one of the examples. While following the README for the steps in
.\keycloakExample\keycloak-quickstarts-latest\app-authz-photoz
This step:
import a resource server configuration. Now select the file that is located at:
keycloak-quickstarts/app-authz-photoz/photoz-restful-api/target/classes/photoz-restful-api-authz-service.json
results in:
ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-16) Uncaught server error: java.lang.RuntimeException: Error while importing policy [Only Owner and Administrators Policy].
at org.keycloak.models.utils.RepresentationToModel.importPolicies(RepresentationToModel.java:2220)
at org.keycloak.models.utils.RepresentationToModel.toModel(RepresentationToModel.java:2180)
at org.keycloak.authorization.admin.ResourceServerService.importSettings(ResourceServerService.java:136)
Additionally, the steps say:
Now click Upload and the resource server will be updated accordingly.
There is not an Upload button, and there is an additional error:
RuntimeException: Script upload is disabled
at org.keycloak.authorization.policy.provider.js.JSPolicyProviderFactory.updatePolicy(JSPolicyProviderFactory.java:125)
==
This makes me think something in the configuration is not enabling this "upload button", so it isn't rendered, and the "import" button performs an script that tries to do an "upload"
Versions I am using:
"Ubuntu"
VERSION is "18.04.1 LTS (Bionic Beaver)"
openjdk version "1.8.0_242"
The reason is JavascriptPolicies are no longer enabled by default in Keycloak for security reasons. You have two options on how to solve this. Either you can enable UPLOAD_SCRIPTS feature with (-Dkeycloak.profile.feature.upload_scripts=enabled), or you can use a new Javascript provider. The later is preferred and more secure.
edit: In the latest version of the quickstart repository, this issue should be fixed (upload script JS policies are replaced with deployed policies).

How to read external config file when starting a bundle jboss fuse karaf

The problem is simple: i want to print all topics from apache kafka after installing kafka module on karaf. I need to get properties from cfg file which is located in jbossfuse/etc and create a KafkaConsumer object. I want to implement BundleActivator to be able to start method in the moment of installation module.
The question is: how can i get properties from the config file?
I found some solution here: some solution, they said " you can use ConfigAdimn service from OSGi spec. ". How can i use it? All examples with the code are welcome
Karaf uses Felix-FileInstall to read config files: http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html
So if there is a file named kafka.cfg, it will pick it up and register a config with the ConfigAdmin-Service under the pid 'kafka'.
You can fetch the ConfigAdmin-Service and fetch the config using an Activator and read that config from there, but I strongly recommend to use DeclarativeServices or Blueprint instead to interact with the OSGi-Framework, both support injection of configuration if it is available.
Because otherwise you have to deal yourself with the following topics:
there is no ConfigAdmin (yet), maybe because your bundle starts earlier)
the ConfigAdmin changes (for example due to a package refresh or update)
the configuration is not yet registered (because felix has not read it yet)
the configuration gets updated (for example somone changes the file)

Why is Talend giving ClassNotFoundException for SQLServerDriver

I've installed Talend ESB 6.5.1 and am trying to connect to a SQL Server database.
I tried using the JTDS driver, but that didn't work, and it appeared that I needed a DLL that wasn't included in the , and do I installed the pure java MS driver instead.
Talend has put the MS driver into Studio\workspace\xxx\temp\dbWizard having renamed it, but when I try to use it I get
Database connection is failed.
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.talend.core.model.metadata.builder.database.JDBCDriverLoader.getConnection(JDBCDriverLoader.java:195)
...
It looks like Talend has put the jdbc driver somewhere, but it not referencing it correctly.
Any ideas what I need to do to get Talend to find it? (I've looked inside the .jar file and the class is definitely there.)
(Taking the generated JDBC URL and using this directly in a tJDBCInput with the driver jar selected works fine... bizarre)
The location where your jar was put does not look familiar. Try deleting all the jtds jar versions in the following locations :
<Talend root folder>\configuration\.m2\repository\org\talend\libraries
<Talend root folder>\lib\java
And restart your studio. When you go back to your component, you'll see an install button. You should be able to download and install the jar.

trouble with service reference

I added a service reference that points to http://api.microsofttranslator.com/V1/soap.svc in my project. After adding the reference an app.config file was created.
When I run the project everything works. After creating a setup file with Advanced Installer (program for authoring Windows Installer setup packages) I get the following error message when I run the installed program.
"Could not find default endpoint element that references contract TranslatorService.LanguageService in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
Can someone help?
This problem is not generated by the setup package created with Advanced Installer, it seems to be .NET specific. Here is another similar thread: Microsoft translator error

Enterprise lib 5.0 not detecting app.config

I have a Solution which contains a Web project and a Class Library project. The Class library project contains Enterprise library 5.0 and app.config. When I try to perform a Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write, I get the following exception:
Resolution of the dependency failed,
type =
"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter",
name = "(none)". Exception occurred
while: while resolving. Exception is:
InvalidOperationException - The type
LogWriter cannot be constructed. You
must configure the container to supply
this value.
----------------------------------------------- At the time of the exception, the
container was: Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
If I move all the class files to the web project and have the Enterprise library configuration in the Web.config, everything works fine. I guess the issue is that the Enterprise library is not detecting the app.config which contains all the configuration.
Kindly help me with this regard.
Thanks in advance.
.NET dlls don't have config files. AppDomains do. You cannot put any configuration in a dll's "app.config" file and expect it to get automatically picked up. This is the way .NET config files work; it's not that "entlib is not automatically detecting" it, it's doing what the .NET framework defines the behavior of config files to be.
The answer is to leave the code in the library, but put the configuration in the web app's web.config file. Then everything will just work.
There are more advanced things you can do like manually loading the config file, but they're fairly advanced and, particularly with logging, can cause admin headaches later.