Juan Hernandez has uploaded a new change for review.

Change subject: core: Make Kerberos manager a POJO
......................................................................

core: Make Kerberos manager a POJO

Currently this is an EBJ, but it doesn't need to be.

Change-Id: I5e281cadd4e7b90433bbd0b2a6e645ccec25655d
Signed-off-by: Juan Hernandez <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManager.java
D 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagment.java
D 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagmentMBean.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java
4 files changed, 36 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/13255/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManager.java
index a11fee7..95de7b2 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManager.java
@@ -2,44 +2,37 @@
 
 import java.io.File;
 
+import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
-import sun.security.krb5.Config;
-import sun.security.krb5.KrbException;
-
-import javax.annotation.PostConstruct;
-import javax.ejb.Singleton;
-import javax.ejb.DependsOn;
-import javax.ejb.Startup;
-import javax.ejb.ConcurrencyManagement;
-import javax.ejb.ConcurrencyManagementType;
-
 /**
  * Manage the container's Kerberos initialization.
- *
  */
-// Here we use a Singleton bean
-// The @Startup annotation is to make sure the bean is initialized on startup.
-// @ConcurrencyManagement - we use bean managed concurrency:
-// Singletons that use bean-managed concurrency allow full concurrent access 
to all the
-// business and timeout methods in the singleton.
-// The developer of the singleton is responsible for ensuring that the state 
of the singleton is synchronized across all clients.
-// The @DependsOn annotation is in order to make sure it is started after the 
Backend bean is initialized
-@SuppressWarnings("restriction")
-@Singleton
-@Startup
-@DependsOn("Backend")
-@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
-public class KerberosManager implements KerberosManagerSericeManagmentMBean {
+public class KerberosManager {
+    // The log:
+    private static final Log log = LogFactory.getLog(KerberosManager.class);
 
-    private static Log log = LogFactory.getLog(KerberosManager.class);
+    // This is a singleton and this is the instance:
+    private static final KerberosManager instance = new KerberosManager();
+
+    public static final KerberosManager getInstance() {
+        return instance;
+    }
+
+    // This flag indicates if the manager has already been initialized so that
+    // the init method can be safely called more than once:
+    private boolean initialized = false;
+
+    private KerberosManager() {
+        // Nothing, just prevent creation of additional instances.
+    }
 
     private boolean isKerberosAuth() {
         boolean isKerberosAuth = false;
-        String authMethod = 
org.ovirt.engine.core.common.config.Config.<String> 
GetValue(ConfigValues.AuthenticationMethod);
-        String domainName = 
org.ovirt.engine.core.common.config.Config.<String> 
GetValue(ConfigValues.DomainName);
+        String authMethod = Config.<String> 
GetValue(ConfigValues.AuthenticationMethod);
+        String domainName = Config.<String> GetValue(ConfigValues.DomainName);
         String ldapSecurityAuthentication = 
org.ovirt.engine.core.common.config.Config.<String> 
GetValue(ConfigValues.LDAPSecurityAuthentication);
 
         if (authMethod.equalsIgnoreCase("LDAP")) {
@@ -55,16 +48,21 @@
         return isKerberosAuth;
     }
 
-    @PostConstruct
-    public void postConstruct() {
-        create();
+    /**
+     * Initialize the manager if needed. This method can be called more than
+     * once and it will perform the initialization only the first time.
+     */
+    public synchronized void init() {
+        if (!initialized) {
+            doInit();
+            initialized = true;
+        }
     }
 
     /**
-     * This method is called upon the bean creation as part
-     * of the management Service bean lifecycle.
+     * Perform the actual initialization tasks.
      */
-    public void create() {
+    private void doInit() {
         if (!isKerberosAuth()) {
             return;
         }
@@ -84,16 +82,4 @@
         }
         System.setProperty("sun.security.krb5.msinterop.kstring","true");
     }
-
-    @SuppressWarnings("restriction")
-    @Override
-    public void refresh() throws KrbException {
-        if (!isKerberosAuth()) {
-            return;
-        }
-        log.info("Refreshing kerberos configuration");
-        Config.refresh();
-
-    }
-
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagment.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagment.java
deleted file mode 100644
index 367528d..0000000
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagment.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.ovirt.engine.core.bll.adbroker;
-
-public interface KerberosManagerSericeManagment {
-
-}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagmentMBean.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagmentMBean.java
deleted file mode 100644
index 5c56c6c..0000000
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/KerberosManagerSericeManagmentMBean.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.ovirt.engine.core.bll.adbroker;
-
-import sun.security.krb5.KrbException;
-
-public interface KerberosManagerSericeManagmentMBean {
-
-    @SuppressWarnings("restriction")
-    public void refresh() throws KrbException;
-
-}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java
index 0c75c6a..f4d9de1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java
@@ -46,7 +46,7 @@
 // The @DependsOn annotation is in order to make sure it is started after the 
stated beans are initialized
 @Singleton
 @Startup
-@DependsOn({"Backend","KerberosManager"})
+@DependsOn({"Backend"})
 @Local(UsersDomainsCacheManager.class)
 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
 @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@@ -151,6 +151,10 @@
     public void create() {
 
         log.info("Start initializing " + getClass().getSimpleName());
+
+        // Make sure the kerberos manager has been initialized:
+        KerberosManager.getInstance().init();
+
         String authMethod = Config.<String> 
GetValue(ConfigValues.AuthenticationMethod);
         if (!authMethod.equalsIgnoreCase("LDAP")) {
             return;


--
To view, visit http://gerrit.ovirt.org/13255
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e281cadd4e7b90433bbd0b2a6e645ccec25655d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to