Krb5ClientHelper { public Subject krb5PasswordLogin(String password) { String loginModuleName = "krb5UsernamePasswordLogin"; LOG.info("Attempting kerberos authentication of user: " + clientPrincipal + " using username and password mechanism"); Map<String, String> jaasOptions = new HashMap<String, String>(); jaasOptions.put("useKeyTab", "false"); jaasOptions.put("storeKey", "false"); jaasOptions.put("doNotPrompt", "false"); jaasOptions.put("refreshKrb5Config", "false"); jaasOptions.put("clearPass", "true"); jaasOptions.put("useTicketCache", "false"); LOG.debug("Dynamic jaas configuration used:" + jaasOptions.toString()); DynamicJaasConfiguration contextConfig = new DynamicJaasConfiguration(); contextConfig.addAppConfigEntry(loginModuleName, "com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, jaasOptions); try { LoginContext loginCtx = new LoginContext(loginModuleName,null, new LoginUsernamePasswordHandler(clientPrincipal, password), contextConfig); loginCtx.login(); Subject clientSubject = loginCtx.getSubject(); String loggedInUser = principalNameFromSubject(clientSubject); LOG.info("SUCCESSFUL LOGIN for user: " + loggedInUser + " using username and password mechanism."); return clientSubject; } catch (LoginException le){ le.printStackTrace(); LOG.info("LOGIN FAILED for user: " + clientPrincipal + " using username and password mechanism. Reason: " + le.toString()); return null; } } Krb5ClientHelper(String clientPrincipal);  Krb5ClientHelper(String realm, String username); Subject krb5KeytabLogin(String keytab); Subject krb5PasswordLogin(String password); String principalNameFromSubject(Subject clientSubject); byte[] requestServiceTicket(Subject clientSubject, String servicePrincipalName);  }
@Test public void clientPasswordloginBadPasssword() { Subject clientSubject = krb5ClientHelper.krb5PasswordLogin(testBadPassword); assertNull(clientSubject); }