Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #757, disable authentication by default in servlet containers but…
… enable it by default when no initial context is available (like in karaf)
- Loading branch information
Showing
7 changed files
with
200 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
hawtio-web/src/main/java/io/hawt/system/ConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.hawt.system; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.naming.Context; | ||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
|
||
/** | ||
* @author Stan Lewis | ||
*/ | ||
public class ConfigManager { | ||
private static final transient Logger LOG = LoggerFactory.getLogger(ConfigManager.class); | ||
|
||
private Context envContext = null; | ||
|
||
public ConfigManager() { | ||
|
||
} | ||
|
||
public void init() { | ||
try { | ||
envContext = (Context) new InitialContext().lookup("java:/comp/env"); | ||
LOG.info("Configuration will be discovered via JNDI"); | ||
} catch (NamingException e) { | ||
LOG.debug("Failed to look up environment context: ", e); | ||
LOG.info("Configuration will be discovered via system properties"); | ||
} | ||
} | ||
|
||
public void destroy() { | ||
if (envContext != null) { | ||
try { | ||
envContext.close(); | ||
} catch (NamingException e) { | ||
// ignore... | ||
} | ||
envContext = null; | ||
} | ||
} | ||
|
||
public String get(String name, String defaultValue) { | ||
String answer = null; | ||
if (envContext != null) { | ||
try { | ||
answer = (String) envContext.lookup("hawtio/" + name); | ||
} catch (Exception e) { | ||
// ignore... | ||
} | ||
} else { | ||
if (defaultValue == null) { | ||
answer = System.getProperty("hawtio." + name); | ||
} else { | ||
answer = System.getProperty("hawtio." + name, defaultValue.toString()); | ||
} | ||
} | ||
if (answer == null) { | ||
answer = defaultValue; | ||
} | ||
LOG.debug("Property {} is set to value {}", name, answer); | ||
return answer; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.