1515 */
1616package org .springframework .geode .security .support ;
1717
18+ import java .util .Optional ;
1819import java .util .Properties ;
1920import java .util .concurrent .atomic .AtomicReference ;
2021
2122import org .apache .geode .security .AuthenticationFailedException ;
2223import org .apache .geode .security .ResourcePermission ;
24+ import org .springframework .beans .BeansException ;
25+ import org .springframework .beans .factory .BeanFactory ;
26+ import org .springframework .beans .factory .BeanFactoryAware ;
2327import org .springframework .beans .factory .DisposableBean ;
2428import org .springframework .beans .factory .annotation .Autowired ;
2529import org .springframework .data .gemfire .support .LazyWiringDeclarableSupport ;
6064 * @author John Blum
6165 * @see org.apache.geode.security.ResourcePermission
6266 * @see org.apache.geode.security.SecurityManager
67+ * @see org.springframework.beans.factory.BeanFactory
68+ * @see org.springframework.beans.factory.BeanFactoryAware
69+ * @see org.springframework.beans.factory.DisposableBean
6370 * @see org.springframework.beans.factory.annotation.Autowired
6471 * @see org.springframework.data.gemfire.support.LazyWiringDeclarableSupport
6572 * @since 1.0.0
6673 */
6774@ SuppressWarnings ("unused" )
6875public class SecurityManagerProxy extends LazyWiringDeclarableSupport
69- implements org .apache .geode .security .SecurityManager , DisposableBean {
76+ implements org .apache .geode .security .SecurityManager , DisposableBean , BeanFactoryAware {
7077
7178 private static final AtomicReference <SecurityManagerProxy > INSTANCE = new AtomicReference <>();
7279
80+ private BeanFactory beanFactory ;
81+
7382 private org .apache .geode .security .SecurityManager securityManager ;
7483
7584 /**
@@ -92,16 +101,19 @@ public static SecurityManagerProxy getInstance() {
92101 * security operations to a Spring managed {@link org.apache.geode.security.SecurityManager} bean.
93102 */
94103 public SecurityManagerProxy () {
95-
96- // TODO remove init() call when GEODE-2083 (https://issues.apache.org/jira/browse/GEODE-2083) is resolved!
97- // NOTE: the init(:Properties) call in the constructor is less than ideal since...
98- // 1) it allows the *this* reference to escape, and...
99- // 2) it is Geode's responsibility to identify Geode Declarable objects and invoke their init(:Properties) method
100- // However, the init(:Properties) method invocation in the constructor is necessary to enable this Proxy to be
101- // identified and auto-wired in a Spring context.
102-
103104 INSTANCE .compareAndSet (null , this );
104- init (new Properties ());
105+ }
106+
107+ /**
108+ * Configures a reference to the current Spring {@link BeanFactory}.
109+ *
110+ * @param beanFactory reference to the current Spring {@link BeanFactory}.
111+ * @throws BeansException if this operation fails to configure the reference to the {@link BeanFactory}.
112+ * @see org.springframework.beans.factory.BeanFactory
113+ */
114+ @ Override
115+ public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
116+ this .beanFactory = beanFactory ;
105117 }
106118
107119 /**
@@ -159,4 +171,11 @@ public void destroy() throws Exception {
159171 super .destroy ();
160172 INSTANCE .set (null );
161173 }
174+
175+ @ Override
176+ protected BeanFactory locateBeanFactory () {
177+
178+ return Optional .ofNullable (this .beanFactory )
179+ .orElseGet (() -> super .locateBeanFactory ());
180+ }
162181}
0 commit comments