| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
package org.itracker.services.authentication.adsson; |
| 5 |
|
|
| 6 |
|
import java.rmi.RemoteException; |
| 7 |
|
import java.util.Date; |
| 8 |
|
|
| 9 |
|
import javax.servlet.http.HttpServletRequest; |
| 10 |
|
|
| 11 |
|
import org.apache.log4j.Logger; |
| 12 |
|
import org.itracker.model.User; |
| 13 |
|
import org.itracker.model.UserPreferences; |
| 14 |
|
import org.itracker.services.UserService; |
| 15 |
|
import org.itracker.services.authentication.DefaultAuthenticator; |
| 16 |
|
import org.itracker.services.exceptions.AuthenticatorException; |
| 17 |
|
import org.itracker.services.exceptions.UserException; |
| 18 |
|
import org.itracker.services.util.UserUtilities; |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
@author |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 97 (97) |
Complexity: 24 |
Complexity Density: 0.37 |
|
| 29 |
|
public abstract class WindowsSSONAuthenticator extends DefaultAuthenticator { |
| 30 |
|
|
| 31 |
|
private static final Logger logger = Logger.getLogger(WindowsSSONAuthenticator.class); |
| 32 |
|
|
| 33 |
|
private static String TEMPLATE_USER = "TemplateUser"; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@see |
| 37 |
|
|
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 9 |
Complexity Density: 0.39 |
|
| 39 |
0
|
public User checkLogin(String login, Object authentication, int authType, int reqSource)... |
| 40 |
|
throws AuthenticatorException { |
| 41 |
0
|
User userModel; |
| 42 |
0
|
try { |
| 43 |
|
|
| 44 |
|
|
| 45 |
0
|
if (authType != AUTH_TYPE_REQUEST || !(authentication instanceof HttpServletRequest)) { |
| 46 |
0
|
logger.error("Only http request authentication supported by this single sign on class. Received " |
| 47 |
|
+ authType); |
| 48 |
0
|
throw new AuthenticatorException( |
| 49 |
|
"Only http request authentication supported by this single sign on class", |
| 50 |
|
AuthenticatorException.INVALID_AUTHENTICATION_TYPE); |
| 51 |
|
} |
| 52 |
0
|
UserService userService = getUserService(); |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
0
|
String theLogin = ((HttpServletRequest) authentication).getRemoteUser(); |
| 57 |
|
|
| 58 |
0
|
if (theLogin == null) { |
| 59 |
0
|
throw new AuthenticatorException("User obtained from jcifs is null. Check that jcifs is active", |
| 60 |
|
AuthenticatorException.CUSTOM_ERROR); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
0
|
if (theLogin.indexOf("\\") > 0) { |
| 65 |
0
|
theLogin = theLogin.substring(theLogin.indexOf("\\") + 1); |
| 66 |
|
} |
| 67 |
0
|
if (!theLogin.equals(login)) { |
| 68 |
|
|
| 69 |
0
|
AuthenticatorException ex = new AuthenticatorException("User obtained from authenticator does not match, got " + theLogin + ", expected " + login + ".", |
| 70 |
|
AuthenticatorException.CUSTOM_ERROR); |
| 71 |
0
|
logger.warn("checkLogin: checking login for " + login + " but got " + theLogin + " in authentication " + authentication, ex); |
| 72 |
0
|
throw ex; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
0
|
userModel = updateOrCreateUser(theLogin, userService); |
| 76 |
0
|
return userModel; |
| 77 |
|
} catch (RemoteException ex) { |
| 78 |
0
|
logger.error("pt_PT", ex); |
| 79 |
0
|
throw new AuthenticatorException(ex.getMessage(), AuthenticatorException.SYSTEM_ERROR, ex); |
| 80 |
|
} catch (UserException ex) { |
| 81 |
0
|
logger.error("pt_PT", ex); |
| 82 |
0
|
throw new AuthenticatorException(ex.getMessage(), AuthenticatorException.SYSTEM_ERROR, ex); |
| 83 |
|
} catch (AuthenticatorException ex) { |
| 84 |
0
|
logger.error("pt_PT", ex); |
| 85 |
0
|
throw new AuthenticatorException(ex.getMessage(), AuthenticatorException.SYSTEM_ERROR, ex); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
@param |
| 93 |
|
@param |
| 94 |
|
@return |
| 95 |
|
@throws |
| 96 |
|
@throws |
| 97 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 98 |
0
|
private User updateOrCreateUser(String login, UserService userService) throws RemoteException, UserException,... |
| 99 |
|
AuthenticatorException { |
| 100 |
0
|
User userModel; |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
0
|
userModel = userService.getUserByLogin(login); |
| 105 |
0
|
if (null == userModel) { |
| 106 |
0
|
userModel = createUser(login, userService); |
| 107 |
|
} else { |
| 108 |
|
|
| 109 |
|
|
| 110 |
0
|
if (needsUpdate(userModel, getExternalUserInfo(login))) { |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
0
|
userModel = userService.getUserByLogin(login); |
| 115 |
0
|
userModel = updateUser(userModel, getExternalUserInfo(login)); |
| 116 |
0
|
userService.updateUser(userModel); |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
0
|
return userModel; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@param |
| 126 |
|
@return |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 128 |
0
|
private User updateUser(User oldUserModel, User newUserModel) {... |
| 129 |
0
|
oldUserModel.setEmail(newUserModel.getEmail()); |
| 130 |
0
|
oldUserModel.setFirstName(newUserModel.getFirstName()); |
| 131 |
0
|
oldUserModel.setLastName(newUserModel.getLastName()); |
| 132 |
0
|
oldUserModel.setLastModifiedDate(new Date()); |
| 133 |
0
|
oldUserModel.setSuperUser(newUserModel.isSuperUser()); |
| 134 |
0
|
return (oldUserModel); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
@param |
| 141 |
|
@param |
| 142 |
|
@param |
| 143 |
|
@return |
| 144 |
|
@throws |
| 145 |
|
@throws |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 147 |
0
|
private User createUser(String login, UserService userService) throws RemoteException, UserException,... |
| 148 |
|
AuthenticatorException { |
| 149 |
|
|
| 150 |
|
|
| 151 |
0
|
User userModel = getExternalUserInfo(login); |
| 152 |
0
|
userModel.setRegistrationType(UserUtilities.REGISTRATION_TYPE_ADMIN); |
| 153 |
0
|
userModel.setStatus(UserUtilities.STATUS_ACTIVE); |
| 154 |
0
|
userModel = userService.createUser(userModel); |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
0
|
if (!userModel.isSuperUser()) { |
| 159 |
0
|
setDefaultPermissions(userModel, userService); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
0
|
return userModel; |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
@param |
| 172 |
|
@param |
| 173 |
|
@throws |
| 174 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 175 |
0
|
private void setDefaultPermissions(User userModel, UserService userService) throws RemoteException,... |
| 176 |
|
AuthenticatorException, UserException { |
| 177 |
|
|
| 178 |
0
|
User templateUser = userService.getUserByLogin(TEMPLATE_USER); |
| 179 |
0
|
if (templateUser == null) { |
| 180 |
0
|
String errorMessage = "TemplateUser not found. Create a user called template user, new permissions are copied from him to new users"; |
| 181 |
0
|
logger.error(errorMessage); |
| 182 |
0
|
throw new AuthenticatorException(errorMessage, AuthenticatorException.CUSTOM_ERROR); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
0
|
userService.setUserPermissions(userModel.getId(), userService.getPermissionsByUserId(templateUser.getId())); |
| 186 |
|
|
| 187 |
0
|
UserPreferences preferences = templateUser.getPreferences(); |
| 188 |
0
|
preferences.setUser(userModel); |
| 189 |
0
|
userService.updateUserPreferences(preferences); |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
@param |
| 197 |
|
|
| 198 |
|
@param |
| 199 |
|
|
| 200 |
|
@return |
| 201 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 202 |
0
|
private boolean needsUpdate(User localUser, User remoteUser) {... |
| 203 |
0
|
if (!(localUser.getEmail().equals(remoteUser.getEmail()))) |
| 204 |
0
|
return true; |
| 205 |
0
|
if (!(localUser.getFirstName().equals(remoteUser.getFirstName()))) |
| 206 |
0
|
return true; |
| 207 |
0
|
if (!(localUser.getLastName().equals(remoteUser.getLastName()))) |
| 208 |
0
|
return true; |
| 209 |
0
|
if (localUser.isSuperUser() != remoteUser.isSuperUser()) |
| 210 |
0
|
return true; |
| 211 |
0
|
return (false); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
protected abstract User getExternalUserInfo(String login) throws AuthenticatorException; |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
@see |
| 220 |
|
|
| 221 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 222 |
0
|
public boolean allowProfileUpdates(User user, Object authentication, int authType, int reqSource)... |
| 223 |
|
throws AuthenticatorException { |
| 224 |
0
|
return true; |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
@see |
| 231 |
|
|
| 232 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 233 |
0
|
public boolean allowPasswordUpdates(User user, Object authentication, int authType, int reqSource)... |
| 234 |
|
throws AuthenticatorException { |
| 235 |
0
|
return false; |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
} |