Skip to content

Commit

Permalink
refactor: rework path to cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
at88mph committed Oct 2, 2024
1 parent 230d515 commit 140c651
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cadc-gms/src/main/java/org/opencadc/auth/OIDCDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
*/
public class OIDCDiscovery {
private static final Logger log = Logger.getLogger(OIDCDiscovery.class);
private static final String CACHE_DIRECTORY_NAME = "cadc-oidc-discovery";
private static final String CACHE_DIRECTORY_NAME = "cadc-gms";
private static final String WELL_KNOWN_ENDPOINT = "/.well-known/openid-configuration";

final URI issuer;
Expand All @@ -101,19 +101,21 @@ public CachingFile getCachingFile() throws MalformedURLException {
private File getCachedFile() {
final Path baseCacheDir = getBaseCacheDirectory();
final String issuerAuthority = this.issuer.getAuthority();
String resourceCacheDir = baseCacheDir + issuerAuthority;
final String resourceCacheDir = baseCacheDir + issuerAuthority;
final Path path = Paths.get(resourceCacheDir, this.issuer.getPath(), "well-known.json");
log.debug("Caching file [" + path + "] in dir [" + resourceCacheDir + "]");

return path.toFile();
}

private Path getBaseCacheDirectory() {
String tmpDir = System.getProperty("java.io.tmpdir");
String userName = System.getProperty("user.name");
final String tmpDir = System.getProperty("java.io.tmpdir");
final String userName = System.getProperty("user.name");

if (tmpDir == null) {
throw new RuntimeException("No tmp system dir defined.");
}

final Path baseCacheDir;
if (userName == null) {
baseCacheDir = Paths.get(tmpDir, OIDCDiscovery.CACHE_DIRECTORY_NAME);
Expand Down

0 comments on commit 140c651

Please sign in to comment.