Hey Rishi,
Try using this code for custom login functionality using JAVA action.
Note: You need to pass System.User as Input parameter to this Java Action to work.
IMxRuntimeResponse response= this.getContext().getRuntimeResponse().get();
IContext systemContext = Core.createSystemContext();
ISession newSession = Core.initializeSession(Core.getUser(systemContext, user.getName()), "");
// the user.getName here used is the name of the object passed as input parameter
response.addCookie("XASSESSIONID", newSession.getId().toString(),"/" ,"" ,-1 );
response.addCookie("XASID", "0." + Core.getXASId(),"/" ,"" ,-1);