Sunday, April 19, 2009

एक शेर..

किताबें पढ़ पढ़ के सोचा था कि हाफिज़ मैं बनुंगा इक दिन,
खुदा रग रग में रहता है खोजता मैं किताबों में!
कि सोचा था मुझे बस मिल गई ताबीज़ आयत की,
भटकता फ़िर भी रहता हूँ इन आइनों की गलियों में!!

Friday, April 17, 2009

Securing a Coherence Cache

Coherence is a data source and the question is if we can secure it so that only authorized users/applications can access it. A sample custom named cache based solution is already available Here. Based on this example I have streamlined and simplified it's integration a little so that cache configuration is simpler and scope of security provider is taken out of Coherence. The entire project is available at Securing a Coherence Cache. [Part II is at http://ezsaid.blogspot.com/2009/10/integrating-ldap-with-coherence.html]

Following are some simplifications:

  1. Add a new XML Element (<entitled>) to enable a cache scheme for security. The configuration will look like the following:
    <distributed-scheme>
    <scheme-name>distributed-scheme</scheme-name>
    <service-name>DistributedCache</service-name>
    <backing-map-scheme>
    <local-scheme></local-scheme>
    </backing-map-scheme>
    <autostart>true</autostart>
    <entitled>
    <security-provider>MySecurityProvider</security-provider>
    </entitled>

    </distributed-scheme>
  2. A new ConfigurableCacheFactory. It's setConfig looks like:
        public void setConfig(XmlElement xmlConfig) {
    // -- Find all the caches for which entitled is set to true
    // -- Fild all cache names that has the scheme for which
    // -- entitled tag is defined
    // -- Replace the scheme name to a class-scheme with Entitled
    // -- cache
    // -- Find all the cache schemes with entitled set to true
    Map map = findEntitledSchemes(xmlConfig);
    XmlElement csM =
    xmlConfig.findElement("caching-scheme-mapping");
    Iterator cMs = csM.getElements("cache-mapping");
    XmlElement cM = null;
    while (cMs.hasNext()) {
    cM = (XmlElement) cMs.next();
    String schemeName =
    cM.findElement("scheme-name").getString();
    if (map.containsKey(schemeName)) {
    cM.findElement("scheme-name").setString("entitled-scheme");
    XmlElement iPs = cM.addElement("init-params");
    XmlElement iP = iPs.addElement("init-param");
    iP.addElement("param-name").setString("security-provider");
    iP.addElement("param-value").setString(map.get(schemeName));
    }
    }

    XmlElement rCS =
    XmlHelper.findElement(xmlConfig, "//caching-schemes");
    XmlElement cS = rCS.addElement("class-scheme");
    cS.addElement("scheme-name").setString("entitled-scheme");
    cS.addElement("class-name").setString(
    EntitledNamedCache.class.getName());
    XmlElement iPs = cS.addElement("init-params");

    XmlElement iP = iPs.addElement("init-param");
    iP.addElement("param-type").setString("string");
    iP.addElement("param-value").setString("{cache-name}");

    XmlElement iP2 = iPs.addElement("init-param");
    iP2.addElement("param-type").setString("string");
    String cache_config =
    System.getProperty("tangosol.coherence.cacheconfig");
    if (cache_config == null) {
    cache_config = FILE_CFG_CACHE;
    }
    iP2.addElement("param-value").setString(cache_config);

    XmlElement iP3 = iPs.addElement("init-param");
    iP3.addElement("param-type").setString("string");
    iP3.addElement("param-value").setString("{security-provider}");

    super.setConfig(xmlConfig);
    }
  3. A new interface to implement. Implement SecurityProvider interface and configure it as a security-provider in the cache configuration.
    public interface SecurityProvider {
    public boolean checkAccess (Subject subject);
    }
And thats all you need. Download the complete code from Securing a Coherence Cache. Enjoy!

Wednesday, April 15, 2009

India - Go and Vote

My sister a Civil Servant has been ultra busy for past two months - 7 days a week, 9 hrs a day, no vacation no public holidays to get the election logistics in her city ready. Keeping records, Computerization, testing each electronic voting machine and tons and tons of reviews and tests. So much effort has gone into making this noble right succeed. People who do not know it takes a lot of energy, effort and your tax money to conduct Elections so its your duty to go out and vote. Choose one and the right one, the one you believe is right to fulfill your aspirations. State can not afford to conduct elections again and again so choose wisely that the government is formed for full five years. Slap those who say "None of the above" should be an option on a ballot paper. Neither the government, nor the state instrument nor you can afford it. Listen to your inner voice and Just go and vote. Make Indian democracy a success again.

Saturday, April 11, 2009

Why is third front a disease India needs to get rid of?

