use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SecurityUpgradeService method postConstruct.
public void postConstruct() {
for (Config config : configs.getConfig()) {
SecurityService service = config.getSecurityService();
if (service != null) {
upgradeJACCProvider(service);
}
}
// Clear up the old policy files for applications
String instanceRoot = env.getInstanceRoot().getAbsolutePath();
File genPolicyDir = new File(instanceRoot, DIR_GENERATED_POLICY);
if (genPolicyDir != null) {
File[] applicationDirs = genPolicyDir.listFiles();
if (applicationDirs != null) {
for (File policyDir : applicationDirs) {
deleteFile(policyDir);
}
}
}
for (Config config : configs.getConfig()) {
SecurityService service = config.getSecurityService();
List<AuthRealm> authRealms = service.getAuthRealm();
try {
for (AuthRealm authRealm : authRealms) {
if (JDBC_REALM_CLASSNAME.equals(authRealm.getClassname())) {
Property digestAlgoProp = authRealm.getProperty(PARAM_DIGEST_ALGORITHM);
if (digestAlgoProp != null) {
String digestAlgo = digestAlgoProp.getValue();
if (digestAlgo == null || digestAlgo.isEmpty()) {
digestAlgoProp.setValue("MD5");
}
} else {
ConfigSupport.apply(new SingleConfigCode<AuthRealm>() {
public Object run(AuthRealm updatedAuthRealm) throws PropertyVetoException, TransactionFailure {
Property prop1 = updatedAuthRealm.createChild(Property.class);
prop1.setName(PARAM_DIGEST_ALGORITHM);
prop1.setValue("MD5");
updatedAuthRealm.getProperty().add(prop1);
return null;
}
}, authRealm);
}
}
}
} catch (PropertyVetoException pve) {
_logger.log(Level.SEVERE, SecurityLoggerInfo.securityUpgradeServiceException, pve);
throw new RuntimeException(pve);
} catch (TransactionFailure tf) {
_logger.log(Level.SEVERE, SecurityLoggerInfo.securityUpgradeServiceException, tf);
throw new RuntimeException(tf);
}
}
if (requiresSecureAdmin()) {
_logger.log(Level.WARNING, SecurityLoggerInfo.securityUpgradeServiceWarning);
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class RealmsManager method setDefaultDigestAlgorithm.
private void setDefaultDigestAlgorithm() {
SecurityService service = config.getSecurityService();
if (service == null) {
return;
}
List<Property> props = service.getProperty();
if (props == null) {
return;
}
Iterator<Property> propsIterator = props.iterator();
while (propsIterator != null && propsIterator.hasNext()) {
Property prop = propsIterator.next();
if (prop != null && DEFAULT_DIGEST_ALGORITHM.equals(prop.getName())) {
this.defaultDigestAlgorithm = prop.getValue();
break;
}
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class ConfigApiTest method getHabitat.
/**
* Returns a configured Habitat with the configuration.
*
* @return a configured Habitat
*/
public ServiceLocator getHabitat() {
ServiceLocator habitat = Utils.instance.getHabitat(this);
assertNotNull("Transactions service from Configuration subsystem is null", habitat.getService(Transactions.class));
return habitat;
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class UpgradeLogging method doUpgrade.
private void doUpgrade(Config config) {
// v3 uses logging.properties to configure the logging facility.
// move all log-service elements to logging.properties
final LogService logService = config.getLogService();
// check if null and exit
if (logService == null)
return;
try {
RepositoryConfig rc = new RepositoryConfig();
String configDir = rc.getRepositoryRoot() + File.separator + rc.getRepositoryName() + File.separator + rc.getInstanceName() + File.separator + "config";
PEFileLayout layout = new PEFileLayout(rc);
File src = new File(layout.getTemplatesDir(), PEFileLayout.LOGGING_PROPERTIES_FILE);
File dest = new File(configDir, PEFileLayout.LOGGING_PROPERTIES_FILE);
if (!dest.exists())
FileUtils.copy(src, dest);
} catch (IOException ioe) {
getLogger().log(Level.SEVERE, FAIL_CREATE_LOG_PROPS, ioe);
}
try {
// Get the logLevels
ModuleLogLevels mll = logService.getModuleLogLevels();
Map<String, String> logLevels = mll.getAllLogLevels();
String file = logService.getFile();
String payaraNotificationFile = logService.getPayaraNotificationFile();
String instanceRoot = System.getProperty("com.sun.aas.instanceRoot");
if (file.contains(instanceRoot)) {
file = file.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
}
if (payaraNotificationFile.contains(instanceRoot)) {
payaraNotificationFile = payaraNotificationFile.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
}
logLevels.put("file", file);
logLevels.put("payara-notification-file", payaraNotificationFile);
logLevels.put("use-system-logging", logService.getUseSystemLogging());
// this can have multiple values so need to add
logLevels.put("log-handler", logService.getLogHandler());
logLevels.put("log-filter", logService.getLogFilter());
logLevels.put("log-to-file", logService.getLogToFile());
logLevels.put("payara-notification-log-to-file", logService.getPayaraNotificationLogToFile());
logLevels.put("log-to-console", logService.getLogToConsole());
logLevels.put("log-rotation-limit-in-bytes", logService.getLogRotationLimitInBytes());
logLevels.put("payara-notification-log-rotation-limit-in-bytes", logService.getPayaraNotificationLogRotationLimitInBytes());
logLevels.put("log-rotation-timelimit-in-minutes", logService.getLogRotationTimelimitInMinutes());
logLevels.put("payara-notification-log-rotation-timelimit-in-minutes", logService.getPayaraNotificationLogRotationTimelimitInMinutes());
logLevels.put("alarms", logService.getAlarms());
logLevels.put("retain-error-statistics-for-hours", logService.getRetainErrorStatisticsForHours());
final Map<String, String> m = new HashMap<String, String>(logLevels);
ConfigSupport.apply(new SingleConfigCode<Config>() {
public Object run(Config c) throws PropertyVetoException, TransactionFailure {
try {
// update logging.properties
logConfig.updateLoggingProperties(m);
c.setLogService(null);
} catch (IOException e) {
getLogger().log(Level.SEVERE, FAIL_UPDATE_LOG_PROPS, e);
}
return null;
}
}, config);
} catch (TransactionFailure tf) {
getLogger().log(Level.SEVERE, FAIL_UPGRADE_LOG_SERVICE, tf);
throw new RuntimeException(tf);
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class TemplateRestResource method buildPath.
/**
* This method will build the path string as needed by ConfigModularityUtils.getOwningObject().
* There is a mismatch between what the method expects and the way the REST URIs are constructed.
* For example, for the transaction-service element, the REST URI, stripped of the HTTP and
* server context information, looks like this:
* /domain/configs/config/server-config/transaction-service. The format expected by the
* getOwningObject(), however, looks like this:
* domain/configs/server-config/transaction-service. In the REST URIs, if there is a collection of
* Named items, the type of the collection is inserted into the URI ("config" here) followed by
* the name of the particular instance ("server-config"). In building the path, we must identify
* Named instances and insert the name of the instance rather than the type. We apply this logic
* as we recurse up to the top of the Dom tree to finish building the path desired.
* @param node
* @return
*/
private String buildPath(Dom node) {
final Dom parentNode = node.parent();
String part = node.model.getTagName();
String name = node.attribute("name");
if (name != null) {
part = name;
}
return (parentNode != null) ? (buildPath(parentNode) + "/" + part) : part;
}
Aggregations