Creativity and Innovation

Just another weblog

Leave a comment

Java Windows Authentication

To do Windows Authenticate in java you need jna.jar and platrofm.jar library

Below code is useful to do authentication

import com.sun.jna.platform.win32.Advapi32;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinNT;

public class AuthWindowsUser {

public static void main(String[] args) {
boolean isWindowsUser=false;

isWindowsUser= authWindowsUser(“A563627″,””,”test@Pass123″);
if(isWindowsUser) {
System.out.println(“User is authenticated”);
} else {
System.out.println(“User is not authenticated”);

public static boolean authWindowsUser(String user, String domain, String password) {
WinNT.HANDLEByReference handle = new WinNT.HANDLEByReference();
boolean successful = Advapi32.INSTANCE.LogonUser(user, domain, password,WinBase.LOGON32_LOGON_NETWORK,WinBase.LOGON32_PROVIDER_DEFAULT, handle);
if (successful) {
return successful;


1 Comment

Configure SonarQube for non-Maven based Java Project

I am curious to analyze my Java code quality using SonarQube. The help line have given on SonarQube website. You can do code analysis of various kind of project for that you have to see the help line here. I am unable to find the guideline to do code analysis of non maven based java project. I faced too much problem but finally I solved it so I would like to write the guideline here which will be helpful to anyone.

  1. Download SonarQube 5.6.3 zip file and extract it on your machine
  2. Download SonarQube Scanner 2.8 zip file and extract it on your machine
  3. Create file. sample file is given here sonar-project-properties in word document format. Copy the file content and make necessary changes like sonar.sources=C:\\Users\\workspace_Mars\\JavaStudy\\src (put the double slash) and save it under your java project root directory like C:\Users\workspace_Mars\JavaStudy\ as shown in the figure.
  4. I am using Windows 7-64 bit, Java8-32 bit and Eclipse Java EE IDE for Web Developers (Version: Mars Release 4.5.0) 32 bit application. So go in the directory C:\Installed Sonar\sonarqube-5.6.3\bin\windows-x86-32 and run StartSonar.bat file.
  5. Do not close the SonarQube console window. Hit http://localhost:9000/ on your favorite web browser. Here I am using Mozilla Firefox. Default login credential is admin/admin. You can see the SonarQube home page as shown in above figure. You can see none of the project is added in SonarQube.
  6. Open command prompt and go into your project then run sonar-scanner.bat file like this C:\Users\workspace_Mars\JavaStudy>”C:\Installed Sonar\sonar-scanner-2.8\bin\sonar-scanner.bat” (wrapped in double quote because space exist in my folder name)
  7. You can see the Sonar Scanner start running on your project. It is analyzing your project.Go on http://localhost:9000/ and refresh the page (hit F5)

    You can see your project under Projects list. Now you can see code analysis on web.

  8. To see the code analysis in eclipse Installed SonarLint plugin in Eclipse.
  9. Go Eclipse>Window >Show view> Others.. and open SonarLint issues, SonarLint Rule Description, SonarQube Servers
  10. Go in SonarQube Servers and Click to connect to a SonarQube server….
  11. Put down the details as show in figure. Press the Test connection button. If everything is fine then it’s show the successfully connected message. Press Finish button.sonarlint-connecting-to-sonarqube
  12. Right click on your project and select SonarLint> Bind to a SonarQube project…
  13. Initially the SonarQube project name is like below press Auto Bind selected projects button or type SonarQube project name. Here my java project name and SonarQube project name (JavaStudy) is same so I have given JavaStudy. It’s intellisense detect and showing ‘main’ on server ‘localhost’. Finally PressFinish buttonProject bind to SonarQube.png
  14. If you open any class then SonarLint showing the issues in SonarLint issues tab.Project issue in SonarLint.png