Wednesday, December 30, 2015

LDAP Details

nltest /dclist:yourdomain.com


https://social.technet.microsoft.com/Forums/windowsserver/en-US/3c137047-23c6-41e0-8a34-0b32423c7403/how-to-find-the-ldap-servers-in-a-domain?forum=winserverDS

You need to use your own domain name as the parameter of the /dclist switch i.e.
nltest /dclist:yourdomain.com
alternatively you can use procedure described in http://support.microsoft.com/kb/816587 to query DNS i.e.:
  1. Click Start, and then click Run.
  2. In the Open box, type cmd.
  3. Type nslookup, and then press ENTER.
  4. Type set type=all, and then press ENTER.
  5. Type _ldap._tcp.dc._msdcs.Domain_Name, where Domain_Name is the name of your domain, and then press ENTER.

package com.example;


import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;

/**
 * Example code for retrieving a Users Primary Group
 * from Microsoft Active Directory via. its LDAP API
 * 
 * @author Adam Retter
 */
public class LDAPTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws NamingException {
        
        final String ldapAdServer = "ldap://localhost:389";
        final String ldapSearchBase = "dc=domain,dc=com";
        
        final String ldapUsername = "xyz@abc.com";
        final String ldapPassword = "secret";
        
        final String ldapAccountToLookup = "divya.parashar@metricstream.com";
        
        
        Hashtable env = new Hashtable();
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        if(ldapUsername != null) {
            env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
        }
        if(ldapPassword != null) {
            env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
        }
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, ldapAdServer);

        //ensures that objectSID attribute values
        //will be returned as a byte[] instead of a String
        env.put("java.naming.ldap.attributes.binary", "objectSID");
        
        // the following is helpful in debugging errors
        //env.put("com.sun.jndi.ldap.trace.ber", System.err);
        
        LdapContext ctx = new InitialLdapContext(env,null);
        
        LDAPTest ldap = new LDAPTest();
        
        //1) lookup the ldap account
   //     SearchResult srLdapUser = ldap.findAccountByAccountName(ctx, ldapSearchBase, ldapAccountToLookup);
        
        SearchResult srresult = ldap.findAccountByFirstNameLastName(ctx, ldapSearchBase, "John Doe");
        //2) get the SID of the users primary group
    //    String primaryGroupSID = ldap.getPrimaryGroupSID(srLdapUser);
        
        //3) get the users Primary Group
    //    String primaryGroupName = ldap.findGroupBySID(ctx, ldapSearchBase, primaryGroupSID);
    }
    
    public SearchResult findAccountByFirstNameLastName( DirContext ctx, String ldapSearchBase , String name) throws NamingException{
    String searchFilter = "(&(objectClass=person)(name=" + name + "))";
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

         NamingEnumeration results = ctx.search(ldapSearchBase, searchFilter, searchControls);

         SearchResult searchResult = null;
         if(results.hasMoreElements()) {
              searchResult = (SearchResult) results.nextElement();

             //make sure there is not another item available, there should be only 1 match
             if(results.hasMoreElements()) {
                 System.err.println("Matched multiple users for the accountName: " + name);
                 return null;
             }
         }
         
         return searchResult;
   
    }
    
    public SearchResult findAccountByAccountName(DirContext ctx, String ldapSearchBase, String accountName) throws NamingException {

        String searchFilter = "(&(objectClass=person)(userPrincipalName=" + accountName + "))";

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        NamingEnumeration results = ctx.search(ldapSearchBase, searchFilter, searchControls);

        SearchResult searchResult = null;
        if(results.hasMoreElements()) {
             searchResult = (SearchResult) results.nextElement();

            //make sure there is not another item available, there should be only 1 match
            if(results.hasMoreElements()) {
                System.err.println("Matched multiple users for the accountName: " + accountName);
                return null;
            }
        }
        
        return searchResult;
    }
    
    public String findGroupBySID(DirContext ctx, String ldapSearchBase, String sid) throws NamingException {
        
        String searchFilter = "(&(objectClass=group)(objectSid=" + sid + "))";

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        
        NamingEnumeration results = ctx.search(ldapSearchBase, searchFilter, searchControls);

        if(results.hasMoreElements()) {
            SearchResult searchResult = (SearchResult) results.nextElement();

            //make sure there is not another item available, there should be only 1 match
            if(results.hasMoreElements()) {
                System.err.println("Matched multiple groups for the group with SID: " + sid);
                return null;
            } else {
                return (String)searchResult.getAttributes().get("sAMAccountName").get();
            }
        }
        return null;
    }
    
    public String getPrimaryGroupSID(SearchResult srLdapUser) throws NamingException {
        byte[] objectSID = (byte[])srLdapUser.getAttributes().get("objectSid").get();
        String strPrimaryGroupID = (String)srLdapUser.getAttributes().get("primaryGroupID").get();
        
        String strObjectSid = decodeSID(objectSID);
        
        return strObjectSid.substring(0, strObjectSid.lastIndexOf('-') + 1) + strPrimaryGroupID;
    }
    
    /**
     * The binary data is in the form:
     * byte[0] - revision level
     * byte[1] - count of sub-authorities
     * byte[2-7] - 48 bit authority (big-endian)
     * and then count x 32 bit sub authorities (little-endian)
     * 
     * The String value is: S-Revision-Authority-SubAuthority[n]...
     * 
     * Based on code from here - http://forums.oracle.com/forums/thread.jspa?threadID=1155740&tstart=0
     */
    public static String decodeSID(byte[] sid) {
        
        final StringBuilder strSid = new StringBuilder("S-");

        // get version
        final int revision = sid[0];
        strSid.append(Integer.toString(revision));
        
        //next byte is the count of sub-authorities
        final int countSubAuths = sid[1] & 0xFF;
        
        //get the authority
        long authority = 0;
        //String rid = "";
        for(int i = 2; i <= 7; i++) {
           authority |= ((long)sid[i]) << (8 * (5 - (i - 2)));
        }
        strSid.append("-");
        strSid.append(Long.toHexString(authority));
        
        //iterate all the sub-auths
        int offset = 8;
        int size = 4; //4 bytes for each sub auth
        for(int j = 0; j < countSubAuths; j++) {
            long subAuthority = 0;
            for(int k = 0; k < size; k++) {
                subAuthority |= (long)(sid[offset + k] & 0xFF) << (8 * k);
            }
            
            strSid.append("-");
            strSid.append(subAuthority);
            
            offset += size;
        }
        
        return strSid.toString();    
    }
}

