1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ca.pjer.cm.module.access.defaultimpl;
19
20 import ca.pjer.cm.api.access.*;
21 import ca.pjer.cm.api.store.StoreService;
22 import ca.pjer.cm.api.store.StoreServiceSystemException;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.commons.logging.Log;
25
26 import java.util.List;
27
28 /***
29 * <br />
30 * $Id: AccessServiceImpl.java,v 1.1 2004/05/19 03:29:17 pjer Exp $<br />
31 * <br />
32 * $RCSfile: AccessServiceImpl.java,v $<br />
33 * $Revision: 1.1 $<br />
34 * $Author: pjer $<br />
35 * $Date: 2004/05/19 03:29:17 $<br />
36 *
37 * @TODO comment me.<br />
38 */
39 public class AccessServiceImpl implements AccessService {
40 private static final Log log = LogFactory.getLog(AccessServiceImpl.class);
41 private StoreService storeService;
42
43 public void setStoreService(StoreService storeService) {
44 this.storeService = storeService;
45 }
46
47 public AccessToken getAccessToken(AccessCredential accessCredential) throws AccessServiceSystemException, InvalidAccessCredentialException {
48 User templateUser = new User();
49 templateUser.setUsername(accessCredential.getUsername());
50 templateUser.setPassword(accessCredential.getPassword());
51 User user = null;
52 try {
53 List userList = storeService.listFromTemplate(templateUser);
54 if (userList.size() < 1) {
55 throw new InvalidAccessCredentialException("Could not found user.");
56 }
57 if (userList.size() > 1) {
58 throw new AccessServiceSystemException("More than one users match the credentials");
59 }
60 user = (User) userList.get(0);
61 } catch (StoreServiceSystemException e) {
62 String s = "Could not get access token : " + e.getMessage();
63 log.error(s);
64 throw new AccessServiceSystemException(s, e);
65 }
66 return new AccessTokenImpl(user.getId());
67 }
68
69 public boolean hasAccess(AccessToken accessToken, Permission permission, Class clazz) throws AccessServiceSystemException, InvalidAccessTokenException {
70 AccessTokenImpl accessTokenImpl = (AccessTokenImpl) accessToken;
71 return accessTokenImpl != null;
72 }
73 }