Project

General

Profile

Revision 8535

Added by Jing Tao over 5 years ago

Fixed a bug that AuthFile constructor didn't read the new value of the password file path from the metacat.properties.

View differences:

src/edu/ucsb/nceas/metacat/authentication/AuthFile.java
103 103
    private String authURI = null;
104 104
    private static String passwordFilePath = null;
105 105
    private static AuthFileHashInterface hashClass = null;
106
    private boolean readPathFromProperty = true;
106 107
    /**
107 108
     * Get the instance of the AuthFile
108 109
     * @return
......
148 149
     */
149 150
    public  AuthFile (String passwordFile) throws AuthenticationException {
150 151
        passwordFilePath = passwordFile;
152
        readPathFromProperty = false;
151 153
        try {
152 154
            init();
153 155
        } catch (Exception e) {
......
160 162
     * Initialize the user/password configuration
161 163
     */
162 164
    private void init() throws PropertyNotFoundException, IOException, ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException {
163
        if(passwordFilePath == null) {
165
        if(readPathFromProperty || passwordFilePath == null) {
164 166
            passwordFilePath  = PropertyService.getProperty("auth.file.path");
165 167
        }
168
        //System.out.println("the password file path is ======================= "+passwordFilePath);
166 169
        File passwordFile = new File(passwordFilePath);
167 170
        
168 171
        authURI = SystemUtil.getContextURL();
......
175 178
        if(!passwordFile.exists()) {
176 179
            File parent = passwordFile.getParentFile();
177 180
            if(!parent.exists()) {
178
                parent.mkdirs();
181
                boolean success = false;
182
                try {
183
                    success = parent.mkdirs();
184
                } catch (Exception e) {
185
                    throw new IOException("AuthFile.init - couldn't create the directory "+parent.getAbsolutePath()+ " since "+e.getMessage());
186
                }
187
                if(!success) {
188
                    throw new IOException("AuthFile.init - couldn't create the directory "+parent.getAbsolutePath()+ ", probably since the metacat doesn't have the write permission.");
189
                }
179 190
            }
180
            passwordFile.createNewFile();
191
            boolean success = false;
192
            try {
193
                success = passwordFile.createNewFile();
194
            }  catch (Exception e) {
195
                throw new IOException("AuthFile.init - couldn't create the file "+passwordFile.getAbsolutePath()+ " since "+e.getMessage());
196
            }
197
            if(!success) {
198
                throw new IOException("AuthFile.init - couldn't create the file "+parent.getAbsolutePath()+ ", probably since the metacat doesn't have the write permission.");
199
            }
200
            
181 201
            OutputStreamWriter writer = null;
182 202
            FileOutputStream output = null;
183 203
            try {

Also available in: Unified diff