1 /* 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.security.auth.login; 27 28 import javax.security.auth.login.AppConfigurationEntry; 29 import javax.security.auth.login.Configuration; 30 import java.net.URI; 31 32 // NOTE: As of JDK 8, this class instantiates 33 // sun.security.provider.ConfigSpiFile and forwards all methods to that 34 // implementation. All implementation fixes and enhancements should be made to 35 // sun.security.provider.ConfigSpiFile and not this class. 36 // See JDK-8005117 for more information. 37 38 /** 39 * This class represents a default implementation for 40 * {@code javax.security.auth.login.Configuration}. 41 * 42 * <p> This object stores the runtime login configuration representation, 43 * and is the amalgamation of multiple static login 44 * configurations that resides in files. 45 * The algorithm for locating the login configuration file(s) and reading their 46 * information into this {@code Configuration} object is: 47 * 48 * <ol> 49 * <li> 50 * Loop through the security properties, 51 * <i>login.config.url.1</i>, <i>login.config.url.2</i>, ..., 52 * <i>login.config.url.X</i>. 53 * Each property value specifies a {@code URL} pointing to a 54 * login configuration file to be loaded. Read in and load 55 * each configuration. 56 * 57 * <li> 58 * The {@code java.lang.System} property 59 * <i>java.security.auth.login.config</i> 60 * may also be set to a {@code URL} pointing to another 61 * login configuration file 62 * (which is the case when a user uses the -D switch at runtime). 63 * If this property is defined, and its use is allowed by the 64 * security property file (the Security property, 65 * <i>policy.allowSystemProperty</i> is set to <i>true</i>), 66 * also load that login configuration. 67 * 68 * <li> 69 * If the <i>java.security.auth.login.config</i> property is defined using 70 * "==" (rather than "="), then ignore all other specified 71 * login configurations and only load this configuration. 72 * 73 * <li> 74 * If no system or security properties were set, try to read from the file, 75 * ${user.home}/.java.login.config, where ${user.home} is the value 76 * represented by the "user.home" System property. 77 * </ol> 78 * 79 * <p> The configuration syntax supported by this implementation 80 * is exactly that syntax specified in the 81 * {@code javax.security.auth.login.Configuration} class. 82 * 83 * @see javax.security.auth.login.LoginContext 84 * @see java.security.Security security properties 85 */ 86 public class ConfigFile extends Configuration { 87 88 private sun.security.provider.ConfigSpiFile configFile; 89 90 /** 91 * Create a new {@code Configuration} object. 92 * 93 * @throws SecurityException if the {@code Configuration} can not be 94 * initialized 95 */ 96 public ConfigFile() { 97 configFile = new sun.security.provider.ConfigSpiFile(); 98 } 99 100 /** 101 * Create a new {@code Configuration} object from the specified {@code URI}. 102 * 103 * @param uri the {@code URI} 104 * @throws SecurityException if the {@code Configuration} can not be 105 * initialized 106 * @throws NullPointerException if {@code uri} is null 107 */ 108 public ConfigFile(URI uri) { 109 configFile = new sun.security.provider.ConfigSpiFile(uri); 110 } 111 112 /** 113 * Retrieve an entry from the {@code Configuration} using an application 114 * name as an index. 115 * 116 * @param applicationName the name used to index the {@code Configuration} 117 * @return an array of {@code AppConfigurationEntry} which correspond to 118 * the stacked configuration of {@code LoginModule}s for this 119 * application, or null if this application has no configured 120 * {@code LoginModule}s. 121 */ 122 @Override 123 public AppConfigurationEntry[] getAppConfigurationEntry 124 (String applicationName) { 125 126 return configFile.engineGetAppConfigurationEntry(applicationName); 127 } 128 129 /** 130 * Refresh and reload the {@code Configuration} by re-reading all of the 131 * login configurations. 132 * 133 * @throws SecurityException if the caller does not have permission 134 * to refresh the {@code Configuration} 135 */ 136 @Override 137 public synchronized void refresh() { 138 configFile.engineRefresh(); 139 } 140 }