DBLookup parameter values as registry entries doesn't work - wso2

WSO2 EI 6.3.0
DBLookup parameter values as registry entries are evaluate like literal. I read https://docs.wso2.com/display/EI630/DBLookup+Mediator but is not working for me.
Me dblookup configuration
<dblookup description="Checking historical">
<connection>
<pool>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>jdbc:sqlserver://localhost:1433;databasename=test</url>
<user>conf:/custom/config.xml/database/user</user>
<password>somepass</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM someTable]]></sql>
</statement>
</dblookup>
and the exception
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Login failed for user 'conf:/custom/config.xml/database/user'

The username which you are using will not work for the reason .
<user>conf:/custom/config.xml/database/user</user>
The user field tries to read the value saved in a file, here you are reading from config.xml however and later you are providing relative path in the .xml ,hence it will not work.
I would suggest that you save the username in a registry file and then access the user name, that should work.

Related

WSO2IS - Disable Embedded LDAP - deployment.toml

How can I disable Embedded Ldap on Identity Server 5.10.0 version? I'm checking conf/identity/embedded-ldap.xml and enable property is true.
<EmbeddedLDAP>
<Property name="enable">true</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
I couldn't find how I can disable. If I overwrite this file when docker starts it came back to true.
If you have <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file and it's enable property value under <EmbeddedLDAP> is templated as {{embedded_ldap.enable}} (shown below),
<EmbeddedLDAP>
<Property name="enable">{{embedded_ldap.enable}}</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
</EmbeddedLDAP>
you can use the following deployment.toml config
[embedded_ldap]
enable = false
If the <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file contains the EmbeddedLDAP config's enable property value as hardcoded to "true", you can change it to false and restat the server to change the config in embedded-ldap.xml.
<EmbeddedLDAP>
<Property name="enable">true</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
</EmbeddedLDAP>
If you don't have <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file, the property value changes in embedded-ldap.xml won't be replaced once the server is restarted.
In WSO2 Identity Server 5.10.0 the configurations are managed by a centralized toml file which is called as deployment.toml. We can add the following configuration to the deployment.toml file which is located in <IS_HOME>/repository/conf directory.
[embedded_ldap]
enable = false
In WSO2 Identity Server 5.10.0 version the file embedded-ldap.xml.j2 doesn't come inside
wso2is-5.10.0/repository/resources/conf/templates/repository/conf/identity so I needed to copy the file from this link: embedded-ldap.xml.j2 and put inside my configuration for docker container conf/is-as-km/repository/resources/conf/templates/repository/conf/identity
docker-compose.yml
...
volumes:
- ./conf/is-as-km:/home/wso2carbon/wso2-config-volume
ports:
- "9444:9443"
...
After that I put the property in deployment.toml:
[embedded_ldap]
enable = false
And everything worked as shown in docker log:
cup-is-as-km ... NFO {org.wso2.carbon.identity.oauth.uma...} - UMA Grant component activated successfully.
cup-is-as-km ... INFO {org.wso2.carbon.ldap.server.DirectoryActivator} - Embedded LDAP is disabled.
cup-is-as-km ... INFO {org.wso2.carbon.mex.internal.Of...} - Office365Support MexServiceComponent bundle activated successfully..
Based on the last answers and comments I reached the solution ;).

Passing a custom authorization token to the backend in WSO2 is not giving the expected result

I am using WSO2 APIM-2.6.0 and I would like to pass a custom token. For which I have used a token exchange mechanism in mediation Policies, In flow. As per the instructions provided on WSO2 documentation from the below link,
https://apim.docs.wso2.com/en/latest/Learn/APIGateway/MessageMediation/passing-a-custom-authorization-token-to-the-backend/
Token exchange xml used,
<sequence xmlns="http://ws.apache.org/ns/synapse" name="TokenExchange">
<property name="Custom" expression="get-property('transport', 'Custom')"/>
<property name="Authorization" expression="get-property('Custom')" scope="transport"/>
<property name="Custom" scope="transport" action="remove"/>
</sequence>
On the management console of API Store when I provide the existing bearer token in the header parameter and when I execute, the response is,
TypeError: Failed to fetch
Code: 200
But, when I copy the same curl command from API Store UI and run through command prompt, it gives the response and it works fine. How can I fix this?

save a dynamic value in wso2 esb for next use