Third front as it stands today constitutes of a bunch of parties that have aligned themselves with either of two main political platforms in the past. BJD and TDP with BJP, SP, RJD and Left with Congress, and so is AIADMK and switching their coalition for the other at a convenient time. Make no mistake some of these parties are great regional powers but their agenda is at a state level but unfortunately with a spineless national policy. These are also the parties that most likely will engage in horse trading at the end of elections. NDA has announced Advani and UPA Manmohan Singh as its Prime Ministerial candidates. Who is from this gutless third front? India has suffered most when we saw four/five PMs one after another by this loosely coupled groups of regional parties. India can not afford it no more. The essence of a successful Republic is strong representation of regional expectations. Either provide a third front with a totally different ideological agenda or just abolish it. India cannot afford to let these parties steal away their regional parliamentary seats and then play Ministry trading in the center and pull the nation to its political dark ages. Whatever they say their own agenda is no different from the common minimum program of either UPA or NDA then why waste our precious time? This no-agenda-political-front is a disease that India has to soon get rid of.

Wednesday, April 08, 2009

Disabling Coherence Cache

Another simple problem: How do I control if certain or all Cache operations should be disabled? By default it is not possible and need some custom coding... How? As usual lets create a cache config..

<cache-config>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>ControllerCache</cache-name>
<scheme-name>some-dist</scheme-name>
</cache-mapping>
<cache-mapping>
<cache-name>ControlledCache</cache-name>
<scheme-name>with-rw-bm</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<distributed-scheme>
<scheme-name>with-rw-bm</scheme-name>
<service-name>unlimited-partitioned</service-name>
<backing-map-scheme>
<read-write-backing-map-scheme>
<scheme-ref>base-rw-bm</scheme-ref>
</read-write-backing-map-scheme>
</backing-map-scheme>
<autostart>true</autostart>
</distributed-scheme>
<read-write-backing-map-scheme>
<scheme-name>base-rw-bm</scheme-name>
<class-name>ControllerBackingMap</class-name>
<internal-cache-scheme>
<local-scheme/>
</internal-cache-scheme>
</read-write-backing-map-scheme>
</caching-schemes>
</cache-config>
Now lets create the ControllerBackingMap...
public class ControllerBackingMap extends ReadWriteBackingMap 
implements XmlConfigurable, MapListenerSupport.SynchronousListener {
private XmlElement m_config;
private volatile boolean isOkay = true;

public ControllerBackingMap (.,.,.,...) {
super (.,.,.,...);
}
...
public void setConfig (XmlElement xmlElement) {
...
// -- Or pass the cache name as a parameter
NamedCache nCache = CacheFactory.getCache ("ControllerCache");
nCache.addMapListener (this);
}

public void entryInserted (MapEvent evt) {
if (evt.getNewValue() == ....) {
isOkay = false;
}
}

public Object put(final Object oKey, final Object oValue) {
???????
}
....
}
Now what? Lets say we want to disable any Cache puts if something has been inserted in the ControllerCache.. Of course expand it to any specifics keeping the controller cache model. The put () method will look like:
   public Object put(final Object oKey, final Object oValue) {
if (!isOkay) {
throw new RuntimeException("Operation currently blocked");
}
return super.put(oKey, oValue);
}
So here you go, Enjoy!

Monday, April 06, 2009

Why Oracle-Sun together makes more sense

For me the marriage is between two who can make each other complete. For Sun wouldn't it make more sense to marry a Devdas who is just made for you and not to some rich Sheikh who has a Harem of wives? Oracle, the Devdas misses an Operating System and a hardware business that Sun could bring and Sun will get a loving husband who will support her, share each others pain and provide a massive software platform to grow. A marriage of two where one does not kill the talents of the other because he had his own to push. A lady who comes with her own kitchen and utensils married to a farmer who grows his own vegetables. I see just a perfect marriage.

Thursday, April 02, 2009

Varun in Tytler out

Jagdish Tytler has been acquitted for the lack of evidence for his role in 1984 riots in Delhi against Sikhs after Indira Gandhi's assassination. This remains one of the few blots that India had to live with for decades and as a nation that it remained ashamed of. Tytler may not have any role or was mistaken or framed, I don't know but by what victims had to say or saw it seemed very much likely that he did play some role. Ironical, isn't it? So a man has been acquitted even though people saw him participating and directing mobs but Varun Gandhi has been slapped NSA because he said what he should not have said. Both are equally reprehensible but harsh treatment for one and letting the other go does not sound right, does it? It is said justice delayed is justice denied. 25 years gives enough time for powerful figures to coarse the evidences to make them doubtful to be not be able to be used against them. Could this be the case? Either way, Its lucky for him to be living under the free sky and fresh air but if he was responsible and still left with any shame or guilt he should leave all political and public office. If he was not responsible then I congratulate him on his acquittal. May the victim's soul rest in peace and who ever was responsible should soon meet them in heaven.