1
2
3
4
5 package gboat2.web.service;
6
7 import gboat2.web.Activator;
8 import gboat2.web.exception.ValidateException;
9 import gboat2.web.validate.AbstractValidator;
10 import gboat2.web.validators.NomalUserValidator;
11 import gboat2.web.validators.NotNullValidator;
12 import gboat2.web.validators.SuperValidator;
13
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.concurrent.CopyOnWriteArrayList;
18
19 import javax.annotation.PostConstruct;
20
21
22
23
24
25
26
27
28
29
30 public abstract class AbstractUserAuthService implements IUserAuthService {
31
32 private static volatile List<AbstractValidator> validateList = new CopyOnWriteArrayList<AbstractValidator>();
33
34
35
36 static {
37 validateList.add(new NotNullValidator(Activator.LOCAL_BUNDLE.getBundleContext()));
38 validateList.add(new SuperValidator(Activator.LOCAL_BUNDLE.getBundleContext()));
39 validateList.add(new NomalUserValidator(Activator.LOCAL_BUNDLE.getBundleContext()));
40 }
41
42
43 @Override
44 public final boolean validateUser(String userName, String password) throws ValidateException {
45 Map<String,Object> paraMap = new HashMap<String,Object>();
46 paraMap.put("username", userName);
47 paraMap.put("password", password);
48 for (AbstractValidator validate : validateList) {
49 validate.validate(paraMap);
50 }
51 return true;
52 }
53
54
55
56
57
58
59 protected void addValidator(AbstractValidator validate){
60 validateList.add(validate);
61 }
62
63
64
65
66
67 protected void removeValidator(AbstractValidator validate){
68 validateList.remove(validate);
69 }
70
71
72
73
74
75
76
77 @PostConstruct
78 protected void init(){
79 }
80
81 }