Remove deprecated warnings
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 27 Jul 2022 07:56:05 +0000 (09:56 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 27 Jul 2022 07:56:05 +0000 (09:56 +0200)
org.argeo.api.cms/src/org/argeo/api/cms/CmsAuth.java
org.argeo.cms/src/org/argeo/cms/auth/KeyringLoginModule.java
org.argeo.cms/src/org/argeo/cms/auth/RemoteAuthRequest.java
org.argeo.cms/src/org/argeo/cms/auth/SingleUserLoginModule.java
org.argeo.cms/src/org/argeo/cms/internal/auth/CmsSessionImpl.java
org.argeo.cms/src/org/argeo/cms/internal/osgi/CmsActivator.java

index decea35508a4da5db931fc3b44a4a7732d5b68d7..6ecfeba11c6689283b04507e9243c9ea6eaa7df8 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.api.cms;
 
+import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
@@ -21,6 +22,14 @@ public enum CmsAuth {
                return new LoginContext(getLoginContextName(), callbackHandler);
        }
 
+       public LoginContext newLoginContext(Subject subject, CallbackHandler callbackHandler) throws LoginException {
+               return new LoginContext(getLoginContextName(), subject, callbackHandler);
+       }
+
+       public LoginContext newLoginContext(Subject subject) throws LoginException {
+               return new LoginContext(getLoginContextName(), subject);
+       }
+
        /*
         * LOGIN CONTEXTS
         */
index c49a59ef1dcc5ea69033618702e0caff7d8c2271..af559df7558026fc187dbf055181b86dd0deaa68 100644 (file)
@@ -1,6 +1,5 @@
 package org.argeo.cms.auth;
 
-import java.security.AccessController;
 import java.util.Map;
 import java.util.Set;
 
@@ -16,6 +15,7 @@ import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 
 import org.argeo.cms.security.PBEKeySpecCallback;
+import org.argeo.util.CurrentSubject;
 import org.argeo.util.PasswordEncryption;
 
 /** Adds a secret key to the private credentials */
@@ -28,7 +28,7 @@ public class KeyringLoginModule implements LoginModule {
                        Map<String, ?> options) {
                this.subject = subject;
                if (subject == null) {
-                       subject = Subject.getSubject(AccessController.getContext());
+                       this.subject = CurrentSubject.current();
                }
                this.callbackHandler = callbackHandler;
        }
index 9720812e0f2e7ad5e8b3987fff689216bbce0f06..be5d0e15e966355c55cb6e8ee70a4d980d729ae8 100644 (file)
@@ -9,7 +9,6 @@ public interface RemoteAuthRequest {
 
        RemoteAuthSession getSession();
 
-       @Deprecated
        RemoteAuthSession createSession();
 
        Locale getLocale();
index 956987d52ddde586d7b9ff8cf370e1608dc8b72a..35b7d5cc7ebe73233f630e1a46bb6aa2bac2168e 100644 (file)
@@ -1,7 +1,5 @@
 package org.argeo.cms.auth;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Locale;
 import java.util.Map;
 
@@ -13,7 +11,6 @@ import javax.security.auth.login.LoginException;
 import javax.security.auth.spi.LoginModule;
 import javax.security.auth.x500.X500Principal;
 
-import org.argeo.api.cms.CmsLog;
 import org.argeo.cms.internal.runtime.CmsContextImpl;
 import org.argeo.osgi.useradmin.OsUserUtils;
 import org.argeo.util.directory.ldap.IpaUtils;
@@ -22,7 +19,7 @@ import org.osgi.service.useradmin.Authorization;
 
 /** Login module for when the system is owned by a single user. */
 public class SingleUserLoginModule implements LoginModule {
-       private final static CmsLog log = CmsLog.getLog(SingleUserLoginModule.class);
+//     private final static CmsLog log = CmsLog.getLog(SingleUserLoginModule.class);
 
        private Subject subject;
        private Map<String, Object> sharedState = null;
index dfedfab1968f02a474bc073f3c7f15914ee810c2..4f5a85ddfc998a0bbd24b33d4b4fc567bf21e565 100644 (file)
@@ -76,9 +76,9 @@ public class CmsSessionImpl implements CmsSession, Serializable {
                try {
                        LoginContext lc;
                        if (isAnonymous()) {
-                               lc = new LoginContext(CmsAuth.LOGIN_CONTEXT_ANONYMOUS, getSubject());
+                               lc = CmsAuth.ANONYMOUS.newLoginContext(getSubject());
                        } else {
-                               lc = new LoginContext(CmsAuth.LOGIN_CONTEXT_USER, getSubject());
+                               lc = CmsAuth.USER.newLoginContext(getSubject());
                        }
                        lc.logout();
                } catch (LoginException e) {
index 5e047d38a6b06db35900bd5439533e164646ff96..59b226a53c61a284ade9a84288cb373c6048831c 100644 (file)
@@ -58,11 +58,11 @@ public class CmsActivator implements BundleActivator {
                } catch (Exception e) {
                        log.error("CMS activator shutdown failed", e);
                }
-               
+
                new GogoShellKiller().start();
        }
 
-       private void initSecurity() {
+       protected void initSecurity() {
                // code-level permissions
                String osgiSecurity = bundleContext.getProperty(Constants.FRAMEWORK_SECURITY);
                if (osgiSecurity != null && Constants.FRAMEWORK_SECURITY_OSGI.equals(osgiSecurity)) {
@@ -104,7 +104,6 @@ public class CmsActivator implements BundleActivator {
 //                     bundleContext.registerService(ArgeoLogger.class, logger, null);
 //     }
 
-
        public static <T> void registerService(Class<T> clss, T service, Dictionary<String, ?> properties) {
                if (bundleContext != null) {
                        bundleContext.registerService(clss, service, properties);
@@ -139,7 +138,6 @@ public class CmsActivator implements BundleActivator {
                bundleContext = null;
        }
 
-
        public static BundleContext getBundleContext() {
                return bundleContext;
        }