private Session createSession ( Properties props ) throws InvalidPasswordDecodingException , UnsupportedCryptoAlgorithmException { Session session = null ; // Since the password attribute in the server.xml is masked // the decryption algorythm is needed to before it can be put // it into the props object. if ( sessionProperties . get ( PASSWORD ) != null && sessionProperties . get ( USER ) != null ) { SerializableProtectedString password = ( SerializableProtectedString ) sessionProperties . get ( PASSWORD ) ; String pwdStr = password == null ? null : String . valueOf ( password . getChars ( ) ) ; pwdStr = PasswordUtil . getCryptoAlgorithm ( pwdStr ) == null ? pwdStr : PasswordUtil . decode ( pwdStr ) ; final String pwd = pwdStr ; sessionProperties . put ( "mail.password" , pwdStr ) ; session = Session . getInstance ( props , new Authenticator ( ) { @ Override protected PasswordAuthentication getPasswordAuthentication ( ) { return new PasswordAuthentication ( ( String ) sessionProperties . get ( USER ) , pwd ) ; } } ) ; } else { session = Session . getInstance ( props , null ) ; } return session ; }
The createSession method creates a session using the props if the password is specified in the server . xml then a session is creating using the password . If it is not specified then session is created with out a authenticator .