1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.security;
20
21 import java.io.IOException;
22
23 import org.eclipse.jetty.security.PropertyUserStore.UserListener;
24 import org.eclipse.jetty.server.UserIdentity;
25 import org.eclipse.jetty.util.Scanner;
26 import org.eclipse.jetty.util.log.Log;
27 import org.eclipse.jetty.util.log.Logger;
28 import org.eclipse.jetty.util.resource.Resource;
29 import org.eclipse.jetty.util.security.Credential;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class HashLoginService extends MappedLoginService implements UserListener
49 {
50 private static final Logger LOG = Log.getLogger(HashLoginService.class);
51
52 private PropertyUserStore _propertyUserStore;
53 private String _config;
54 private Resource _configResource;
55 private Scanner _scanner;
56 private int _refreshInterval = 0;
57
58
59 public HashLoginService()
60 {
61 }
62
63
64 public HashLoginService(String name)
65 {
66 setName(name);
67 }
68
69
70 public HashLoginService(String name, String config)
71 {
72 setName(name);
73 setConfig(config);
74 }
75
76
77 public String getConfig()
78 {
79 return _config;
80 }
81
82
83 public void getConfig(String config)
84 {
85 _config = config;
86 }
87
88
89 public Resource getConfigResource()
90 {
91 return _configResource;
92 }
93
94
95
96
97
98
99
100
101 public void setConfig(String config)
102 {
103 _config = config;
104 }
105
106
107 public void setRefreshInterval(int msec)
108 {
109 _refreshInterval = msec;
110 }
111
112
113 public int getRefreshInterval()
114 {
115 return _refreshInterval;
116 }
117
118
119 @Override
120 protected UserIdentity loadUser(String username)
121 {
122 return null;
123 }
124
125
126 @Override
127 public void loadUsers() throws IOException
128 {
129
130 }
131
132
133
134
135
136 @Override
137 protected void doStart() throws Exception
138 {
139 super.doStart();
140
141 if (_propertyUserStore == null)
142 {
143 if(LOG.isDebugEnabled())
144 LOG.debug("doStart: Starting new PropertyUserStore. PropertiesFile: " + _config + " refreshInterval: " + _refreshInterval);
145
146 _propertyUserStore = new PropertyUserStore();
147 _propertyUserStore.setRefreshInterval(_refreshInterval);
148 _propertyUserStore.setConfig(_config);
149 _propertyUserStore.registerUserListener(this);
150 _propertyUserStore.start();
151 }
152 }
153
154
155
156
157
158 @Override
159 protected void doStop() throws Exception
160 {
161 super.doStop();
162 if (_scanner != null)
163 _scanner.stop();
164 _scanner = null;
165 }
166
167
168 @Override
169 public void update(String userName, Credential credential, String[] roleArray)
170 {
171 if (LOG.isDebugEnabled())
172 LOG.debug("update: " + userName + " Roles: " + roleArray.length);
173 putUser(userName,credential,roleArray);
174 }
175
176
177 @Override
178 public void remove(String userName)
179 {
180 if (LOG.isDebugEnabled())
181 LOG.debug("remove: " + userName);
182 removeUser(userName);
183 }
184 }