Skip to content

Commit 5e33c4f

Browse files
committed
Remove SecurityManager usage
1 parent 5814e56 commit 5e33c4f

File tree

6 files changed

+6
-107
lines changed

6 files changed

+6
-107
lines changed

mq/main/mq-broker/broker-comm/src/main/java/com/sun/messaging/jmq/jmsserver/config/BrokerConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation
44
*
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -470,7 +470,7 @@
470470
* // accesscontrol classes/properties imq.accesscontrol.file.properties=class,filename,dirpath
471471
* imq.accesscontrol.file.class=com.sun.messaging.jmq.jmsserver.auth.acl.JMQFileAccessControlModel
472472
*
473-
* imq.accesscontrol.jaas.properties=class,permissionFactory,policyProvider
473+
* imq.accesscontrol.jaas.properties=class,permissionFactory
474474
* imq.accesscontrol.jaas.class=com.sun.messaging.jmq.jmsserver.auth.acl.JAASAccessControlModel
475475
*
476476
* // logging classes imq.log.file.class=com.sun.messaging.jmq.util.log.FileLogHandler
@@ -686,7 +686,7 @@ public class BrokerConfig extends UpdateProperties {
686686
+ ".user_repository.jaas.class=com.sun.messaging.jmq.jmsserver.auth.jaas.UserRepositoryImpl\n" + IMQ
687687
+ ".accesscontrol.file.properties=class,filename,dirpath,url\n" + IMQ
688688
+ ".accesscontrol.file.class=com.sun.messaging.jmq.jmsserver.auth.acl.JMQFileAccessControlModel\n" + IMQ
689-
+ ".accesscontrol.jaas.properties=class,permissionFactory,permissionFactoryProvide,policyProvider\n" + IMQ
689+
+ ".accesscontrol.jaas.properties=class,permissionFactory,permissionFactoryProvide\n" + IMQ
690690
+ ".accesscontrol.jaas.class=com.sun.messaging.jmq.jmsserver.auth.acl.JAASAccessControlModel\n" + IMQ
691691
+ ".log.file.class=com.sun.messaging.jmq.util.log.FileLogHandler\n" + IMQ + ".log.console.class=com.sun.messaging.jmq.util.log.StreamLogHandler\n"
692692
+ IMQ + ".log.syslog.class=com.sun.messaging.jmq.util.log.SysLogHandler\n" + IMQ

mq/main/mq-broker/broker-comm/src/main/java/com/sun/messaging/jmq/jmsserver/resources/BrokerResources.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation
44
*
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -452,8 +452,6 @@ private BrokerResources(ResourceBundle rb) {
452452
public static final String I_RM_DST_NOTFOUND_INSTORE = "B1304";
453453
public static final String I_AUTHENTICATE_USER_AS = "B1305";
454454
public static final String I_AUTHENTICATE_AS_USER = "B1306";
455-
public static final String I_SET_DEFAULT_SECURITY_MANAGER = "B1307";
456-
public static final String I_SET_JAVA_POLICY_PROVIDER = "B1308";
457455
public static final String I_NO_NONRECOVERY_TXNACK_TO_ROLLBACK = "B1309";
458456
public static final String I_NO_MORE_TXNACK_TO_ROLLBACK = "B1310";
459457
public static final String I_REMOTE_TXN_PRESUMED_ROLLBACK = "B1311";
@@ -1746,7 +1744,6 @@ private BrokerResources(ResourceBundle rb) {
17461744
public static final String X_REPLACE_PROPS_FOR_REPLACE_MSG = "B4442";
17471745
public static final String X_CLEANUP_MSG_CLOSE_SESSION = "B4443";
17481746
public static final String X_CANNOT_DELIVER_MESSAGE_TO_CONSUMER = "B4444";
1749-
public static final String X_SERVICE_TYPE_NOT_FOUND_FOR_SERVICE = "B4445";
17501747
public static final String X_PU_SERVICE_REBIND = "B4446";
17511748
public static final String X_CREATE_CONNECTION_FOR_USER_IN_SERVICE = "B4447";
17521749
public static final String X_JDBC_DRIVER_SET_LOGIN_TIMEOUT = "B4448";

mq/main/mq-broker/broker-comm/src/main/resources/com/sun/messaging/jmq/jmsserver/resources/BrokerResources.properties

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
3-
# Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
3+
# Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation
44
#
55
# This program and the accompanying materials are made available under the
66
# terms of the Eclipse Public License v. 2.0, which is available at
@@ -941,8 +941,6 @@ B1304=Unable to remove destination {0} from store because of not found in store:
941941

942942
B1305=Authenticating user {0} as {1}
943943
B1306=Authenticating {0} as user {1}
944-
B1307=Set default security manager
945-
B1308=Set Java policy provider to {0}
946944
B1309=No non-recovery transaction acks to roll back for remote transaction {0}
947945
B1310=No more transaction acks to roll back for remote transaction {0}
948946
B1311=Presumed rollback for remote transaction {0} from {1}
@@ -3163,7 +3161,6 @@ B4442=Exception in replacing properties for replacement of message {0}: {1}
31633161
B4443=Exception in cleanup message {0} on closing session {1}: {2}
31643162
B4444=Can not deliver message {0} to consumer {1}
31653163
#{0} is a string
3166-
B4445=Can not find service type for service {0}
31673164
B4446=Exception occurred while rebinding port unification service to address {0}
31683165
B4447=Failed to create connection for user {0} in service {1}: {2}
31693166
#{0}, {1} are strings

mq/main/mq-broker/broker-core/src/main/java/com/sun/messaging/jmq/jmsserver/Broker.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,6 @@ private int _start(boolean inProcess, Properties propsFromCommandLine, boolean i
533533
return 0;
534534
}
535535

536-
try {
537-
AccessController.setSecurityManagerIfneed();
538-
} catch (Exception e) {
539-
logger.logStack(Logger.ERROR, e.getMessage(), e);
540-
if (failStartThrowable != null) {
541-
failStartThrowable.initCause(e);
542-
}
543-
return (1);
544-
}
545536
if (!MQAuthenticator.authenticateCMDUserIfset()) {
546537
logger.log(Logger.INFO, BrokerResources.I_SHUTDOWN_BROKER);
547538
if (failStartThrowable != null) {

mq/main/mq-broker/broker-core/src/main/java/com/sun/messaging/jmq/jmsserver/auth/AccessController.java

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
3+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation
44
*
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,9 +19,7 @@
1919

2020
import java.util.List;
2121
import java.util.Properties;
22-
import java.util.Iterator;
2322
import java.security.Principal;
24-
import java.security.Policy;
2523
import java.security.AccessControlException;
2624
import javax.security.auth.Subject;
2725
import javax.security.auth.Refreshable;
@@ -32,8 +30,6 @@
3230
import com.sun.messaging.jmq.jmsserver.resources.BrokerResources;
3331
import com.sun.messaging.jmq.jmsserver.config.BrokerConfig;
3432
import com.sun.messaging.jmq.jmsserver.util.BrokerException;
35-
import com.sun.messaging.jmq.jmsserver.service.ServiceManager;
36-
import com.sun.messaging.jmq.jmsserver.auth.acl.JAASAccessControlModel;
3733
import com.sun.messaging.jmq.util.StringUtil;
3834
import com.sun.messaging.jmq.auth.api.server.*;
3935

@@ -448,80 +444,4 @@ public synchronized void checkDestinationPermission(String serviceName, String s
448444
}
449445

450446
// private static final String DEFAULT_POLICY_FILENAME = "broker.policy";
451-
452-
/** @throws SecurityException */
453-
public static void setSecurityManagerIfneed() throws BrokerException {
454-
455-
boolean need = false;
456-
String svcname = null;
457-
String svctype = null;
458-
AccessController ac = null;
459-
// BrokerConfig bcfg = Globals.getConfig();
460-
Logger logger = Globals.getLogger();
461-
462-
String pp = null, svcpp = null;
463-
List activesvcs = ServiceManager.getAllActiveServiceNames();
464-
Iterator itr = activesvcs.iterator();
465-
while (itr.hasNext()) {
466-
svcname = (String) itr.next();
467-
svctype = ServiceManager.getServiceTypeString(svcname);
468-
if (svctype == null) {
469-
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_TYPE_NOT_FOUND_FOR_SERVICE, svcname));
470-
}
471-
472-
ac = AccessController.getInstance(svcname, ServiceType.getServiceType(svctype));
473-
if (!ac.isAccessControlEnabled()) {
474-
continue;
475-
}
476-
if (ac.getAccessControlType().equals(JAASAccessControlModel.TYPE)) {
477-
need = true;
478-
svcpp = ac.getAuthProperties().getProperty(AccessController.PROP_ACCESSCONTROL_PREFIX + JAASAccessControlModel.PROP_POLICY_PROVIDER);
479-
if (pp == null) {
480-
pp = svcpp;
481-
continue;
482-
}
483-
if (svcpp == null) {
484-
continue;
485-
}
486-
if (!pp.equals(svcpp)) {
487-
throw new BrokerException("XI18N - Multiple Java policy providers is not allowed:" + pp + ", " + svcpp);
488-
}
489-
}
490-
}
491-
if (!need) {
492-
return;
493-
}
494-
495-
Policy ppc = null;
496-
if (pp != null) {
497-
try {
498-
ppc = (Policy) Class.forName(pp).getDeclaredConstructor().newInstance();
499-
} catch (Exception e) {
500-
throw new BrokerException(e.getClass().getName() + ": " + e.getMessage() + " - " + AccessController.PROP_ACCESSCONTROL_PREFIX
501-
+ JAASAccessControlModel.PROP_POLICY_PROVIDER + "=" + pp);
502-
}
503-
}
504-
505-
synchronized (System.class) {
506-
if (System.getSecurityManager() == null) {
507-
String val = System.getProperty("java.security.policy");
508-
if (val == null) {//NOPMD
509-
/*
510-
* logger.log(logger.INFO, "Set java.security.policy to MQ default policy file");
511-
* System.setProperty("java.security.policy",
512-
* "file:"+Globals.getInstanceEtcDir()+File.separator+DEFAULT_POLICY_FILENAME);
513-
*/
514-
} else {
515-
logger.log(logger.INFO, "java.security.policy=" + val);
516-
}
517-
System.setSecurityManager(new SecurityManager());
518-
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_SET_DEFAULT_SECURITY_MANAGER));
519-
}
520-
}
521-
if (ppc != null) {
522-
logger.log(logger.INFO, AccessController.PROP_ACCESSCONTROL_PREFIX + JAASAccessControlModel.PROP_POLICY_PROVIDER + "=" + pp);
523-
Policy.setPolicy(ppc);
524-
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_SET_JAVA_POLICY_PROVIDER, ppc.getClass().getName()));
525-
}
526-
}
527447
}