Tuesday, November 3, 2015

Change root password mysql

http://www.cyberciti.biz/faq/mysql-change-root-password/

Sunday, October 18, 2015

coupon links

http://saltnlight5.blogspot.in/
http://docs.spring.io/spring-security/site/docs/current/reference/html/core-web-filters.html#access-denied-handler
http://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html
https://developer.chrome.com/extensions/contentSecurityPolicy
https://spring.io/guides/gs/rest-service-cors/
https://github.com/spring-guides/gs-securing-web/blob/master/complete/src/main/resources/templates/hello.html
https://spring.io/guides/gs/securing-web/

http://www.concretepage.com/spring/spring-security/spring-mvc-security-jdbc-authentication-example-with-custom-userdetailsservice-and-database-tables-using-java-configuration

MAVEN ERROR FIX

http://blog.timmattison.com/archives/2012/03/28/how-to-fix-maven-errors-in-eclipse-when-getting-started-with-heroku/

https://developer.chrome.com/extensions/content_scripts

GOOD TUTORIAL ON CHROME EXTENSION


https://blog.hartleybrody.com/chrome-extension/

http://springinpractice.com/

mvn clean install -U
http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/

https://github.com/netgloo/spring-boot-samples

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-connect-to-production-database

https://spring.io/guides/gs/securing-web/

https://spring.io/guides/gs/securing-web/#run_the_app














Saturday, October 17, 2015

Friday, October 16, 2015

maven compiler

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Tuesday, October 13, 2015

Thursday, October 8, 2015

Zip4J and schematools and SVN setup on Ubuntu

http://www.lingala.net/zip4j/download.php


http://dba.stackexchange.com/questions/46557/open-source-tools-for-oracle-schema-compares


