1 17 18 19 package org.apache.catalina.realm; 20 21 22 import org.apache.tomcat.util.digester.Digester; 23 import org.apache.tomcat.util.digester.Rule; 24 import org.apache.tomcat.util.digester.RuleSetBase; 25 import org.xml.sax.Attributes ; 26 27 28 35 36 public class MemoryRuleSet extends RuleSetBase { 37 38 39 41 42 45 protected String prefix = null; 46 47 48 50 51 55 public MemoryRuleSet() { 56 57 this("tomcat-users/"); 58 59 } 60 61 62 69 public MemoryRuleSet(String prefix) { 70 71 super(); 72 this.namespaceURI = null; 73 this.prefix = prefix; 74 75 } 76 77 78 80 81 90 public void addRuleInstances(Digester digester) { 91 92 digester.addRule(prefix + "user", new MemoryUserRule()); 93 94 } 95 96 97 } 98 99 100 103 final class MemoryUserRule extends Rule { 104 105 106 109 public MemoryUserRule() { 110 } 111 112 113 118 public void begin(String namespace, String name, Attributes attributes) 119 throws Exception { 120 121 String username = attributes.getValue("name"); 122 if (username == null) { 123 username = attributes.getValue("username"); 124 } 125 String password = attributes.getValue("password"); 126 String roles = attributes.getValue("roles"); 127 128 MemoryRealm realm = 129 (MemoryRealm) digester.peek(digester.getCount() - 1); 130 realm.addUser(username, password, roles); 131 132 } 133 134 135 } 136 | Popular Tags |