1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  package com.buckosoft.BuckoVidLib.business;
56  
57  import java.util.ArrayList;
58  import java.util.List;
59  
60  import org.apache.commons.logging.Log;
61  import org.apache.commons.logging.LogFactory;
62  import org.springframework.beans.factory.annotation.Autowired;
63  
64  import com.buckosoft.BSAccount.domain.BSAccount;
65  import com.buckosoft.BSAccount.domain.BSAccountUser;
66  import com.buckosoft.BSAccount.domain.BSAccountUserWebSession;
67  import com.buckosoft.BuckoVidLib.domain.User;
68  import com.buckosoft.BuckoVidLib.domain.UserAttribute;
69  import com.buckosoft.BuckoVidLib.domain.UserWebSession;
70  import com.buckosoft.BuckoVidLib.util.ConfigManager;
71  
72  
73  
74  
75  
76  
77  
78  
79  public class UserFactory implements com.buckosoft.BSAccount.domain.UserFactory {
80  	protected final static boolean DEBUG = true;
81  	protected final Log log = LogFactory.getLog(getClass());
82  
83  
84  
85  
86  	@Autowired
87  	private BuckoVidLib		bvl;
88  
89  	
90  
91  
92  	public BSAccountUser getNewUser() {
93  		if (DEBUG)
94  			log.debug("getNewUser()");
95  		return(new User(null));
96  	}
97  
98  	
99  
100 
101 	public BSAccountUserWebSession getNewUserWebSession(BSAccountUser user) {
102 		log.debug("Create new session for \"" + user.getUsername() + "\"");
103 		return(new UserWebSession(user));
104 	}
105 
106 	
107 
108 
109 	public BSAccountUser getUser(BSAccount account) {
110 		User u = new User(account);
111 		if (account.isRegisteredUser()) {
112 			List<String>	admins = new ArrayList<String>();
113 			String s = ConfigManager.getString("BuckoVidLib.admins", null);
114 			if (s != null) {
115 				String[] ss = s.split(",");
116 				for (String t : ss) {
117 					admins.add(t.trim());
118 					log.debug("admins: " + t);
119 				}
120 				if (admins.contains(account.getUsername())) {
121 					u.setAdmin(true);
122 					u.setUnrestricted(true);
123 					log.info("Setting " + account.getUsername() + " to be an admin");
124 				}
125 			} else {
126 				log.warn("admins: none");
127 			}
128 			List<String>	rusers = new ArrayList<String>();
129 			s = ConfigManager.getString("BuckoVidLib.unrestrictedUsers", null);
130 			if (s != null) {
131 				String[] ss = s.split(",");
132 				for (String t : ss) {
133 					rusers.add(t.trim());
134 					log.debug("unrestricteds: " + t);
135 				}
136 				if (rusers.contains(account.getUsername())) {
137 					u.setUnrestricted(true);
138 					log.info("Setting " + account.getUsername() + " to be unrestricted");
139 				}
140 			} else {
141 				log.info("unrestrictedUsers: none");
142 			}
143 			u.setUserAttributes(bvl.getUserAttributes(u.getUserId()));
144 			if (log.isDebugEnabled()) {
145 				if (u.getUserAttributes() == null)
146 					log.debug("null userAttributes returned");
147 				else {
148 					for (UserAttribute ua : u.getUserAttributes())
149 						log.debug("UserAttribute: " + ua.getKey() + " / " + ua.getValue());
150 				}
151 			}
152 		}
153 		return(u);
154 	}
155 
156 }