diff --git a/src/main/java/de/bps/onyx/plugin/OnyxModule.java b/src/main/java/de/bps/onyx/plugin/OnyxModule.java index 5d139dd13842933f796d39d8ddbbe89659993bd1..05274a14e2ab535976d5aea99a340953e713ddf9 100644 --- a/src/main/java/de/bps/onyx/plugin/OnyxModule.java +++ b/src/main/java/de/bps/onyx/plugin/OnyxModule.java @@ -236,7 +236,7 @@ public class OnyxModule extends AbstractOLATModule implements ConfigOnOff { } } catch(NoSuchFileException nsfe) { eval.setValid(false); - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); eval.setValid(false); } finally { diff --git a/src/main/java/org/olat/admin/user/UserCreateController.java b/src/main/java/org/olat/admin/user/UserCreateController.java index 7eb26007e3f9355ae43844d763cc18c2b2a47f5a..c2f394da1eef275ccc15249076a17162ec091b26 100644 --- a/src/main/java/org/olat/admin/user/UserCreateController.java +++ b/src/main/java/org/olat/admin/user/UserCreateController.java @@ -28,7 +28,6 @@ package org.olat.admin.user; import java.util.List; import java.util.Map; -import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.Constants; @@ -63,6 +62,7 @@ import org.olat.core.util.resource.OresHelper; import org.olat.user.ChangePasswordForm; import org.olat.user.UserManager; import org.olat.user.propertyhandlers.UserPropertyHandler; +import org.springframework.beans.factory.annotation.Autowired; /** * Initial Date: Jul 31, 2003 @@ -154,6 +154,9 @@ class NewUserForm extends FormBasicController { private TextElement psw2TextElement; private SingleSelection languageSingleSelection; private SelectionElement authCheckbox; + + @Autowired + private BaseSecurity securityManager; /** * @@ -343,7 +346,7 @@ class NewUserForm extends FormBasicController { newUser.getPreferences().setLanguage(lang); newUser.getPreferences().setInformSessionTimeout(true); // Save everything in database - Identity ident = AuthHelper.createAndPersistIdentityAndUserWithUserGroup(username, null, pwd, newUser); + Identity ident = securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(username, null, pwd, newUser); return ident; } diff --git a/src/main/java/org/olat/admin/user/imp/ImportStep00.java b/src/main/java/org/olat/admin/user/imp/ImportStep00.java index 4fbf0fa58ec3707f939507ed55e4366fb23c4ce9..1cfcc5b3a73fd1597fa9ad46af04d091643b295b 100644 --- a/src/main/java/org/olat/admin/user/imp/ImportStep00.java +++ b/src/main/java/org/olat/admin/user/imp/ImportStep00.java @@ -34,6 +34,8 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; +import org.olat.basesecurity.Authentication; +import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.dispatcher.mapper.Mapper; @@ -60,9 +62,11 @@ import org.olat.core.util.i18n.I18nManager; import org.olat.core.util.i18n.I18nModule; import org.olat.registration.RegistrationManager; import org.olat.registration.TemporaryKey; +import org.olat.shibboleth.ShibbolethDispatcher; import org.olat.shibboleth.ShibbolethModule; import org.olat.user.UserManager; import org.olat.user.propertyhandlers.UserPropertyHandler; +import org.springframework.beans.factory.annotation.Autowired; import com.thoughtworks.xstream.XStream; @@ -115,12 +119,14 @@ class ImportStep00 extends BasicStep { private List<TransientIdentity> newIdents; private List<UserPropertyHandler> userPropertyHandlers; - private final UserManager um; + @Autowired + private UserManager um; + @Autowired + private BaseSecurity securityManager; public ImportStepForm00(UserRequest ureq, WindowControl control, Form rootForm, StepsRunContext runContext) { super(ureq, control, rootForm, runContext, LAYOUT_VERTICAL, null); flc.setTranslator(getTranslator()); - um = UserManager.getInstance(); initForm(ureq); } @@ -213,9 +219,17 @@ class ImportStep00 extends BasicStep { if (parts.length > columnId) { pwd = parts[columnId].trim(); if (StringHelper.containsNonWhitespace(pwd)) { - if(pwd.startsWith(UserImportController.SHIBBOLETH_MARKER) - && ShibbolethModule.isEnableShibbolethLogins()) { - //something to check? + if(pwd.startsWith(UserImportController.SHIBBOLETH_MARKER) && ShibbolethModule.isEnableShibbolethLogins()) { + String authusername = pwd.substring(UserImportController.SHIBBOLETH_MARKER.length()); + Authentication auth = securityManager.findAuthenticationByAuthusername(authusername, ShibbolethDispatcher.PROVIDER_SHIB); + if(auth != null) { + String authLogin = auth.getIdentity().getName(); + if(!login.equals(authLogin)) { + textAreaElement.setErrorKey("error.shibbolet.name.inuse", new String[] { String.valueOf(i + 1), authusername }); + importDataError = true; + break; + } + } } else if (!UserManager.getInstance().syntaxCheckOlatPassword(pwd)) { textAreaElement.setErrorKey("error.pwd", new String[] { String.valueOf(i + 1), pwd }); importDataError = true; diff --git a/src/main/java/org/olat/admin/user/imp/UserImportController.java b/src/main/java/org/olat/admin/user/imp/UserImportController.java index fd0a7ead0875f3a73902eae3ba9c25ec229ddb42..42e5414513731d1c0f466aad71dc8ea44156ed26 100644 --- a/src/main/java/org/olat/admin/user/imp/UserImportController.java +++ b/src/main/java/org/olat/admin/user/imp/UserImportController.java @@ -32,10 +32,8 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.Authentication; import org.olat.basesecurity.BaseSecurity; -import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.UserRequest; @@ -62,6 +60,7 @@ import org.olat.shibboleth.ShibbolethDispatcher; import org.olat.shibboleth.ShibbolethModule; import org.olat.user.UserManager; import org.olat.user.propertyhandlers.UserPropertyHandler; +import org.springframework.beans.factory.annotation.Autowired; /** * Description:<br> @@ -84,12 +83,17 @@ public class UserImportController extends BasicController { private Link startLink; private StepsMainRunController importStepsController; - - private final BaseSecurity securityManager; - private final OLATAuthManager olatAuthManager; - private final BusinessGroupService businessGroupService; - private final UserManager um; - private final DB dbInstance; + + @Autowired + private DB dbInstance; + @Autowired + private UserManager um; + @Autowired + private BaseSecurity securityManager; + @Autowired + private OLATAuthManager olatAuthManager; + @Autowired + private BusinessGroupService businessGroupService; /** * @param ureq @@ -99,11 +103,6 @@ public class UserImportController extends BasicController { */ public UserImportController(UserRequest ureq, WindowControl wControl, boolean canCreateOLATPassword) { super(ureq, wControl); - um = UserManager.getInstance(); - dbInstance = CoreSpringFactory.getImpl(DB.class); - securityManager = CoreSpringFactory.getImpl(BaseSecurity.class); - olatAuthManager = CoreSpringFactory.getImpl(OLATAuthManager.class); - businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.canCreateOLATPassword = canCreateOLATPassword; mainVC = createVelocityContainer("importindex"); startLink = LinkFactory.createButton("import.start", mainVC, this); @@ -173,11 +172,11 @@ public class UserImportController extends BasicController { Identity ident; if(pwd != null && pwd.startsWith(SHIBBOLETH_MARKER) && ShibbolethModule.isEnableShibbolethLogins()) { String uniqueID = pwd.substring(SHIBBOLETH_MARKER.length()); - ident = AuthHelper.createAndPersistIdentityAndUserWithUserGroup(login, ShibbolethDispatcher.PROVIDER_SHIB, uniqueID, newUser); + ident = securityManager.createAndPersistIdentityAndUserWithUserGroup(login, null, ShibbolethDispatcher.PROVIDER_SHIB, uniqueID, newUser); report.incrementCreatedUser(); report.incrementUpdatedShibboletAuthentication(); } else { - ident = AuthHelper.createAndPersistIdentityAndUserWithUserGroup(login, null, pwd, newUser); + ident = securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(login, null, pwd, newUser); report.incrementCreatedUser(); } return ident; @@ -221,23 +220,27 @@ public class UserImportController extends BasicController { return userToUpdate.getIdentity(); } - /** - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) - */ + @Override protected void doDispose() { // child controllers disposed by basic controller } @Override protected void event(UserRequest ureq, Component source, Event event) { - if (source == startLink){ + if (source == startLink) { + doOpenImportWizard(ureq); + } + } + + private void doOpenImportWizard(UserRequest ureq) { // use fallback translator for user property translation setTranslator(um.getPropertyHandlerTranslator(getTranslator())); userPropertyHandlers = um.getUserPropertyHandlersFor(usageIdentifyer, true); - + Step start = new ImportStep00(ureq, canCreateOLATPassword); // callback executed in case wizard is finished. StepRunnerCallback finish = new StepRunnerCallback() { + @Override public Step execute(UserRequest ureq1, WindowControl wControl1, StepsRunContext runContext) { // all information to do now is within the runContext saved ImportReport report = new ImportReport(); @@ -293,10 +296,9 @@ public class UserImportController extends BasicController { }; importStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, - translate("title"), "o_sel_user_import_wizard"); + translate("title"), "o_sel_user_import_wizard"); listenTo(importStepsController); - getWindowControl().pushAsModalDialog(importStepsController.getInitialComponent()); - } + getWindowControl().pushAsModalDialog(importStepsController.getInitialComponent()); } private Collection<Identity> getIdentities(List<Identity> allIdents) { @@ -376,7 +378,10 @@ public class UserImportController extends BasicController { } public void addError(String error) { - errors.add(error); + if(StringHelper.containsNonWhitespace(error)) { + errors.add(error); + hasErrors = true; + } } public int getNumOfUpdatedUser() { diff --git a/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_de.properties index 10076212197875f9d55cfa72dd78860dd6c476c9..90b46a6566da54dc72ef3293d7b4b10f89ab59de 100644 --- a/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_de.properties @@ -12,6 +12,7 @@ error.login=Fehler auf Zeile {0}\: der Benutzername "{1}" entspricht nicht den O error.login.douplicate=Fehler auf Zeile {0}\: Der Benutzername "{1}" ist mehrfach in der Liste vorhanden, sollte jedoch einmalig sein. error.mandatory=Fehler auf Zeile {0}\: die Angabe von "{1}" ist obligatorisch. error.pwd=Fehler auf Zeile {0}\: das Passwort "{1}" entspricht nicht den OLAT-Konventionen. Bitte \u00E4ndern Sie dieses Passwort. +error.shibbolet.name.inuse=Fehler auf Zeile {0}\: dieser Shibboleth-Identifikator "{1}" wird bereits in einem bestehenden Konto benutzt. form.importdata=Kopierte Zeilen aus Excel formatexplanation.part1=Benutzen Sie Excel (oder OpenOffice) gem\u00E4ss untenstehender Abbildung (Auf Beispielabbildung klicken).<br><ul> formatexplanation.part2.cancreatepassword=Benutzername *, Passwort, Sprache{0}.</li><li>Wenn das Feld "Passwort" leer gelassen wird, m\u00FCssen Sie dem Benutzer sp\u00E4ter ein Passwort setzen.</li> diff --git a/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_en.properties index 2e0c60e02679a367d551e6b7986e079a40cc9d7f..c53eca5f144a04c1188ace32e807c7e278313505 100644 --- a/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/admin/user/imp/_i18n/LocalStrings_en.properties @@ -12,6 +12,7 @@ error.login=Error in line {0}\: the user name "{1}" does not follow OLAT convent error.login.douplicate=Error in line {0}\: The user name "{1}" has been found at least twice but needs to be unique. error.mandatory=Error in line {0}\: the attribute "{1}" is mandatory. error.pwd=Error in line {0}\: the password "{1}" does not follow OLAT conventions. Please change this password. +error.shibbolet.name.inuse=Error in line {0}\: this shibboleth identifier "{1}" is already in use in an existing account. form.importdata=Copied rows from Excel formatexplanation.conventions=Rules for username and password\: formatexplanation.part1=Use Excel (or OpenOffice) according to the image below (click on example).<br><ul> diff --git a/src/main/java/org/olat/basesecurity/AuthHelper.java b/src/main/java/org/olat/basesecurity/AuthHelper.java index 8d6d7c579dab4b6a2bb5c4d85590779c585021ae..ec1fa4036e4684fae3b6e68b74a98edbfe31ae3c 100644 --- a/src/main/java/org/olat/basesecurity/AuthHelper.java +++ b/src/main/java/org/olat/basesecurity/AuthHelper.java @@ -54,7 +54,6 @@ import org.olat.core.gui.render.StringOutput; import org.olat.core.gui.render.URLBuilder; import org.olat.core.id.Identity; import org.olat.core.id.Roles; -import org.olat.core.id.User; import org.olat.core.id.UserConstants; import org.olat.core.logging.AssertException; import org.olat.core.logging.OLog; @@ -340,67 +339,6 @@ public class AuthHelper { return LOGIN_OK; } - /** - * Persists the given user and creates an identity for it - * - * @param loginName - * @param pwd null: no OLAT authentication is generated. If not null, the password will be - * encrypted and and an OLAT authentication is generated. - * @param newUser unpersisted user - * @return Identity - */ - private static Identity createAndPersistIdentityAndUser(String loginName, String externalId, String pwd, User newUser) { - Identity ident = null; - if (pwd == null) { - // when no password is used the provider must be set to null to not generate - // an OLAT authentication token. See method doku. - ident = BaseSecurityManager.getInstance().createAndPersistIdentityAndUser(loginName, externalId, newUser, null, null); - } else { - ident = BaseSecurityManager.getInstance().createAndPersistIdentityAndUser(loginName, externalId, newUser, - BaseSecurityModule.getDefaultAuthProviderIdentifier(), loginName, pwd); - } - // TODO: Tracing message - return ident; - } - - /** - * Persists the given user, creates an identity for it and adds the user to - * the users system group - * - * @param loginName - * @param pwd null: no OLAT authentication is generated. If not null, the password will be - * encrypted and and an OLAT authentication is generated. - * @param newUser unpersisted users - * @return Identity - */ - public static Identity createAndPersistIdentityAndUserWithUserGroup(String loginName, String externalId, String pwd, User newUser) { - Identity ident = createAndPersistIdentityAndUser(loginName, externalId, pwd, newUser); - // Add user to system users group - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS); - securityManager.addIdentityToSecurityGroup(ident, olatuserGroup); - return ident; - } - - /** - * Persists the given user, creates an identity for it and adds the user to - * the users system group, create an authentication for an external provider - * - * @param loginName - * @param provider - * @param authusername - * @param newUser - * @return - */ - public static Identity createAndPersistIdentityAndUserWithUserGroup(String loginName, String externalId, String provider, String authusername, User newUser) { - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - Identity ident = securityManager.createAndPersistIdentityAndUser(loginName, externalId, newUser, provider, authusername, null); - // Add user to system users group - SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS); - securityManager.addIdentityToSecurityGroup(ident, olatuserGroup); - return ident; - } - /** * This is a convenience method to log out. IMPORTANT: This method initiates a * redirect and RETURN. Make sure you return the call hierarchy gracefully. diff --git a/src/main/java/org/olat/basesecurity/BaseSecurity.java b/src/main/java/org/olat/basesecurity/BaseSecurity.java index 3b99666aaf17df8b873e148fee3840e5fbac86fb..393a9313e483c0e8b8dbdc63d0668691a1620130 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurity.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurity.java @@ -301,6 +301,33 @@ public interface BaseSecurity { * @return the new identity */ public Identity createAndPersistIdentityAndUser(String username, String externalId, User user, String provider, String authusername, String password); + + /** + * Persists the given user, creates an identity for it and adds the user to + * the users system group + * + * @param loginName + * @param externalId + * @param pwd null: no OLAT authentication is generated. If not null, the password will be + * encrypted and and an OLAT authentication is generated. + * @param newUser unpersisted users + * @return Identity + */ + public Identity createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(String loginName, String externalId, String pwd, User newUser); + + /** + * Persists the given user, creates an identity for it and adds the user to + * the users system group, create an authentication for an external provider + * + * @param loginName + * @param externalId + * @param provider + * @param authusername + * @param newUser + * @return + */ + public Identity createAndPersistIdentityAndUserWithUserGroup(String loginName, String externalId, String provider, String authusername, User newUser); + /** * Return the List of associated Authentications. diff --git a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java index 24524011d02ec2dab44b1675501b76643bc29b45..367eebf1e2b3c8d9edb1e309483b2fdfdaa5d232 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java @@ -58,7 +58,8 @@ import org.olat.core.id.Roles; import org.olat.core.id.User; import org.olat.core.id.UserConstants; import org.olat.core.logging.AssertException; -import org.olat.core.manager.BasicManager; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; import org.olat.core.util.Encoder; import org.olat.core.util.Encoder.Algorithm; import org.olat.core.util.Util; @@ -82,7 +83,10 @@ import org.olat.user.UserManager; * * @author Felix Jost, Florian Gnaegi */ -public class BaseSecurityManager extends BasicManager implements BaseSecurity { +public class BaseSecurityManager implements BaseSecurity { + + private static final OLog log = Tracing.createLoggerFor(BaseSecurityManager.class); + private DB dbInstance; private LoginModule loginModule; private OLATResourceManager orm; @@ -452,11 +456,11 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { if (!hasBeenInGroup && isNowInGroup) { // user not yet in security group, add him addIdentityToSecurityGroup(updatedIdentity, securityGroup); - logAudit("User::" + (actingIdentity == null ? "unkown" : actingIdentity.getName()) + " added system role::" + groupName + " to user::" + updatedIdentity.getName(), null); + log.audit("User::" + (actingIdentity == null ? "unkown" : actingIdentity.getName()) + " added system role::" + groupName + " to user::" + updatedIdentity.getName(), null); } else if (hasBeenInGroup && !isNowInGroup) { // user not anymore in security group, remove him removeIdentityFromSecurityGroup(updatedIdentity, securityGroup); - logAudit("User::" + (actingIdentity == null ? "unkown" : actingIdentity.getName()) + " removed system role::" + groupName + " from user::" + updatedIdentity.getName(), null); + log.audit("User::" + (actingIdentity == null ? "unkown" : actingIdentity.getName()) + " removed system role::" + groupName + " from user::" + updatedIdentity.getName(), null); } } @@ -671,8 +675,8 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { .createQuery(sb.toString()) .setParameter("resourceKey", resource.getKey()) .executeUpdate(); - if(isLogDebugEnabled()) { - logDebug(rowDeleted + " policies deleted"); + if(log.isDebug()) { + log.debug(rowDeleted + " policies deleted"); } } @@ -740,6 +744,56 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { return iimpl; } + /** + * Persists the given user, creates an identity for it and adds the user to + * the users system group + * + * @param loginName + * @param externalId + * @param pwd null: no OLAT authentication is generated. If not null, the password will be + * encrypted and and an OLAT authentication is generated. + * @param newUser unpersisted users + * @return Identity + */ + @Override + public Identity createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(String loginName, String externalId, String pwd, User newUser) { + Identity ident = null; + if (pwd == null) { + // when no password is used the provider must be set to null to not generate + // an OLAT authentication token. See method doku. + ident = createAndPersistIdentityAndUser(loginName, externalId, newUser, null, null); + log.audit("Create an identity without authentication (login=" + loginName + ")"); + } else { + ident = createAndPersistIdentityAndUser(loginName, externalId, newUser, BaseSecurityModule.getDefaultAuthProviderIdentifier(), loginName, pwd); + log.audit("Create an identity with " + BaseSecurityModule.getDefaultAuthProviderIdentifier() + " authentication (login=" + loginName + ")"); + } + + // Add user to system users group + SecurityGroup olatuserGroup = findSecurityGroupByName(Constants.GROUP_OLATUSERS); + addIdentityToSecurityGroup(ident, olatuserGroup); + return ident; + } + + /** + * Persists the given user, creates an identity for it and adds the user to + * the users system group, create an authentication for an external provider + * + * @param loginName + * @param externalId + * @param provider + * @param authusername + * @param newUser + * @return + */ + @Override + public Identity createAndPersistIdentityAndUserWithUserGroup(String loginName, String externalId, String provider, String authusername, User newUser) { + Identity ident = createAndPersistIdentityAndUser(loginName, externalId, newUser, provider, authusername, null); + log.audit("Create an identity with " + provider + " authentication (login=" + loginName + ",authusername=" + authusername + ")"); + // Add user to system users group + SecurityGroup olatuserGroup = findSecurityGroupByName(Constants.GROUP_OLATUSERS); + addIdentityToSecurityGroup(ident, olatuserGroup); + return ident; + } private void notifyNewIdentityCreated(Identity newIdentity) { //Save the identity on the DB. So can the listeners of the event retrieve it @@ -1158,7 +1212,8 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { public Authentication createAndPersistAuthentication(final Identity ident, final String provider, final String authUserName, final String credentials, final Encoder.Algorithm algorithm) { OLATResourceable resourceable = OresHelper.createOLATResourceableInstanceWithoutCheck(provider, ident.getKey()); - return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resourceable, new SyncerCallback<Authentication>(){ + return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resourceable, new SyncerCallback<Authentication>() { + @Override public Authentication execute() { Authentication auth = findAuthentication(ident, provider); if(auth == null) { @@ -1170,6 +1225,7 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { auth = new AuthenticationImpl(ident, provider, authUserName, credentials); } dbInstance.getCurrentEntityManager().persist(auth); + log.audit("Create " + provider + " authentication (login=" + ident.getName() + ",authusername=" + authUserName + ")"); } return auth; } @@ -1286,7 +1342,7 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { dbInstance.getCurrentEntityManager().remove(authRef); } } catch (EntityNotFoundException e) { - logError("", e); + log.error("", e); } } diff --git a/src/main/java/org/olat/core/util/PathUtils.java b/src/main/java/org/olat/core/util/PathUtils.java index c49169774e39594770724a615e383e89e87555ba..b54ec3819456929481eb723073856d14b6bc41ca 100644 --- a/src/main/java/org/olat/core/util/PathUtils.java +++ b/src/main/java/org/olat/core/util/PathUtils.java @@ -41,7 +41,7 @@ import java.nio.file.attribute.BasicFileAttributes; public class PathUtils { public static Path visit(File file, String filename, FileVisitor<Path> visitor) - throws IOException { + throws IOException, IllegalArgumentException { if(!StringHelper.containsNonWhitespace(filename)) { filename = file.getName(); } diff --git a/src/main/java/org/olat/fileresource/types/FeedFileResource.java b/src/main/java/org/olat/fileresource/types/FeedFileResource.java index 74234de258d50e34b3c5dad164504a331230098c..643cd05b76d502153ea91e4704b998f13c2eec9c 100644 --- a/src/main/java/org/olat/fileresource/types/FeedFileResource.java +++ b/src/main/java/org/olat/fileresource/types/FeedFileResource.java @@ -96,7 +96,7 @@ public abstract class FeedFileResource extends FileResource { eval.setDescription(feed.getDescription()); } } - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); } return eval; diff --git a/src/main/java/org/olat/fileresource/types/GlossaryResource.java b/src/main/java/org/olat/fileresource/types/GlossaryResource.java index 4af7d53aae976da5e18e7bd1c18b08a4fd1401c7..fe70b0ca2e2c6eb71c1ff4981650aa9dab9ea8ad 100644 --- a/src/main/java/org/olat/fileresource/types/GlossaryResource.java +++ b/src/main/java/org/olat/fileresource/types/GlossaryResource.java @@ -94,7 +94,7 @@ public class GlossaryResource extends FileResource { eval.setValid(true); } eval.setValid(visitor.isValid()); - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); } return eval; diff --git a/src/main/java/org/olat/fileresource/types/ImsCPFileResource.java b/src/main/java/org/olat/fileresource/types/ImsCPFileResource.java index 80a2c3749f790b4f69ab4d161be651647f06c1a7..27910be268992052cf2fdf73b3b9add59f9436fe 100644 --- a/src/main/java/org/olat/fileresource/types/ImsCPFileResource.java +++ b/src/main/java/org/olat/fileresource/types/ImsCPFileResource.java @@ -79,7 +79,7 @@ public class ImsCPFileResource extends FileResource { } else { eval.setValid(false); } - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); eval.setValid(false); } diff --git a/src/main/java/org/olat/fileresource/types/ScormCPFileResource.java b/src/main/java/org/olat/fileresource/types/ScormCPFileResource.java index 35cb66842fb4858800218aed36bd6f6bc1c22d3f..a025776a8a12ef6687387d2a8fc4892c14cd1f88 100644 --- a/src/main/java/org/olat/fileresource/types/ScormCPFileResource.java +++ b/src/main/java/org/olat/fileresource/types/ScormCPFileResource.java @@ -94,7 +94,7 @@ public class ScormCPFileResource extends FileResource { } else { eval.setValid(false); } - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); eval.setValid(false); } diff --git a/src/main/java/org/olat/fileresource/types/WikiResource.java b/src/main/java/org/olat/fileresource/types/WikiResource.java index 645c50bd120d1fbe1725607872156688ac4530f8..0ff7c3f98894707d8e500a001fd433e72e76d8fc 100644 --- a/src/main/java/org/olat/fileresource/types/WikiResource.java +++ b/src/main/java/org/olat/fileresource/types/WikiResource.java @@ -63,7 +63,7 @@ public class WikiResource extends FileResource { IndexFileFilter visitor = new IndexFileFilter(); PathUtils.visit(file, filename, visitor); eval.setValid(visitor.isValid()); - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); } return eval; diff --git a/src/main/java/org/olat/ims/qti/fileresource/SurveyFileResource.java b/src/main/java/org/olat/ims/qti/fileresource/SurveyFileResource.java index 143bf5098da6f2689f917c40d81627b33fdb1268..95aa95cc3c8ab1fed7fe47446f52453757387b5a 100644 --- a/src/main/java/org/olat/ims/qti/fileresource/SurveyFileResource.java +++ b/src/main/java/org/olat/ims/qti/fileresource/SurveyFileResource.java @@ -100,7 +100,7 @@ public class SurveyFileResource extends FileResource { } else { eval.setValid(false); } - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); eval.setValid(false); } diff --git a/src/main/java/org/olat/ims/qti/fileresource/TestFileResource.java b/src/main/java/org/olat/ims/qti/fileresource/TestFileResource.java index f4ab27f13fd500fab8a5ff806d0071486ec6c1ce..bc775b75fb6e50ffc2cf265c2c08b8e6f4aea4b4 100644 --- a/src/main/java/org/olat/ims/qti/fileresource/TestFileResource.java +++ b/src/main/java/org/olat/ims/qti/fileresource/TestFileResource.java @@ -100,7 +100,7 @@ public class TestFileResource extends FileResource { } else { eval.setValid(false); } - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); eval.setValid(false); } diff --git a/src/main/java/org/olat/registration/RegistrationManager.java b/src/main/java/org/olat/registration/RegistrationManager.java index 4ce1ac27c7151ab3abf0275920a1eb9eb4b10f3e..99b5aae43c45b9d03fa6a6361b550194b2603ef9 100644 --- a/src/main/java/org/olat/registration/RegistrationManager.java +++ b/src/main/java/org/olat/registration/RegistrationManager.java @@ -37,7 +37,7 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.hibernate.type.StandardBasicTypes; -import org.olat.basesecurity.AuthHelper; +import org.olat.basesecurity.BaseSecurity; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; @@ -72,6 +72,7 @@ public class RegistrationManager extends BasicManager { private RegistrationModule registrationModule; private MailManager mailManager; + private BaseSecurity securityManager; private RegistrationManager() { // singleton @@ -100,6 +101,14 @@ public class RegistrationManager extends BasicManager { this.registrationModule = registrationModule; } + /** + * [used by Spring] + * @param securityManager + */ + public void setSecurityManager(BaseSecurity securityManager) { + this.securityManager = securityManager; + } + public boolean validateEmailUsername(String email) { List<String> whiteList = registrationModule.getDomainList(); if(whiteList.isEmpty()) { @@ -172,7 +181,7 @@ public class RegistrationManager extends BasicManager { * @return the newly created subject or null */ public Identity createNewUserAndIdentityFromTemporaryKey(String login, String pwd, User myUser, TemporaryKeyImpl tk) { - Identity identity = AuthHelper.createAndPersistIdentityAndUserWithUserGroup(login, null, pwd, myUser); + Identity identity = securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(login, null, pwd, myUser); if (identity == null) return null; deleteTemporaryKey(tk); return identity; diff --git a/src/main/java/org/olat/registration/_spring/registrationContext.xml b/src/main/java/org/olat/registration/_spring/registrationContext.xml index 666da25a6841c654e6c774f0671310de8c6698f3..c1bcca812c73789b8194a2f76f4410194756138f 100644 --- a/src/main/java/org/olat/registration/_spring/registrationContext.xml +++ b/src/main/java/org/olat/registration/_spring/registrationContext.xml @@ -43,6 +43,7 @@ <bean id="selfRegistrationManager" class="org.olat.registration.RegistrationManager"> <property name="registrationModule" ref="registrationModule" /> <property name="mailManager" ref="mailManager"/> + <property name="securityManager" ref="baseSecurityManager"/> </bean> <bean id="registrationPresetUsername.byEmail" diff --git a/src/main/java/org/olat/repository/handlers/CourseHandler.java b/src/main/java/org/olat/repository/handlers/CourseHandler.java index 25c062f33c7cb5edefbf03169571888b7d6ff582..3a63e5605d1b28d408eef348c5c6608136e953cf 100644 --- a/src/main/java/org/olat/repository/handlers/CourseHandler.java +++ b/src/main/java/org/olat/repository/handlers/CourseHandler.java @@ -194,7 +194,7 @@ public class CourseHandler implements RepositoryHandler { } } eval.setValid(visitor.isValid()); - } catch (IOException e) { + } catch (IOException | IllegalArgumentException e) { log.error("", e); } return eval; diff --git a/src/main/java/org/olat/user/restapi/UserWebService.java b/src/main/java/org/olat/user/restapi/UserWebService.java index 09c575066e119ccd30a91b3a328f39d2531dc711..c0376d15facee5b98b12749dfb9ef4169630b91c 100644 --- a/src/main/java/org/olat/user/restapi/UserWebService.java +++ b/src/main/java/org/olat/user/restapi/UserWebService.java @@ -61,7 +61,6 @@ import javax.ws.rs.core.UriInfo; import org.olat.admin.user.UserShortDescription; import org.olat.admin.user.delete.service.UserDeletionManager; -import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.Authentication; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; @@ -262,7 +261,7 @@ public class UserWebService { List<ErrorVO> errors = validateUser(null, user, request); if(errors.isEmpty()) { User newUser = UserManager.getInstance().createUser(user.getFirstName(), user.getLastName(), user.getEmail()); - Identity id = AuthHelper.createAndPersistIdentityAndUserWithUserGroup(user.getLogin(), user.getExternalId(), user.getPassword(), newUser); + Identity id = BaseSecurityManager.getInstance().createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(user.getLogin(), user.getExternalId(), user.getPassword(), newUser); post(newUser, user, getLocale(request)); UserManager.getInstance().updateUser(newUser); return Response.ok(get(id)).build(); diff --git a/src/test/java/org/olat/user/EmailCheckPerformanceTest.java b/src/test/java/org/olat/user/EmailCheckPerformanceTest.java index 93bb738bc5715aedb8f3df5792a71c168e98aad1..583a05882be133d98c4f00f867a3fde62f4c67fb 100644 --- a/src/test/java/org/olat/user/EmailCheckPerformanceTest.java +++ b/src/test/java/org/olat/user/EmailCheckPerformanceTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.Constants; import org.olat.core.commons.persistence.DB; @@ -124,7 +123,7 @@ public class EmailCheckPerformanceTest extends OlatTestCase { user.setProperty(UserConstants.INSTITUTIONALEMAIL, username + "@" + institution); user.setProperty(UserConstants.INSTITUTIONALNAME, institution); user.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, username + "-" + institution); - AuthHelper.createAndPersistIdentityAndUserWithUserGroup(username, null, "hokuspokus", user); + securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(username, null, "hokuspokus", user); if (i % 10 == 0) { // flush now to obtimize performance diff --git a/src/test/java/org/olat/user/UserPropertiesPerformanceTest.java b/src/test/java/org/olat/user/UserPropertiesPerformanceTest.java index e423f62510a521a432f2fe580cbf1ec87c4999eb..cb2f0e1cb9ef3707c96eafeac340b7908a7f1063 100644 --- a/src/test/java/org/olat/user/UserPropertiesPerformanceTest.java +++ b/src/test/java/org/olat/user/UserPropertiesPerformanceTest.java @@ -28,9 +28,7 @@ import java.util.List; import java.util.Map; import org.junit.Test; -import org.olat.basesecurity.AuthHelper; import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.BaseSecurityModule; import org.olat.basesecurity.Constants; import org.olat.core.commons.persistence.DB; @@ -42,6 +40,7 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.Formatter; import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; /** * <h3>Description:</h3> @@ -59,6 +58,10 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { private static OLog log = Tracing.createLoggerFor(UserPropertiesPerformanceTest.class); + @Autowired + private UserManager um; + @Autowired + private BaseSecurity securityManager; /** @@ -75,12 +78,9 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { int numberUsers = 50000; int measureSteps = 10000; - - UserManager um = UserManager.getInstance(); - BaseSecurity sm = BaseSecurityManager.getInstance(); // create users group - sm.createAndPersistNamedSecurityGroup(Constants.GROUP_OLATUSERS); + securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_OLATUSERS); String username; String institution; @@ -112,7 +112,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { user.setProperty(UserConstants.INSTITUTIONALEMAIL, username + "@" + institution); user.setProperty(UserConstants.INSTITUTIONALNAME, institution); user.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, username + "-" + institution); - AuthHelper.createAndPersistIdentityAndUserWithUserGroup(username, null, "hokuspokus", user); + securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(username, null, "hokuspokus", user); if (i % 10 == 0) { // flush now to obtimize performance @@ -132,7 +132,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { attributes.put(UserConstants.TELMOBILE, "123456"); String[] providers = new String[]{BaseSecurityModule.getDefaultAuthProviderIdentifier()}; long querystart = System.currentTimeMillis(); - List<Identity> result = sm.getIdentitiesByPowerSearch(null, attributes, true, null, null, providers, null, null, null, null, null); + List<Identity> result = securityManager.getIdentitiesByPowerSearch(null, attributes, true, null, null, providers, null, null, null, null, null); long querytime = System.currentTimeMillis() - querystart; assertEquals(i/2, result.size()); DBFactory.getInstance().closeSession(); @@ -146,7 +146,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { // find all users with power search query. the query will match on all // users since the user value search is a like '%value%' search querystart = System.currentTimeMillis(); - result = sm.getIdentitiesByPowerSearch(null, attributes, false, null, null, providers, null, null, null, null, null); + result = securityManager.getIdentitiesByPowerSearch(null, attributes, false, null, null, providers, null, null, null, null, null); querytime = System.currentTimeMillis() - querystart; assertEquals(i, result.size()); DBFactory.getInstance().closeSession(); @@ -160,7 +160,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { // find all users with an empty power search query: this should remove // all joins from the query (except the user join) querystart = System.currentTimeMillis(); - result = sm.getIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, null); + result = securityManager.getIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, null); querytime = System.currentTimeMillis() - querystart; assertEquals(i, result.size()); DBFactory.getInstance().closeSession(); @@ -175,7 +175,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { // attribute that limits the result to one user is the login name attributes.put(UserConstants.GENDER, (i % 2 == 0 ? "m" : "f")); querystart = System.currentTimeMillis(); - result = sm.getIdentitiesByPowerSearch(i/2 + "test", attributes, true, null, null, providers, null, null, null, null, null); + result = securityManager.getIdentitiesByPowerSearch(i/2 + "test", attributes, true, null, null, providers, null, null, null, null, null); querytime = System.currentTimeMillis() - querystart; assertEquals(1, result.size()); DBFactory.getInstance().closeSession(); @@ -189,7 +189,7 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { // find one specific user via a dedicated search via login name. No // joining is done (automatic by hibernate) querystart = System.currentTimeMillis(); - ident = sm.findIdentityByName(i/2 + "test"); + ident = securityManager.findIdentityByName(i/2 + "test"); querytime = System.currentTimeMillis() - querystart; assertNotNull(ident); DBFactory.getInstance().closeSession(); @@ -209,10 +209,8 @@ public class UserPropertiesPerformanceTest extends OlatTestCase { } } - DB db = DBFactory.getInstance(); - db.closeSession(); + DB db = DBFactory.getInstance(); + db.closeSession(); } } - - } \ No newline at end of file