Refactored JaasAuthenticationProvider

The toUrl() method on File gives a deprecation warning with Java 6, so I reimplemented
the logic for building the Jaas config URL.
This commit is contained in:
Luke Taylor 2010-01-03 16:28:44 +00:00
parent 893f212fa5
commit 80aacf447f
1 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package org.springframework.security.authentication.jaas;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.Principal;
import java.security.Security;
import java.util.ArrayList;
@ -244,8 +245,7 @@ public class JaasAuthenticationProvider implements AuthenticationProvider, Appli
*
*/
private void configureJaasUsingLoop() throws IOException {
File loginConfigFile = loginConfig.getFile();
String loginConfigUrl = loginConfigFile.toURL().toString();
String loginConfigUrl = convertLoginConfigToUrl();
boolean alreadySet = false;
int n = 1;
@ -269,6 +269,17 @@ public class JaasAuthenticationProvider implements AuthenticationProvider, Appli
}
}
private String convertLoginConfigToUrl() throws IOException {
String loginConfigPath = loginConfig.getFile().getAbsolutePath();
loginConfigPath.replace(File.separatorChar, '/');
if (!loginConfigPath.startsWith("/")) {
loginConfigPath = "/" + loginConfigPath;
}
return new URL("file", "", loginConfigPath).toString();
}
/**
* Handles the logout by getting the SecurityContext for the session that was destroyed. <b>MUST NOT use
* SecurityContextHolder as we are logging out a session that is not related to the current user.</b>