http://www.krizna.com/ubuntu/setup-svn-server-on-ubuntu-14-04/

Friday, September 11, 2015

Setting up java 8 on rhel

http://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/

Friday, July 24, 2015

Preparation

201 Created or POST-Redirect-GET
Completable Future
Java Stream API
Concurrent Blocking Queue
http://appcrawler.com/wordpress/2012/08/01/tcpdump-to-see-oracle-errors/
http://appcrawler.com/wordpress/2015/06/10/credit-card-tokenization-overview/
http://appcrawler.com/wordpress/2015/04/09/dump-heap-programatically/
http://appcrawler.com/wordpress/2015/01/28/healthy-socket-activity-shown-in-wireshark/
https://springframework.guru/blog/
http://appcrawler.com/wordpress/2015/01/13/determining-the-order-of-java-classes-called/
http://appcrawler.com/wordpress/2014/07/15/does-java-reuse-closed-sockets-when-the-host-still-has-one-open/
http://appcrawler.com/wordpress/2014/07/10/simulating-shopper-abandonment-in-jmeter/
http://appcrawler.com/wordpress/2014/06/20/where-is-a-given-thread-connecting/
http://appcrawler.com/wordpress/2014/01/03/using-strace-to-determine-progress-when-processing-a-file/
http://appcrawler.com/wordpress/2013/12/28/gathering-information-from-hotspot-garbage-collection-logs/
http://appcrawler.com/wordpress/2013/12/10/is-connection-refused-always-a-network-issue/
http://appcrawler.com/wordpress/2013/03/07/outofmemory-error-in-one-classloader/
http://appcrawler.com/wordpress/2013/04/28/can-you-run-java-hprof-and-a-custom-agentlib-together/
http://appcrawler.com/wordpress/2013/06/20/inserting-full-objects-into-a-database-column/
http://appcrawler.com/wordpress/2013/05/06/one-way-to-tell-if-a-thread-pool-is-hung/
http://appcrawler.com/wordpress/2013/05/09/formatting-garbage-collection-output-with-timestamps/
http://appcrawler.com/wordpress/2011/06/21/multiple-threads-using-same-physical-connection/
http://appcrawler.com/wordpress/2013/07/05/tying-a-linux-socket-file-descriptor-to-a-port-and-ip/
http://appcrawler.com/wordpress/2013/07/08/which-threads-are-running-on-a-given-cpu/
http://appcrawler.com/wordpress/2013/07/17/which-threads-are-talking-to-the-database/
http://appcrawler.com/wordpress/2013/07/15/determining-the-source-of-high-java-cpu/
http://appcrawler.com/wordpress/2013/10/22/interrupting-a-thread-in-java/
http://appcrawler.com/wordpress/2013/11/30/getting-count-of-sessions-created-by-minute/
http://appcrawler.com/wordpress/2013/11/21/when-does-the-cms-collector-run-by-default/
http://appcrawler.com/wordpress/2012/10/01/exhausting-the-heap-on-a-jdbc-batch-with-huge-size/
http://appcrawler.com/wordpress/2012/11/09/tracing-sql-across-the-wire/
http://appcrawler.com/wordpress/2012/12/03/quick-way-to-trace-a-session-on-a-server/
http://appcrawler.com/wordpress/2012/12/27/handling-out-of-memory-errors-in-hotspot/
http://appcrawler.com/wordpress/2013/01/02/simple-byte-code-injection-example-with-javassist/

http://dsebban.github.io/blog/2015/rxjava-in-action-with-live-financial-market-data-from-ib-part-1.html




Tuesday, May 19, 2015

Pushing existing project to git

Git global setup git config --global user.name "NAME" git config --global user.email "EMAIL" Create a new repository mkdir Facade cd Facade git init touch README.md git add README.md git commit -m "first commit" git remote add origin git@gitlab.corp.xyz.net:service-decoupling/Facade.git git push -u origin master Push an existing Git repository cd existing_git_repo git remote add origin git@gitlab.corp.xyz.net:service-decoupling/Facade.git git push -u origin master

Friday, March 27, 2015