Showing posts with label Weblogic. Show all posts
Showing posts with label Weblogic. Show all posts

Friday, March 28, 2014

JMS Message Selectors and OSB

JMS Topics are a good way to keep publishing messages and multiple subscribers can fetch messages based on their criteria. How we define the criteria is one of the main decision points that should be considered while defining the message structure and headers of the message. In one of the implementations done recently there was a requirement where consumers wanted to filter the messages based on a status, that was part of the body .So instead of reading all messages and parsing the status ,they were looking for a way to easily filter the messages.
As per the JMS spec ::
A JMS message selector allows a client to specify, by header field references and property references, the messages it is interested in. Only messages whose header and property values match the selector are delivered. What it means for a message not to be delivered depends on the Message Consumer being used.
Message selectors cannot reference message body values.
A message selector matches a message if the selector evaluates to true when the message's header field values and property values are substituted for their corresponding identifiers in the selector.
A message selector is a String whose syntax is based on a subset of the SQL92 conditional expression syntax. If the value of a message selector is an empty string, the value is treated as a null and indicates that there is no message selector for the message consumer.
A property value may duplicate a value in a message's body, or it may not. Although JMS does not define a policy for what should or should not be made a property, application developers should note that JMS providers will likely handle data in a message's body more efficiently than data in a message's properties. For best performance, applications should use message properties only when they need to customize a message's header. The primary reason for doing this is to support customized message selection
Weblogic customized the message selector for weblogic JMS.
JMS_BEA_SELECT is a built-in function in WebLogic JMS SQL syntax. You specify the syntax type, which must be set to xpath (XML Path Language) and an XPath expression.
    Eg:- JMS_BEA_SELECT('xpath', '/message/status/text()') = ‘REQUEST_SUBMITTED’
But from OSB point of view, the message selector goes by strict JMS spec and the custom Message selector function - JMS_BEA_SELECT is not supported as it is designed to be more generic and needs to communicate with JMS Topics from different vendors. So the only supported options will be to have custom message headers defined on the message and consumers filtering on them, even it means duplicating the fields in header and body of the message.

Wednesday, March 19, 2014

Weblogic JMS Topic does not support durable subscriptions-workaround


One of our service consumers where facing issues with durable subscription. They were able to successfully connect as durable subscribers in Single node topic, but they started issues once they started connecting to clustered environments where the topic where configured as Uniform Distributed Topic.

Error Snippet
-------------
weblogic.jms.common.JMSException: [JMSClientExceptions:055030]This topic does not support durable subscriptions
                at weblogic.jms.client.JMSSession.createDurableSubscriber(JMSSession.java:2482)
                at weblogic.jms.client.JMSSession.createDurableSubscriber(JMSSession.java:2460)
                at weblogic.jms.client.WLSessionImpl.createDurableSubscriber(WLSessionImpl.java:1204)
                at com.artesia.video.flip.ArtesiaConnectionInitializer.run(ArtesiaConnectionInitializer.java:168)
 
Topic configuration
--------------------------
GeoDownloadTopic
Uniform Distributed Topic
jms/Topic/GeoTestTopic
GEOJMSTopic_SD
  GEOJMSServer_1, GEOJMSServer_2, GEOJMSServer_3, GEOJMSServer_4

To use durable subscription you will need to use JNDI of individual node Topic.

Eg: -  GEOJMSServer_1@jms.Topic.GeoDownloadTopic


How to get the JNDI name of each node
  • Click the Servers node to expand it and expose the names of the servers currently being administered through the console.
  • Click the name of the server whose JNDI tree you want to view.
  • Scroll down to the bottom of the Configuration pane, and Click the "View JNDI Tree" link.
  • The JNDI tree will appear in a new browser window. You can click on an individual object name to view information about its bind name and hash code.

Thursday, May 2, 2013

Cross-Site Request Forgery (CSRF) in weblogic /osb 11g



          Recently while I was doing continuous testing in OSB Console and collecting the performance metrics, the server was not responding. When we started digging in we saw that the Admin server was down and it was throwing Could not discover URL for server 'AdminServer' error.
