| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.authentication; |
| 20 |
|
|
| 21 |
|
import java.util.ArrayList; |
| 22 |
|
import java.util.HashMap; |
| 23 |
|
import java.util.List; |
| 24 |
|
import java.util.Map; |
| 25 |
|
|
| 26 |
|
import org.apache.log4j.Logger; |
| 27 |
|
import org.itracker.model.Permission; |
| 28 |
|
import org.itracker.model.User; |
| 29 |
|
import org.itracker.services.exceptions.AuthenticatorException; |
| 30 |
|
import org.itracker.services.exceptions.PasswordException; |
| 31 |
|
import org.itracker.services.exceptions.UserException; |
| 32 |
|
import org.itracker.services.util.UserUtilities; |
| 33 |
|
import org.jfree.util.Log; |
| 34 |
|
import org.springframework.dao.DataAccessException; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
|
|
|
| 0% |
Uncovered Elements: 139 (139) |
Complexity: 44 |
Complexity Density: 0.47 |
|
| 42 |
|
public class DefaultAuthenticator extends AbstractPluggableAuthenticator { |
| 43 |
|
|
| 44 |
|
private static final Logger logger = Logger.getLogger(DefaultAuthenticator.class); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@param |
| 51 |
|
@param |
| 52 |
|
@param |
| 53 |
|
@param |
| 54 |
|
@return |
| 55 |
|
@throws |
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 67 (67) |
Complexity: 20 |
Complexity Density: 0.43 |
|
| 57 |
0
|
public User checkLogin(final String login, final Object authentication, final int authType, final int reqSource) throws AuthenticatorException {... |
| 58 |
0
|
if (logger.isDebugEnabled()) { |
| 59 |
0
|
logger.debug("Checking login for " + login + " using DefaultAuthenticator"); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
0
|
if (login != null && authentication != null && !login.equals("")) { |
| 63 |
0
|
User user; |
| 64 |
0
|
try { |
| 65 |
0
|
user = getUserService().getUserByLogin(login); |
| 66 |
|
} catch (DataAccessException e) { |
| 67 |
0
|
logger.error("checkLogin: failed to get user by login: " + login, e); |
| 68 |
0
|
throw new AuthenticatorException(AuthenticatorException.UNKNOWN_USER, e.getMessage()); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
0
|
if (user.getStatus() != UserUtilities.STATUS_ACTIVE) { |
| 77 |
0
|
AuthenticatorException e = new AuthenticatorException(AuthenticatorException.INACTIVE_ACCOUNT); |
| 78 |
0
|
logger.info("checkLogin: user is inactive, user: " + user, e); |
| 79 |
0
|
throw e; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
0
|
String userPassword; |
| 83 |
0
|
try { |
| 84 |
0
|
userPassword = getUserService().getUserPasswordByLogin(login); |
| 85 |
|
} catch (DataAccessException e) { |
| 86 |
0
|
AuthenticatorException ex = new AuthenticatorException(e.getMessage(), authType); |
| 87 |
0
|
logger.info("checkLogin: user is inactive, user: " + user, ex); |
| 88 |
0
|
throw e; |
| 89 |
|
} |
| 90 |
0
|
if (userPassword == null || userPassword.equals("")) { |
| 91 |
0
|
AuthenticatorException e = new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); |
| 92 |
0
|
logger.info("checkLogin: user has no password, user: " + user, e); |
| 93 |
0
|
throw e; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
0
|
try { |
| 97 |
0
|
if (!userPassword.endsWith("=")) { |
| 98 |
0
|
logger.info("checkLogin: User " + login + " has old style password. Converting to SHA1 hash."); |
| 99 |
0
|
try { |
| 100 |
0
|
user.setPassword(UserUtilities.encryptPassword(userPassword)); |
| 101 |
0
|
getUserService().updateUser(user); |
| 102 |
|
} catch (UserException ue) { |
| 103 |
0
|
logger.error("checkLogin: User password conversion failed for user " + user, ue); |
| 104 |
0
|
throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| 108 |
0
|
if (authType == AUTH_TYPE_PASSWORD_PLAIN) { |
| 109 |
0
|
if (!userPassword.equals(UserUtilities.encryptPassword((String) authentication))) { |
| 110 |
0
|
throw new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); |
| 111 |
|
} |
| 112 |
0
|
} else if (authType == AUTH_TYPE_PASSWORD_ENC) { |
| 113 |
0
|
if (!userPassword.equals(authentication)) { |
| 114 |
0
|
throw new AuthenticatorException(AuthenticatorException.INVALID_PASSWORD); |
| 115 |
|
} |
| 116 |
|
} else { |
| 117 |
0
|
logger.info("checkLogin: invalid authenticator type: " + authType); |
| 118 |
0
|
throw new AuthenticatorException(AuthenticatorException.INVALID_AUTHENTICATION_TYPE); |
| 119 |
|
} |
| 120 |
|
} catch (ClassCastException cce) { |
| 121 |
0
|
logger.error("checkLogin: Authenticator was of wrong type.", cce); |
| 122 |
0
|
throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); |
| 123 |
|
} catch (PasswordException pe) { |
| 124 |
0
|
throw new AuthenticatorException(AuthenticatorException.SYSTEM_ERROR); |
| 125 |
|
} catch (AuthenticatorException ae) { |
| 126 |
0
|
if (logger.isDebugEnabled()) { |
| 127 |
0
|
logger.debug("checkLogin: failed to authenticate " + login, ae); |
| 128 |
|
} |
| 129 |
0
|
throw ae; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
0
|
return user; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
0
|
Log.info("checkLogin: no login was supplied: " + login + ", type: " + authType + ", source: " + reqSource); |
| 136 |
0
|
throw new AuthenticatorException(AuthenticatorException.INVALID_DATA); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@param |
| 143 |
|
@param |
| 144 |
|
@return |
| 145 |
|
@throws |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 147 |
0
|
public List<Permission> getUserPermissions(User user, int reqSource) throws AuthenticatorException {... |
| 148 |
0
|
if (user == null || user.getId() == null) { |
| 149 |
0
|
throw new AuthenticatorException(AuthenticatorException.INVALID_DATA); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
0
|
List<Permission> permissionList; |
| 153 |
0
|
try { |
| 154 |
0
|
permissionList = getUserService().getUserPermissionsLocal(user); |
| 155 |
|
} catch (DataAccessException e) { |
| 156 |
0
|
throw new AuthenticatorException(e.getMessage(), reqSource); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
0
|
if (user.isSuperUser()) { |
| 160 |
0
|
List<Permission> augmentedPermissions = new ArrayList<Permission>(); |
| 161 |
|
|
| 162 |
|
|
| 163 |
0
|
Permission permission = new Permission(-1, user, null); |
| 164 |
0
|
augmentedPermissions.add(permission); |
| 165 |
0
|
augmentedPermissions.addAll(permissionList); |
| 166 |
0
|
return augmentedPermissions; |
| 167 |
|
|
| 168 |
|
} else { |
| 169 |
0
|
return permissionList; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@param |
| 178 |
|
@param |
| 179 |
|
@param |
| 180 |
|
@param |
| 181 |
|
@param |
| 182 |
|
@return |
| 183 |
|
@throws |
| 184 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 11 |
Complexity Density: 0.42 |
|
| 185 |
0
|
public List<User> getUsersWithProjectPermission(Integer projectId,... |
| 186 |
|
int[] permissionTypes, |
| 187 |
|
boolean requireAll, |
| 188 |
|
boolean activeOnly, |
| 189 |
|
int reqSource) |
| 190 |
|
throws AuthenticatorException { |
| 191 |
|
|
| 192 |
0
|
List<User> users; |
| 193 |
|
|
| 194 |
0
|
try { |
| 195 |
0
|
Map<Integer, User> userMap = new HashMap<Integer, User>(); |
| 196 |
|
|
| 197 |
0
|
if (requireAll) { |
| 198 |
|
|
| 199 |
0
|
Integer[] types = new Integer[permissionTypes.length]; |
| 200 |
0
|
for (int i = 0; i < types.length; i++) { |
| 201 |
0
|
types[i] = permissionTypes[i]; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
0
|
List<User> explicitUsers = getUserService().findUsersForProjectByPermissionTypeList(projectId, types); |
| 205 |
|
|
| 206 |
0
|
for (User user : explicitUsers) { |
| 207 |
0
|
userMap.put(user.getId(), user); |
| 208 |
|
} |
| 209 |
|
} else { |
| 210 |
|
|
| 211 |
0
|
for (int i = 0; i < permissionTypes.length; i++) { |
| 212 |
0
|
List<User> explicitUsers = getUserService().getUsersWithPermissionLocal(projectId, permissionTypes[i]); |
| 213 |
|
|
| 214 |
0
|
for (User user : explicitUsers) { |
| 215 |
0
|
userMap.put(user.getId(), user); |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
} |
| 219 |
|
|
| 220 |
|
} |
| 221 |
|
|
| 222 |
0
|
List<User> superUsers = getUserService().getSuperUsers(); |
| 223 |
0
|
for (User superUser : superUsers) { |
| 224 |
0
|
userMap.put(superUser.getId(), superUser); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
0
|
users = new ArrayList<User>(); |
| 228 |
0
|
for (User user : userMap.values()) { |
| 229 |
0
|
if (activeOnly) { |
| 230 |
0
|
if (user.getStatus() == UserUtilities.STATUS_ACTIVE) { |
| 231 |
0
|
users.add(user); |
| 232 |
|
} |
| 233 |
|
} else { |
| 234 |
0
|
users.add(user); |
| 235 |
|
} |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
} catch (Exception e) { |
| 239 |
0
|
logger.error("Error retreiving users with permissions.", e); |
| 240 |
0
|
throw new AuthenticatorException(); |
| 241 |
|
} |
| 242 |
|
|
| 243 |
0
|
return users; |
| 244 |
|
|
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
@param |
| 251 |
|
@param |
| 252 |
|
@param |
| 253 |
|
@param |
| 254 |
|
@return |
| 255 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 256 |
0
|
public boolean allowRegistration(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 257 |
0
|
return true; |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
|
|
| 263 |
|
|
| 264 |
|
@param |
| 265 |
|
@param |
| 266 |
|
@param |
| 267 |
|
@return |
| 268 |
|
@throws |
| 269 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 270 |
0
|
public boolean allowProfileCreation(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 271 |
0
|
return true; |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| 277 |
|
@param |
| 278 |
|
@param |
| 279 |
|
@param |
| 280 |
|
@param |
| 281 |
|
@return |
| 282 |
|
@throws |
| 283 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 284 |
0
|
public boolean allowProfileUpdates(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 285 |
0
|
return true; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
|
@param |
| 292 |
|
@param |
| 293 |
|
@param |
| 294 |
|
@param |
| 295 |
|
@return |
| 296 |
|
@throws |
| 297 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 298 |
0
|
public boolean allowPasswordUpdates(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 299 |
0
|
return true; |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
@param |
| 306 |
|
@param |
| 307 |
|
@param |
| 308 |
|
@param |
| 309 |
|
@return |
| 310 |
|
@throws |
| 311 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 312 |
0
|
public boolean allowPermissionUpdates(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 313 |
0
|
return true; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
|
@param |
| 320 |
|
@param |
| 321 |
|
@param |
| 322 |
|
@param |
| 323 |
|
@return |
| 324 |
|
@throws |
| 325 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 326 |
0
|
public boolean allowPreferenceUpdates(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 327 |
0
|
return true; |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 331 |
|
|
| 332 |
|
|
| 333 |
|
@param |
| 334 |
|
@param |
| 335 |
|
@param |
| 336 |
|
@param |
| 337 |
|
@return |
| 338 |
|
@throws |
| 339 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 340 |
0
|
public boolean createProfile(User user, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 341 |
0
|
return false; |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
|
|
| 347 |
|
@param |
| 348 |
|
@param |
| 349 |
|
@param |
| 350 |
|
@param |
| 351 |
|
@param |
| 352 |
|
@return |
| 353 |
|
@throws |
| 354 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 355 |
0
|
public boolean updateProfile(User user, int updateType, Object authentication, int authType, int reqSource) throws AuthenticatorException {... |
| 356 |
0
|
return false; |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
} |