mq/main/mq-broker/broker-core/src/main/java/com/sun/messaging/jmq/jmsserver/auth/acl/JAASAccessControlModel.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class JAASAccessControlModel implements AccessControlModel {
4141
public static final String TYPE = "jaas";
4242

4343
public static final String PROP_PERMISSION_FACTORY = TYPE + ".permissionFactory";
44-
public static final String PROP_POLICY_PROVIDER = TYPE + ".policyProvider";
4544

4645
private Logger logger = Globals.getLogger();
4746

@@ -68,15 +67,10 @@ public void initialize(String type, Properties authProperties) {
6867
Properties authProps = authProperties;
6968

7069
String pfclass = authProps.getProperty(AccessController.PROP_ACCESSCONTROL_PREFIX + PROP_PERMISSION_FACTORY);
71-
String ppclass = authProps.getProperty(AccessController.PROP_ACCESSCONTROL_PREFIX + PROP_POLICY_PROVIDER);
7270
try {
7371
if (pfclass != null) {
7472
permFactory = (PermissionFactory) Class.forName(pfclass).getDeclaredConstructor().newInstance();
7573
}
76-
// if (ppclass != null) policyProvider = (Policy)Class.forName(ppclass).newInstance();
77-
if (ppclass != null) {
78-
Class.forName(ppclass).getDeclaredConstructor().newInstance();
79-
}
8074
} catch (Exception e) {
8175
logger.logStack(Logger.ERROR, e.getMessage(), e);
8276
throw new AccessControlException(e.getClass().getName() + ": " + e.getMessage());

0 commit comments

Comments
 (0)