@@ -168,10 +168,21 @@ public SunPKCS11 run() throws Exception {
168168 * fips.nssdb.path System property after expansion.
169169 * Security properties expansion is unsupported.
170170 */
171- System .setProperty (
172- FIPS_NSSDB_PATH_PROP ,
171+ String nssdbPath =
173172 SecurityProperties .privilegedGetOverridable (
174- FIPS_NSSDB_PATH_PROP ));
173+ FIPS_NSSDB_PATH_PROP );
174+ if (System .getSecurityManager () != null ) {
175+ AccessController .doPrivileged (
176+ (PrivilegedAction <Void >) () -> {
177+ System .setProperty (
178+ FIPS_NSSDB_PATH_PROP ,
179+ nssdbPath );
180+ return null ;
181+ });
182+ } else {
183+ System .setProperty (
184+ FIPS_NSSDB_PATH_PROP , nssdbPath );
185+ }
175186 }
176187 return new SunPKCS11 (new Config (newConfigName ));
177188 }
@@ -1450,6 +1461,7 @@ private static final class P11Service extends Service {
14501461 }
14511462
14521463 @ Override
1464+ @ SuppressWarnings ("removal" )
14531465 public Object newInstance (Object param )
14541466 throws NoSuchAlgorithmException {
14551467 if (!token .isValid ()) {
@@ -1469,7 +1481,26 @@ public Object newInstance(Object param)
14691481 * property.
14701482 */
14711483 try {
1472- token .ensureLoggedIn (null );
1484+ if (System .getSecurityManager () != null ) {
1485+ try {
1486+ AccessController .doPrivileged (
1487+ (PrivilegedExceptionAction <Void >) () -> {
1488+ token .ensureLoggedIn (null );
1489+ return null ;
1490+ });
1491+ } catch (PrivilegedActionException pae ) {
1492+ Exception e = pae .getException ();
1493+ if (e instanceof LoginException le ) {
1494+ throw le ;
1495+ } else if (e instanceof PKCS11Exception p11e ) {
1496+ throw p11e ;
1497+ } else {
1498+ throw new RuntimeException (e );
1499+ }
1500+ }
1501+ } else {
1502+ token .ensureLoggedIn (null );
1503+ }
14731504 } catch (PKCS11Exception | LoginException e ) {
14741505 throw new ProviderException ("FIPS: error during the Token" +
14751506 " login required for the " + getType () +
0 commit comments