ErrorLog
<Cannot contact the admin server. Therefore constructing the Cluster Authority Current time with the time skew 0
java.rmi.UnknownHostException: Could not discover URL for server 'AdminServer'
        at weblogic.protocol.URLManager.findURL(URLManager.java:145)
        at com.bea.alsb.platform.weblogic.topology.WlsRemoteServerImpl.getInitialContext(WlsRemoteServerImpl.java:94)
        at com.bea.alsb.platform.weblogic.topology.WlsRemoteServerImpl.lookupJNDI(WlsRemoteServerImpl.java:54)
        at com.bea.wli.sb.init.RemoteClusterTimerAuthority.getTimerAuthority(RemoteClusterTimerAuthority.java:59)
        at com.bea.wli.sb.init.RemoteClusterTimerAuthority.getClusterTimerAuthorityCurrentTime(RemoteClusterTimerAuthority.java:33)
        at com.bea.wli.timer.TimeSkewSynchronizer$TimeSkewSynchronizerTask.run(TimeSkewSynchronizer.java:47)

When we did some more research, it looked like a CSRF attack.
ErrorLog
A Cross-site request forgery (CSRF) has been detected. Task=com.bea.console.actions.changemgmt.StopEditAction address=10.111.11.10 user=george
Not sure what triggered it, but it was nice to know more on CSRF from oracle blogs and Wiki.
Cross-Site Request Forgery (CSRF), also known as Cross-Site Reference Forgery (XSRF), Session Riding is a type of malicious exploit where unauthorized requests are transmitted from a user to a trusted website (the target). CSRF exploits the trust that the targeted site has in a user’s browser and generally works by embedding a link or script in a malicious page to access a site to which the user has already been authenticated.

Monday, February 4, 2013

Custom SQL authenticator configurations on weblogic -Part1



I had a scenario where we were not able to authenticate users against LDAP and access to LDAP was not provided. So the next option was to get export of the user data and have a custom SQL authentication configured on the weblogic server.
So we had a person table with all user tables. But there were couple of issues when we tried to configure custom sql authentication. In our scenario the user gets automatically authenticated in the J2ee application, so the authentication to Human worklist application was not required, so we had the option of hardcoding a single password so that its easy for j2ee web app to call worklist api to access tasks based the user id alone.
The steps for configuring the custom sql authenticator can be found in reference blogs listed below.


Issue#1
Since the PERSON table didn’t have password column, I tried assigning the query select welcome1 from dual query to retrieve the password. So for all users it will return welcome1 as password. But it didnt work.
<wls:sql-get-users-password>SELECT select ‘welcome1’ from dual </wls:sql-get-users-password>

Error stackTrace
------------------------------
<Jan 15, 2013 9:19:53 AM IST> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>
<Jan 15, 2013 9:22:39 AM IST> <Error> <Security> <BEA-000000> <[Security:090759]A SQLException occurred while retrieving password informatio
n
java.sql.SQLException: Invalid column index
        at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:6336)
        at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:6306)
        at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:303)
        at weblogic.jdbc.wrapper.PreparedStatement.setString(PreparedStatement.java:908)
        at weblogic.security.providers.authentication.shared.DBMSSQLRuntimeQueryImpl.passwordStringQuery(DBMSSQLRuntimeQueryImpl.java:88)
        Truncated. see log file for complete stacktrace

Issue #2
I tried using PERSON and SOA_PASSWORD tables with emailaddress and Password column respectively .Email address from PERSON and password from SOA_PASSWORD table.
This also throws error

Error Stacktrace
--------------------------
java.sql.SQLException: Invalid column index
        at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:6336)
        at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:6306)
        at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:303)
        at weblogic.jdbc.wrapper.PreparedStatement.setString(PreparedStatement.java:908)
        at weblogic.security.providers.authentication.shared.DBMSSQLRuntimeQueryImpl.passwordStringQuery(DBMSSQLRuntimeQueryImpl.java:88)
        Truncated. see log file for complete stacktrace