i need to save result of web service login method as a property in wso2 esb. and use it whenever i want. token will be expired in 20 min so i want to save token in wso2 esb and when it expire regenerate it. how can i save a property dynamic in wso2 esb and retrieve it. my sequence to generate tokekn is :
<sequence name="x" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<p:login xmlns:p="http://corebankingservice.endpoint.webservicegateway.core.channelmanager.caspian.com/">
<chUserInfoRequestBean xmlns="">
<password>****</password>
<username>user</username>
</chUserInfoRequestBean>
<channelServiceType xmlns="">***</channelServiceType>
</p:login>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="http://x.x.x.x:8280/services/..."/>
</endpoint>
</send>
</property name="SessionId" value = ...>
</sequence>
result of this sequence is SessionId so i need to save SessionId in memory or db or .... and use it for another method until it will be expired. how can i save such a this property in registery or cashe or database and use it later.
The only "official" way I know (which I used), is to use the dblookup mediator (retrieve the value later) and dbreport meditaor (to store the value) in a database.
Write value to a db:
<dbreport>
<connection>
<pool>
<dsName>datasource_name</dsName>
</pool>
</connection>
<statement>
<sql>
insert into table (attributName1, attributName2) values ('value1','value2')</sql>
</statement>
</dbreport>
The values can be passed from a property like in this example.
<sql>
insert into dbo.sais_config_db (serviceName, configKey, configValue) values ('staticVal1','staticVal2',?)</sql>
<parameter expression="get-property('myPropertyName')" type="CHAR"/>
Read value:
<dblookup>
<connection>
<pool>
<dsName>sais_config_db</dsName>
</pool>
</connection>
<statement>
<sql>
SELECT value1 FROM tableName where ....</sql>
<result name="resultFromDb" column="value1"/>
</statement>
</dblookup>
Hope that helps. There is another option, but I don't know if that works (haven't tried it).
Link
With WSO2 Enterprise Integrator 6.x.x and up, it's possible to set a property with scope "registry" that will persist the value between calls and being globally visible.
For example to persist the access token received in the JSON response:
<property description="propAccessToken" expression="json-eval($.access_token)" name="access_token" scope="registry" type="STRING"/>
Then to get the property use the following expression:
get-property('registry', 'access_token')

wso2 esb sequence DB update

I have a problem with the DBreport mediator which output a syntax error, but I can't see any error in the SQL statement
<sequence xmlns="http://ws.apache.org/ns/synapse" name="_dbcount">
<dblookup>
<connection>
<pool>
<password>1234</password>
<user>root</user>
<url>jdbc:mysql://localhost:3306/new_db</url>
<driver>com.mysql.jdbc.Driver</driver>
</pool>
</connection>
<statement>
<sql>
<![CDATA[ select * from consume where username= ? and id_api+ ?]]></sql>
<parameter value="riccardo" type="VARCHAR" />
<parameter value="1" type="INTEGER" />
<result name="result_use" column="use" />
<result name="result_user" column="username" />
</statement>
</dblookup>
<dbreport>
<connection>
<pool>
<password>1234</password>
<user>root</user>
<url>jdbc:mysql://localhost:3306/new_db</url>
<driver>com.mysql.jdbc.Driver</driver>
<property name="autocommit" value="false" />
</pool>
</connection>
<statement>
<sql>
<![CDATA[UPDATE consume SET use=21 WHERE username='riccardo' AND id_api='1']]></sql>
</statement>
</dbreport>
<log level="custom">
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="result for client" expression="get-property('result_user')" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="result for use" expression="get-property('result_use')" />
</log>
</sequence>
The first DB lookup works fine but the second SQL statement in the DBreport cannot update the value:
ERROR - DBReportMediator Error execuring insert statem
ent : UPDATE consume SET use='21' WHERE username='riccardo' AND id_api='1' again
st DataSource : jdbc:mysql://localhost:3306/new_db
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'use='21' WHERE username='riccardo' AND id_api=
'1'' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)...
My tables are as follows:
consume (int id, varchar username, int id_api, int use)
users (int id, varchar username, varchar password)
many thanks
EDIT I think there are major issues with DBREPORT AND DBLOOKUP mediators when writing on a Mysql DB, reading is fine, but Update and Insert just don't work...
tell me if I am wrong
Nuvio,
I think this issue arises not because of something wrong in the DBReport mediator. While going through the reported stack trace and the sequence configuration I can see you have defined "use" as a column name. I'm not quite sure how you created a database column with the term "use" because it is a MySQL keyword and MySQL query compiler should throw a SQLException whenever you have a keyword as a column or any other user defined attribute in your SQL query. Having a non-keyword name for in place of the column "use" would fix your problem.
Cheers,
Prabath

Log4Cxx sql server appender

Is it possible, when using Log4Cxx, to write the logs to MS SQL server?
I have been Googling for a while and have found a few examples that use the ODBCAppender. E.G.:
<appender name="MyOdbcMysqlAppender" class="org.apache.log4j.odbc.ODBCAppender">
<param name="URL" value="Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=errorlog;User=logger;Password=abc123;Option=3;"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="INSERT INTO errorlog (errormessage) VALUES ('%d - %c - %p - %m')"/>
</layout>
</appender>
Maybe I just need the correct value for the 'Driver' field? I am using MS SQL Server 2008.
Thank you!
I've gotten the following to work; define an ODBC source named LPErrorLog, define a login 'logger' with some password(abc123), configure SQLServer to support both WIndows and SQLServer authentication. Test your ODBC source, make sure you can login and access the target DB (LPErrorLog in example below) configure your ConversionPattern to match the fields in your DB. Temporarily configure same ConversionPattern for a normal file appender, then scarf the resulting INSERT INTO string from the file after logging to it, drop it into a SQL Server Management Studio script, then execute it to verify that it inserts what you want into the target DB, that it succeeds.
<appender name="MySqlAppender" class="org.apache.log4j.odbc.ODBCAppender">
<param name="URL" value="DSN=LPLogStore;Server=localhost\SQLEXPRESS;Database=LPErrorLog;Uid=logger;Pwd=abc123"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="INSERT INTO [LPErrorLog].[dbo].[errorlog] ([Logger],[LogTime],[Level],[FileName],[Location],[LineNo],[Message]) VALUES ('%c','%d{dd MMM yyyy HH:mm:ss,SSS}','%p','%F','%l','%L','%m')" />
</layout>