From 3615f8559af558889772139e5b80be6eea4c4606 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Tue, 4 Sep 2012 08:41:30 +0200
Subject: [PATCH] OO-341: add a method to load an identity by its user in
 BaseSecurity, remove IdentityManager, IdentityManagerImpl

---
 .../org/olat/basesecurity/BaseSecurity.java   |   7 +
 .../basesecurity/BaseSecurityManager.java     |  60 +++++---
 .../basesecurity/IdentityManagerImpl.java     |  57 -------
 .../core/dispatcher/ErrorFeedbackMailer.java  |   4 +-
 .../org/olat/core/id/IdentityManager.java     |  38 -----
 .../DateDisplayPropertyHandler.java           | 139 ++++++++++++++++++
 .../org/olat/_spring/olatextconfig.xml        |  10 --
 .../basesecurity/BaseSecurityManagerTest.java |  89 +++++++++++
 .../olat/basesecurity/BaseSecurityTest.java   | 131 -----------------
 .../org/olat/basesecurity/IdentityTest.java   |   7 +-
 10 files changed, 284 insertions(+), 258 deletions(-)
 delete mode 100644 src/main/java/org/olat/basesecurity/IdentityManagerImpl.java
 delete mode 100644 src/main/java/org/olat/core/id/IdentityManager.java
 create mode 100644 src/main/java/org/olat/user/propertyhandlers/DateDisplayPropertyHandler.java
 create mode 100644 src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java