This works properly.
Conclusion :-- User and Password queries have to be on same table.

Solution
----------
finally created a VIEW -- SOA_PASSWORD_VIEW with à  SELECT person.EMAILADDRESS, 'welcome1' FROM PERSON person;

CREATE OR REPLACE FORCE VIEW "SOA_PASSWORD_VIEW" ("EMAILADDRESS", "PASSWORD") AS   SELECT person.EMAILADDRESS, 'welcome1' FROM PERSON person;

Sample queries you add in config.xml

Code snippet from config.xml
--------------------------------------------------------------

<wls:sql-get-users-password>SELECT PASSWORD FROM SOA_PASSWORD_VIEW WHERE EMAILADDRESS = ?</wls:sql-get-users-password>
        <wls:sql-user-exists>SELECT EMAILADDRESS FROM SOA_PASSWORD_VIEW WHERE EMAILADDRESS = ?</wls:sql-user-exists>
        <wls:sql-list-member-groups>SELECT ROLES_NAME FROM PERSON_ROLE WHERE PERSON_EMAILADDRESS = ?</wls:sql-list-member-groups>
        <wls:sql-list-users>SELECT EMAILADDRESS FROM SOA_PASSWORD_VIEW WHERE EMAILADDRESS LIKE ? and rownum &lt; 10</wls:sql-list-users>
        <wls:sql-list-groups>SELECT NAME FROM ROLE WHERE NAME LIKE ? and rownum &lt; 10</wls:sql-list-groups>
        <wls:sql-group-exists>SELECT NAME FROM ROLE WHERE NAME = ?</wls:sql-group-exists>
        <wls:sql-is-member>SELECT PERSON_EMAILADDRESS FROM PERSON_ROLE WHERE ROLES_NAME = ? AND PERSON_EMAILADDRESS = ?</wls:sql-is-member>
        <wls:password-style>PLAINTEXT</wls:password-style>
        <wls:sql-create-user>INSERT INTO SOA_PASSWORD_VIEW (EMAILADDRESS,PASSWORD) VALUES ( ? , ? )</wls:sql-create-user>
        <wls:sql-remove-user>DELETE FROM SOA_PASSWORD_VIEW WHERE EMAILADDRESS = ?</wls:sql-remove-user>
        <wls:sql-remove-group-memberships>DELETE FROM PERSON_ROLE WHERE PERSON_EMAILADDRESS = ? OR ROLES_NAME = ?</wls:sql-remove-group-memberships>
        <wls:sql-set-user-password>UPDATE SOA_PASSWORD_VIEW SET PASSWORD = ?</wls:sql-set-user-password>
        <wls:sql-create-group>INSERT INTO ROLE(NAME) VALUES ( ? )</wls:sql-create-group>
        <wls:sql-add-member-to-group>INSERT INTO PERSON_ROLE (ROLES_NAME,PERSON_EMAILADDRESS) VALUES( ?, ?)</wls:sql-add-member-to-group>
        <wls:sql-remove-member-from-group>DELETE FROM PERSON_ROLE WHERE ROLES_NAME = ? AND PERSON_EMAILADDRESS = ?</wls:sql-remove-member-from-group>
        <wls:sql-remove-group>DELETE FROM ROLE WHERE NAME = ?</wls:sql-remove-group>
        <wls:sql-remove-group-member>DELETE FROM PERSON_ROLE WHERE ROLES_NAME = ?</wls:sql-remove-group-member>
        <wls:sql-list-group-members>SELECT PERSON_EMAILADDRESS FROM PERSON_ROLE WHERE ROLES_NAME = ? AND PERSON_EMAILADDRESS LIKE ? and rownum &lt; 10</wls:sql-list-group-members>
      </sec:authentication-provider>

This basically covers the initial DB setup and issues faced while configuring the Custom SQL authenticator. Thanks to Bhupinder,Ram and Venkat for helping with this configuration

Resources: