1 43 package org.exolab.jms.authentication; 44 45 import java.security.Principal ; 46 47 import org.exolab.jms.service.BasicService; 48 import org.exolab.jms.service.ServiceException; 49 import org.exolab.jms.net.connector.Authenticator; 50 import org.exolab.jms.net.connector.ResourceException; 51 import org.exolab.jms.common.security.BasicPrincipal; 52 53 54 60 public class AuthenticationMgr extends BasicService implements Authenticator { 61 62 65 private UserManager _users; 66 67 70 private static final String AM_SERVICE_NAME = "AuthenticationManager"; 71 72 75 private static volatile AuthenticationMgr _instance; 76 77 78 83 private AuthenticationMgr() throws ServiceException { 84 super(AM_SERVICE_NAME); 85 _users = new UserManager(); 86 } 87 88 94 public static AuthenticationMgr createInstance() throws ServiceException { 95 _instance = new AuthenticationMgr(); 96 return _instance; 97 } 98 99 106 public static AuthenticationMgr instance() { 107 return _instance; 108 } 109 110 public void run() { 112 } 114 115 public void stop() throws ServiceException { 117 _users.destroy(); 119 120 _instance = null; 122 } 123 124 131 public boolean addUser(User user) { 132 return _users.createUser(user); 133 } 134 135 142 public boolean removeUser(User user) { 143 return _users.deleteUser(user); 144 } 145 146 152 public User getUser(User user) { 153 return _users.getUser(user); 154 } 155 156 163 public boolean updateUser(User user) { 164 return _users.updateUser(user); 165 } 166 167 175 public boolean validateUser(String username, String password) { 176 return _users.validateUser(username, password); 177 } 178 179 185 public boolean authenticate(Principal principal) { 186 String user = null; 187 String password = null; 188 if (principal instanceof BasicPrincipal) { 189 BasicPrincipal basic = (BasicPrincipal) principal; 190 user = basic.getName(); 191 password = basic.getPassword(); 192 } else { 193 } 195 return validateUser(user, password); 196 } 197 } 198 | Popular Tags |