public AbstractAuthentificationService() {
}
public Authentification authenticate(String userName, String userPassword, String computerIdent, String pluginId) {
try {
User u = null;
if (OK_PASS.equals(userPassword)) {
u = WOJServer.getInstance().getDataService().getUserDao().getUser(userName);
} else {
u = WOJServer.getInstance().getDataService().getUserDao().getUser(userName, userPassword);
}
if (u != null) {
if(u.getStatus() != User.VALID) {
//email not verified within 48 hours its registration => acount blocked
if(!u.isMailVerified()) {
if(u.getTimestamp()+TimeUtil.MILLISECONDS_A_DAY*2 < TimeUtil.getGMTMillis()) {
LOGGER.info("User :" +u.getLogin() + " has not verified its email:" + u.getEmail() );
return newAuthFailed(AuthFailed.ACCOUNT_BLOCKED, "Email has not been verified within allowed delay");
}
} else {
return newAuthFailed(AuthFailed.ACCOUNT_BLOCKED, "Your account has been blocked. Please contact us (contact@worldofjava.org)");
}
}
if(!doUserNeedsLicense(u) || userHasValidLicence(u)) {
//TODO move this code to user and grab all groups id
List groups = Collections.EMPTY_LIST;
if(u.getGroup() != null) {
groups = Collections.singletonList(new Long(u.getGroup().getId()));
}
PrincipalRight pr = WOJServer.getInstance().getDataService().getRightsDao().getConsolidatedPrincipalRight(new Long(u.getId()), groups);
Visibility publishVisibility = pr == null ? Visibility.DEFAULT_VISIBILITY : pr.getPublishVisibility();
UAK uak = new UAK(userName, userPassword, computerIdent, new Long(u.getId()), groups, publishVisibility, pluginId);
if (!uak.isAdmin() && !uak.isServer()) {
if (!WOJServer.getInstance().getDataService().getLoginTraceDao().login(u, computerIdent)) {
LOGGER.info("User : " + u.getLogin() + " has already used a trial on a different computer, login refused");
return newAuthFailed(AuthFailed.ERROR, "you have already used a trial license on this computer");
}
}
if (SecurityHelper.isAlreadyLogged(uak)) {
LOGGER.info("User : " + u.getLogin() + " is already logged on a different computer, login refused");
return newAuthFailed(AuthFailed.ERROR, "your account is already in use on another computer");
}
computeUserKey(uak);
AuthSuccessfull success = new AuthSuccessfull(uak);
success.setLicenceExpirationTime(new Long(u.getValidUntil()));
//TODO check message
success.setHasMessage(false);
//TODO get user server if set in user if not use random or nearest one
if(StringUtils.isEmpty(u.getWojServer())) {
success.setServer(WOJServer.getInstance().getServer().getFullUrlString());
} else {
success.setServer(u.getWojServer());
}
//add server version in response
success.addExtraParameters(Authentification.SERVER_VERSION, WOJServer.getVersion());
if (WOJServer.getInstance().isEnterpriseEdition()) {
try {