1 55 56 package org.jboss.axis.security.simple; 57 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.MessageContext; 60 import org.jboss.axis.security.AuthenticatedUser; 61 import org.jboss.axis.security.SecurityProvider; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.logging.Logger; 64 65 import java.io.File ; 66 import java.io.FileReader ; 67 import java.io.LineNumberReader ; 68 import java.util.HashMap ; 69 import java.util.StringTokenizer ; 70 71 76 public class SimpleSecurityProvider implements SecurityProvider 77 { 78 private static Logger log = Logger.getLogger(SimpleSecurityProvider.class.getName()); 79 80 HashMap users = null; 81 HashMap perms = null; 82 83 boolean initialized = false; 84 85 private synchronized void initialize(MessageContext msgContext) 87 { 88 if (initialized) return; 89 90 String configPath = msgContext.getStrProp(Constants.MC_CONFIGPATH); 91 if (configPath == null) 92 { 93 configPath = ""; 94 } 95 else 96 { 97 configPath += File.separator; 98 } 99 File userFile = new File (configPath + "users.lst"); 100 if (userFile.exists()) 101 { 102 users = new HashMap (); 103 104 try 105 { 106 107 FileReader fr = new FileReader (userFile); 108 LineNumberReader lnr = new LineNumberReader (fr); 109 String line = null; 110 111 while ((line = lnr.readLine()) != null) 113 { 114 StringTokenizer st = new StringTokenizer (line); 115 if (st.hasMoreTokens()) 116 { 117 String userID = st.nextToken(); 118 String passwd = (st.hasMoreTokens()) ? st.nextToken() : ""; 119 120 if (log.isDebugEnabled()) 121 { 122 log.debug(Messages.getMessage("fromFile00", 123 userID, passwd)); 124 } 125 126 users.put(userID, passwd); 127 } 128 } 129 130 lnr.close(); 131 132 } 133 catch (Exception e) 134 { 135 log.error(Messages.getMessage("exception00"), e); 136 return; 137 } 138 } 139 initialized = true; 140 } 141 142 149 public AuthenticatedUser authenticate(MessageContext msgContext) 150 { 151 152 if (!initialized) 153 { 154 initialize(msgContext); 155 } 156 157 String username = msgContext.getUsername(); 158 String password = msgContext.getPassword(); 159 160 if (users != null) 161 { 162 if (log.isDebugEnabled()) 163 { 164 log.debug(Messages.getMessage("user00", username)); 165 } 166 167 if (username == null || 169 username.equals("") || 170 !users.containsKey(username)) 171 return null; 172 173 String valid = (String )users.get(username); 174 175 if (log.isDebugEnabled()) 176 { 177 log.debug(Messages.getMessage("password00", password)); 178 } 179 180 if (valid.length() > 0 && !valid.equals(password)) 182 return null; 183 184 if (log.isDebugEnabled()) 185 { 186 log.debug(Messages.getMessage("auth00", username)); 187 } 188 189 return new SimpleAuthenticatedUser(username); 190 } 191 192 return null; 193 } 194 195 201 public boolean userMatches(AuthenticatedUser user, String principal) 202 { 203 if (user == null) return principal == null; 204 return user.getName().compareToIgnoreCase(principal) == 0; 205 } 206 } 207 | Popular Tags |