diff --git a/src/main/java/org/olat/basesecurity/BaseSecurity.java b/src/main/java/org/olat/basesecurity/BaseSecurity.java
index 5c70c4a2625..e52e61cfde2 100644
--- a/src/main/java/org/olat/basesecurity/BaseSecurity.java
+++ b/src/main/java/org/olat/basesecurity/BaseSecurity.java
@@ -156,6 +156,13 @@ public interface BaseSecurity {
 	 */
 	public Identity findIdentityByName(String identityName);
 	
+	/**
+	 * Find an identity by its user
+	 * @param user
+	 * @return The identity or null if not found
+	 */
+	public Identity findIdentityByUser(User user);
+	
 	/**
 	 * Find identities by names. This is an exact match.
 	 * <p>
diff --git a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java
index dc6a8f8ac9b..9678bb8e3a6 100644
--- a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java
+++ b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java
@@ -1040,16 +1040,40 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity {
 	/**
 	 * @see org.olat.basesecurity.Manager#findIdentityByName(java.lang.String)
 	 */
+	@Override
 	public Identity findIdentityByName(String identityName) {
 		if (identityName == null) throw new AssertException("findIdentitybyName: name was null");
-		List identities = DBFactory.getInstance().find(
-				"select ident from org.olat.basesecurity.IdentityImpl as ident where ident.name = ?", new Object[] { identityName },
-				new Type[] { StandardBasicTypes.STRING });
-		int size = identities.size();
-		if (size == 0) return null;
-		if (size != 1) throw new AssertException("non unique name in identites: " + identityName);
-		Identity identity = (Identity) identities.get(0);
-		return identity;
+
+		StringBuilder sb = new StringBuilder();
+		sb.append("select ident from ").append(IdentityImpl.class.getName()).append(" as ident where ident.name=:username");
+		
+		List<Identity> identities = DBFactory.getInstance().getCurrentEntityManager()
+				.createQuery(sb.toString(), Identity.class)
+				.setParameter("username", identityName)
+				.getResultList();
+		
+		if(identities.isEmpty()) {
+			return null;
+		}
+		return identities.get(0);
+	}
+	
+	@Override
+	public Identity findIdentityByUser(User user) {
+		if (user == null) return null;
+		
+		StringBuilder sb = new StringBuilder();
+		sb.append("select ident from ").append(IdentityImpl.class.getName()).append(" as ident where ident.user.key=:userKey");
+		
+		List<Identity> identities = DBFactory.getInstance().getCurrentEntityManager()
+				.createQuery(sb.toString(), Identity.class)
+				.setParameter("userKey", user.getKey())
+				.getResultList();
+		
+		if(identities.isEmpty()) {
+			return null;
+		}
+		return identities.get(0);
 	}
 
 	@Override
@@ -1587,16 +1611,18 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity {
 		DBFactory.getInstance().updateObject(identity);
 	}
 
-	
+	@Override
 	public List<SecurityGroup> getSecurityGroupsForIdentity(Identity identity) {
-		DB db = DBFactory.getInstance();
-	  List<SecurityGroup> secGroups = db.find(
-				"select sgi from"
-				+ " org.olat.basesecurity.SecurityGroupImpl as sgi," 
-				+ " org.olat.basesecurity.SecurityGroupMembershipImpl as sgmsi "
-				+ " where sgmsi.securityGroup = sgi and sgmsi.identity = ?",
-				new Object[] { identity.getKey() },
-				new Type[] { StandardBasicTypes.LONG });
+		StringBuilder sb = new StringBuilder();
+		sb.append("select sgi from ").append(SecurityGroupImpl.class.getName()).append(" as sgi, ")
+		  .append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmsi ")
+		  .append(" where sgmsi.securityGroup=sgi and sgmsi.identity.key=:identityKey");
+
+	  List<SecurityGroup> secGroups = DBFactory.getInstance().getCurrentEntityManager()
+	  		.createQuery(sb.toString(), SecurityGroup.class)
+	  		.setParameter("identityKey", identity.getKey())
+	  		.getResultList();
+
   	return secGroups;
 	}
 	
diff --git a/src/main/java/org/olat/basesecurity/IdentityManagerImpl.java b/src/main/java/org/olat/basesecurity/IdentityManagerImpl.java
deleted file mode 100644
index c8d9b0b2492..00000000000
--- a/src/main/java/org/olat/basesecurity/IdentityManagerImpl.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
-* OLAT - Online Learning and Training<br>
-* http://www.olat.org
-* <p>
-* Licensed under the Apache License, Version 2.0 (the "License"); <br>
-* you may not use this file except in compliance with the License.<br>
-* You may obtain a copy of the License at
-* <p>
-* http://www.apache.org/licenses/LICENSE-2.0
-* <p>
-* Unless required by applicable law or agreed to in writing,<br>
-* software distributed under the License is distributed on an "AS IS" BASIS, <br>
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
-* See the License for the specific language governing permissions and <br>
-* limitations under the License.
-* <p>
-* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
-* University of Zurich, Switzerland.
-* <hr>
-* <a href="http://www.openolat.org">
-* OpenOLAT - Online Learning and Training</a><br>
-* This file has been modified by the OpenOLAT community. Changes are licensed
-* under the Apache 2.0 license as the original file.
-*/
-package org.olat.basesecurity;
-
-import org.olat.core.id.Identity;
-import org.olat.core.id.IdentityManager;
-import org.olat.core.manager.BasicManager;
-
-/**
- * Description:<br>
- * TODO: patrickb Class Description for IdentityManagerImpl
- * 
- * <P>
- * Initial Date:  23.08.2007 <br>
- * @author patrickb
- */
-public class IdentityManagerImpl extends BasicManager implements IdentityManager {
-
-	BaseSecurity im = null;
-	
-	/**
-	 * for spring
-	 *
-	 */
-	private IdentityManagerImpl(BaseSecurity im){
-		this.im = im;
-	}
-	/**
-	 * @see org.olat.core.id.IdentityManager#findIdentityByName(java.lang.String)
-	 */
-	public Identity findIdentityByName(String userName) {
-		return im.findIdentityByName(userName);
-	}
-
-}
diff --git a/src/main/java/org/olat/core/dispatcher/ErrorFeedbackMailer.java b/src/main/java/org/olat/core/dispatcher/ErrorFeedbackMailer.java
index e9f2b3da392..c2929ee5bfc 100644
--- a/src/main/java/org/olat/core/dispatcher/ErrorFeedbackMailer.java
+++ b/src/main/java/org/olat/core/dispatcher/ErrorFeedbackMailer.java
@@ -32,9 +32,9 @@ import java.util.Iterator;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.olat.basesecurity.BaseSecurity;
 import org.olat.core.CoreSpringFactory;
 import org.olat.core.id.Identity;
-import org.olat.core.id.IdentityManager;
 import org.olat.core.logging.LogFileParser;
 import org.olat.core.logging.Tracing;
 import org.olat.core.util.WebappHelper;
@@ -73,7 +73,7 @@ public class ErrorFeedbackMailer implements Dispatcher {
 		String errorNr = request.getParameter("fx_errnum");
 		String username = request.getParameter("username");
 		try {
-			IdentityManager im = (IdentityManager) CoreSpringFactory.getBean("core.id.IdentityManager");
+			BaseSecurity im = CoreSpringFactory.getImpl(BaseSecurity.class);
 			Identity ident = im.findIdentityByName(username);
 			// if null, user may crashed befor getting a valid session, try with
 			// guest user instead
diff --git a/src/main/java/org/olat/core/id/IdentityManager.java b/src/main/java/org/olat/core/id/IdentityManager.java
deleted file mode 100644
index 25d40e4685b..00000000000
--- a/src/main/java/org/olat/core/id/IdentityManager.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
-* OLAT - Online Learning and Training<br>
-* http://www.olat.org
-* <p>
-* Licensed under the Apache License, Version 2.0 (the "License"); <br>
-* you may not use this file except in compliance with the License.<br>
-* You may obtain a copy of the License at
-* <p>
-* http://www.apache.org/licenses/LICENSE-2.0
-* <p>
-* Unless required by applicable law or agreed to in writing,<br>
-* software distributed under the License is distributed on an "AS IS" BASIS, <br>
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
-* See the License for the specific language governing permissions and <br>
-* limitations under the License.
-* <p>
-* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
-* University of Zurich, Switzerland.
-* <hr>
-* <a href="http://www.openolat.org">
-* OpenOLAT - Online Learning and Training</a><br>
-* This file has been modified by the OpenOLAT community. Changes are licensed
-* under the Apache 2.0 license as the original file.  
-* <p>
-*/ 
-
-package org.olat.core.id;
-
-public interface IdentityManager {
-  
-  /**
-   * Find the Identity (and the user) that match to a given username.
-   * The match is an exact match.
-   * @param userName
-   * @return Identity or <code>null</code> meaning <i>not found</i>
-   */
-  public Identity findIdentityByName(String userName);
-}
diff --git a/src/main/java/org/olat/user/propertyhandlers/DateDisplayPropertyHandler.java b/src/main/java/org/olat/user/propertyhandlers/DateDisplayPropertyHandler.java
new file mode 100644
index 00000000000..e7a5ba77dcf
--- /dev/null
+++ b/src/main/java/org/olat/user/propertyhandlers/DateDisplayPropertyHandler.java
@@ -0,0 +1,139 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.user.propertyhandlers;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+
+import org.olat.basesecurity.BaseSecurityManager;
+import org.olat.core.gui.components.form.ValidationError;
+import org.olat.core.gui.components.form.flexible.FormItem;
+import org.olat.core.gui.components.form.flexible.FormItemContainer;
+import org.olat.core.gui.components.form.flexible.FormUIFactory;
+import org.olat.core.gui.components.form.flexible.elements.TextElement;
+import org.olat.core.id.Identity;
+import org.olat.core.id.User;
+import org.olat.core.logging.OLog;
+import org.olat.core.logging.Tracing;
+import org.olat.core.util.StringHelper;
+import org.olat.user.AbstractUserPropertyHandler;
+
+/**
+ * this class displays a static textElement. it always shows one of three dates:
+ * user creation-date, user last-modified-date or user last-login-date
+ * 
+ * @author strentini, sergio.trentini@frentix.com
+ * 
+ */
+public class DateDisplayPropertyHandler extends AbstractUserPropertyHandler {
+
+	private OLog log = Tracing.createLoggerFor(this.getClass());
+
+	private static final String DATE_TYPE_CR = "creationDateDisplayProperty";
+	private static final String DATE_TYPE_LL = "lastloginDateDisplayProperty";
+
+	@Override
+	public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
+
+		Date date = getDateValue(user);
+		String dateString = StringHelper.formatLocaleDate(date.getTime(), locale);
+		FormItem item = FormUIFactory.getInstance().addStaticTextElement(getName(), i18nFormElementLabelKey(), dateString, formItemContainer);
+
+		return item;
+	}
+
+	/**
+	 * returns the correct date according to the name of this
+	 * DateDisplayPropertyHandler-name<br />
+	 * 
+	 * which can be one of three: the creation-date, the lastlogin-date or the
+	 * last-modified-date
+	 */
+	private Date getDateValue(User user) {
+		String myName = getName();
+
+		if (DATE_TYPE_CR.equals(myName))
+			return user.getCreationDate();
+		if (DATE_TYPE_LL.equals(myName)) {
+			Identity id = BaseSecurityManager.getInstance().findIdentityByUser(user);
+			if (id != null)
+				return id.getLastLogin();
+
+			// huh, we didn't find this identity
+			log.warn("Couldn't find Identity for given User: " + user.getKey());
+			return new Date(0);
+		}
+
+		// huh, something different.. return 1970
+		return new Date(0);
+	}
+
+	public String getUserProperty(User user, Locale locale) {
+		Date date = getDateValue(user);
+		if (date != null && locale != null)
+			return StringHelper.formatLocaleDate(getDateValue(user).getTime(), locale);
+		return StringHelper.formatLocaleDate(-1, locale);
+	}
+
+	/**
+	 * @return The non-i18-ified raw value from the database ( in this case its
+	 *         the unix tstamp of this Date-Field, time in milliseconds since
+	 *         1970)
+	 */
+	protected String getInternalValue(User user) {
+		if (user != null) {
+			return String.valueOf(getDateValue(user).getTime());
+		}
+		return "";
+	}
+
+	@Override
+	public void updateUserFromFormItem(User user, FormItem formItem) {
+		// we do nothing here, its read-only
+	}
+
+	@Override
+	public boolean isValid(FormItem formItem, Map formContext) {
+		// always valid, no check
+		return true;
+	}
+
+	@Override
+	public boolean isValidValue(String value, ValidationError validationError, Locale locale) {
+		// always valid, no check
+		return true;
+	}
+
+	@Override
+	public String getStringValue(FormItem formItem) {
+		if (formItem instanceof TextElement) {
+			return ((TextElement) formItem).getValue();
+		}
+		return ""; // should not happen, passed formItem is expected to be a
+					// textElement
+	}
+
+	@Override
+	public String getStringValue(String displayValue, Locale locale) {
+		return displayValue;
+	}
+
+}
diff --git a/src/main/resources/serviceconfig/org/olat/_spring/olatextconfig.xml b/src/main/resources/serviceconfig/org/olat/_spring/olatextconfig.xml
index c162e6f2d82..f7786140c5b 100644
--- a/src/main/resources/serviceconfig/org/olat/_spring/olatextconfig.xml
+++ b/src/main/resources/serviceconfig/org/olat/_spring/olatextconfig.xml
@@ -82,17 +82,7 @@
 		<constructor-arg index="0" ref="resourceManager" />
 		<constructor-arg index="1" ref="propertyManager" />
 	</bean> 
-  
-    <!--
-		*****************************************
-		*** Define the Identity Manager       ***
-		*****************************************
-	-->
-	<bean id="core.id.IdentityManager" class="org.olat.basesecurity.IdentityManagerImpl"  >
-		<constructor-arg type="org.olat.basesecurity.BaseSecurity" ref="baseSecurityManager"/>
-	</bean>  
 
-   
     <!--
 		*****************************************
 		*** IMS Content Packaging  Manager    ***
diff --git a/src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java b/src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
new file mode 100644
index 00000000000..83f96480e2e
--- /dev/null
+++ b/src/test/java/org/olat/basesecurity/BaseSecurityManagerTest.java
@@ -0,0 +1,89 @@
+package org.olat.basesecurity;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.olat.core.commons.persistence.DB;
+import org.olat.core.id.Identity;
+import org.olat.test.JunitTestHelper;
+import org.olat.test.OlatTestCase;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Test the basic functions of the base security manager.
+ * 
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ */
+public class BaseSecurityManagerTest extends OlatTestCase {
+	
+	@Autowired
+	private DB dbInstance;
+	@Autowired
+	private BaseSecurity securityManager;
+
+	@Test
+	public void testFindIdentityByUser() {
+		//create a user it
+		String username = "find-me-" + UUID.randomUUID().toString();
+		Identity id = JunitTestHelper.createAndPersistIdentityAsUser(username);
+		Assert.assertNotNull(id);
+		Assert.assertNotNull(id.getUser());
+		dbInstance.commitAndCloseSession();
+		
+		//find it
+		Identity foundId = securityManager.findIdentityByUser(id.getUser());
+		Assert.assertNotNull(foundId);
+		Assert.assertEquals(username, foundId.getName());
+		Assert.assertEquals(id, foundId);
+		Assert.assertEquals(id.getUser(), foundId.getUser());
+	}
+	
+	@Test
+	public void testFindIdentityByName() {
+		//create a user it
+		String name = "find-me-" + UUID.randomUUID().toString();
+		Identity id = JunitTestHelper.createAndPersistIdentityAsUser(name);
+		Assert.assertNotNull(id);
+		Assert.assertEquals(name, id.getName());
+		dbInstance.commitAndCloseSession();
+		
+		//find it
+		Identity foundId = securityManager.findIdentityByName(name);
+		Assert.assertNotNull(foundId);
+		Assert.assertEquals(name, foundId.getName());
+		Assert.assertEquals(id, foundId);
+	}
+	
+	@Test
+	public void testGetSecurityGroupsForIdentity() {
+		// create
+		Identity id = JunitTestHelper.createAndPersistIdentityAsUser( "find-sec-" + UUID.randomUUID().toString());
+		SecurityGroup secGroup1 = securityManager.createAndPersistSecurityGroup();
+		SecurityGroup secGroup2 = securityManager.createAndPersistSecurityGroup();
+		SecurityGroup secGroup3 = securityManager.createAndPersistSecurityGroup();
+		securityManager.addIdentityToSecurityGroup(id, secGroup1);
+		securityManager.addIdentityToSecurityGroup(id, secGroup2);
+		dbInstance.commitAndCloseSession();
+		
+		//check
+		List<SecurityGroup> secGroups = securityManager.getSecurityGroupsForIdentity(id);
+		Assert.assertNotNull(secGroups);
+		Assert.assertTrue(secGroups.contains(secGroup1));
+		Assert.assertTrue(secGroups.contains(secGroup2));
+		Assert.assertFalse(secGroups.contains(secGroup3));
+	}
+	
+	@Test
+	public void testCreateNamedGroup() {
+		String name = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
+		SecurityGroup ng = securityManager.createAndPersistNamedSecurityGroup(name);
+		dbInstance.commitAndCloseSession();
+		
+		SecurityGroup sgFound = securityManager.findSecurityGroupByName(name);
+		Assert.assertNotNull(sgFound);
+		Assert.assertEquals(sgFound.getKey(), ng.getKey());
+	}
+
+}
diff --git a/src/test/java/org/olat/basesecurity/BaseSecurityTest.java b/src/test/java/org/olat/basesecurity/BaseSecurityTest.java
index 650b14cf304..1509406a3ac 100644
--- a/src/test/java/org/olat/basesecurity/BaseSecurityTest.java
+++ b/src/test/java/org/olat/basesecurity/BaseSecurityTest.java
@@ -65,138 +65,7 @@ public class BaseSecurityTest extends OlatTestCase {
 	@Autowired
 	private BaseSecurity baseSecurityManager;
 	
-	@Test public void testSecurityGroup() {
-		System.out.println("start testSecurityGroup");
-		try {
-			Identity ident = getOrCreateIdentity("anIdentity");
-			// check on those four default groups
-			SecurityGroup ng;
-			ng = baseSecurityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
-			assertNotNull(ng);
-			ng = baseSecurityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
-			assertNotNull(ng);
-			ng = baseSecurityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
-			assertNotNull(ng);
-			ng = baseSecurityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
-			assertNotNull(ng);
-
-			SecurityGroup secg = baseSecurityManager.createAndPersistSecurityGroup();
-			SecurityGroup secg2 = baseSecurityManager.createAndPersistSecurityGroup();
-			SecurityGroup secg3 = baseSecurityManager.createAndPersistSecurityGroup();
-			assertNotNull(secg.getKey());
-
-			baseSecurityManager.addIdentityToSecurityGroup(ident, secg);
-			Identity ident2 = baseSecurityManager.createAndPersistIdentity("gugus", null, BaseSecurityModule.getDefaultAuthProviderIdentifier(), "uuu", Encoder.encrypt("ppp"));
-			
-			// simulate some user gui clicks
-			DBFactory.getInstance().closeSession();
-
-			// groupmembership test
-			assertTrue(baseSecurityManager.isIdentityInSecurityGroup(ident, secg));
-			assertFalse(baseSecurityManager.isIdentityInSecurityGroup(ident, secg2));
-			assertFalse(baseSecurityManager.isIdentityInSecurityGroup(ident2, secg2));
-			assertFalse(baseSecurityManager.isIdentityInSecurityGroup(ident2, secg));
 
-			baseSecurityManager.addIdentityToSecurityGroup(ident2, secg3);
-			assertTrue(baseSecurityManager.isIdentityInSecurityGroup(ident2, secg3));
-			// simulate some user gui clicks
-			DBFactory.getInstance().closeSession();
-
-			baseSecurityManager.deleteSecurityGroup(secg3);
-
-			// simulate some user gui clicks
-			DBFactory.getInstance().closeSession();
-			assertFalse(baseSecurityManager.isIdentityInSecurityGroup(ident2, secg3));
-
-			List idents = baseSecurityManager.getIdentitiesOfSecurityGroup(secg);
-			assertEquals(idents.size(), 1);
-			baseSecurityManager.deleteSecurityGroup(secg2);
-			baseSecurityManager.deleteSecurityGroup(secg);
-		} catch (Exception e) {
-			e.printStackTrace();
-		} catch (Error err) {
-			err.printStackTrace();
-		}
-		System.out.println("stop testSecurityGroup");
-	}
-
-	@Test public void testNamedGroups() {
-		System.out.println("start testNamedGroups");
-		try {
-			SecurityGroup ng = baseSecurityManager.createAndPersistNamedSecurityGroup("abc");
-			DBFactory.getInstance().closeSession();
-			SecurityGroup sgFound = baseSecurityManager.findSecurityGroupByName("abc");
-			assertNotNull(sgFound);
-			assertTrue(sgFound.getKey().equals(ng.getKey()));
-		} catch (Exception e) {
-			e.printStackTrace();
-		} catch (Error err) {
-			err.printStackTrace();
-		}
-		System.out.println("stop testNamedGroups");
-	}
-	
-	@Test public void testPolicy() {
-		System.out.println("start testPolicy");
-		try {
-			Identity ident = getOrCreateIdentity("anIdentity");
-			Identity ident2 = baseSecurityManager.createAndPersistIdentity("gugus2", null, BaseSecurityModule.getDefaultAuthProviderIdentifier(), "uuu2", Encoder.encrypt("ppp"));
-			
-			SecurityGroup secg = baseSecurityManager.createAndPersistSecurityGroup();
-			SecurityGroup secg2 = baseSecurityManager.createAndPersistSecurityGroup();
-
-			baseSecurityManager.addIdentityToSecurityGroup(ident, secg);
-			// resourceable type
-			OLATResourceable or1 = OresHelper.createOLATResourceableInstance("Forum", new Long("111"));
-			// simulate some user gui clicks
-			DBFactory.getInstance().closeSession();
-
-			
-			// resourceable (type and key)
-			OLATResourceable or2 = OresHelper.createOLATResourceableInstance("Forum", new Long("123"));
-
-			baseSecurityManager.createAndPersistPolicy(secg2, Constants.PERMISSION_ACCESS, or1);
-			Policy policy = baseSecurityManager.createAndPersistPolicy(secg, "read", or2); // instance
-																																		// resource
-			assertNotNull(policy);
-			assertNotNull(policy.getSecurityGroup());
-			assertNotNull(policy.getSecurityGroup().getKey());
-			assertTrue(policy.getSecurityGroup().getKey().equals(secg.getKey()));
-
-			policy = baseSecurityManager.createAndPersistPolicy(secg, "read", or1); // type resource
-			assertNotNull(policy);
-
-			//assert we have instance access if we own the type policy
-			assertTrue(baseSecurityManager.isIdentityPermittedOnResourceable(ident, "read", or2));
-
-			assertTrue(baseSecurityManager.isIdentityPermittedOnResourceable(ident, "read", or1));
-			assertFalse(baseSecurityManager.isIdentityPermittedOnResourceable(ident, "write", or1));
-			assertFalse(baseSecurityManager.isIdentityPermittedOnResourceable(ident2, "read", or1));
-			assertTrue(baseSecurityManager.isIdentityPermittedOnResourceable(ident, "read", or2));
-			assertFalse(baseSecurityManager.isIdentityPermittedOnResourceable(ident, "blub", or2));
-
-			DBFactory.getInstance().closeSession();
-
-			// test on deleting a securitygroup that is still referenced by a policy
-			// (referential integrity)
-			boolean r = true;
-			try {
-				baseSecurityManager.deleteSecurityGroup(secg);
-				DBFactory.getInstance().closeSession();
-			} catch (Exception e) {
-				if (((DBRuntimeException) e).getCause() instanceof PropertyValueException) {
-					r = true;
-				}
-			}
-			DBFactory.getInstance().closeSession();
-			assertTrue(r);
-		} catch (NumberFormatException e) {
-			e.printStackTrace();
-		} catch (Error err) {
-			err.printStackTrace();
-		}
-		System.out.println("stop testPolicy");	
-	}
 	
 	@Test public void testGetIdentitiesByPowerSearch() {
 		System.out.println("start testGetIdentitiesByPowerSearch");
diff --git a/src/test/java/org/olat/basesecurity/IdentityTest.java b/src/test/java/org/olat/basesecurity/IdentityTest.java
index 7e3dcd1f579..eb904c40d8b 100644
--- a/src/test/java/org/olat/basesecurity/IdentityTest.java
+++ b/src/test/java/org/olat/basesecurity/IdentityTest.java
@@ -29,13 +29,14 @@ package org.olat.basesecurity;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.olat.core.commons.persistence.DB;
 import org.olat.core.commons.persistence.DBFactory;
 import org.olat.core.id.Identity;
+import org.olat.core.logging.OLog;
+import org.olat.core.logging.Tracing;
 import org.olat.test.JunitTestHelper;
 import org.olat.test.OlatTestCase;
 
@@ -48,7 +49,7 @@ import org.olat.test.OlatTestCase;
  */
 public class IdentityTest extends OlatTestCase {
 
-	private static Logger log = Logger.getLogger(IdentityTest.class.getName());
+	private static OLog log = Tracing.createLoggerFor(IdentityTest.class);
 	// variables for test fixture
 	private static boolean isInitialized = false;
 	private static Identity ident1, ident2;
@@ -78,7 +79,6 @@ public class IdentityTest extends OlatTestCase {
 
 	@Test
 	public void testEquals() {
-
 		assertFalse("Wrong equals implementation, different types are recognized as equals ",ident1.equals(new Integer(1)));
 		assertFalse("Wrong equals implementation, different users are recognized as equals ",ident1.equals(ident2));
 		assertFalse("Wrong equals implementation, null value is recognized as equals ",ident1.equals(null));
@@ -87,6 +87,7 @@ public class IdentityTest extends OlatTestCase {
 		Identity ident1_2 = ma.findIdentityByName(identityTest1Name);
 		assertTrue("Wrong equals implementation, same users are NOT recognized as equals ",ident1.equals(ident1_2));
 	}
+	
 	@Test
 	public void testHashCode() {
 		assertTrue("Wrong hashCode implementation, same users have NOT same hash-code ",ident1.hashCode() == ident1.hashCode());
-- 
GitLab