1 17 18 package org.objectweb.jac.aspects.authentication; 19 20 import org.objectweb.jac.util.WrappedThrowableException; 21 import java.io.File ; 22 import java.io.FileReader ; 23 import java.io.StreamTokenizer ; 24 import java.util.HashMap ; 25 26 32 33 public class FilePasswordAuthenticator extends PasswordAuthenticator { 34 35 File passwordFile; 36 37 44 public FilePasswordAuthenticator(String retries, String passwordFilename) { 45 super(Integer.parseInt(retries)); 46 passwordFile = new File (passwordFilename); 47 } 48 49 HashMap passwords; 50 51 boolean checkPassword(String username, String password) { 52 if (passwords==null) { 53 passwords = new HashMap (); 55 try { 56 StreamTokenizer tokens = new StreamTokenizer (new FileReader (passwordFile)); 57 tokens.resetSyntax(); 58 tokens.wordChars('\000','\377'); 59 tokens.whitespaceChars('\n','\n'); 60 tokens.whitespaceChars('\r','\r'); 61 while (tokens.nextToken() != StreamTokenizer.TT_EOF) { 62 String line = tokens.sval.trim(); 63 int index = line.indexOf(':'); 64 if (index!=-1) { 65 passwords.put(line.substring(0,index), 66 line.substring(index+1)); 67 } 68 } 69 } catch (Exception e) { 70 throw new WrappedThrowableException(e); 71 } 72 } 73 Object pass = passwords.get(username); 74 return (pass!=null && pass.equals(password)); 75 } 76 } 77 | Popular Tags |