use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class SecurityUtil method getAnonymousUser.
public String getAnonymousUser(ServiceLocator habitat) {
String user = null;
// find the ADMIN_REALM
AuthRealm adminFileAuthRealm = null;
for (AuthRealm auth : domain.getConfigNamed(DAS_CONFIG).getSecurityService().getAuthRealm()) {
if (auth.getName().equals(ADMIN_REALM)) {
adminFileAuthRealm = auth;
break;
}
}
if (adminFileAuthRealm == null) {
// There must always be an admin realm
throw new IllegalStateException("Cannot find admin realm");
}
// Get FileRealm class name
String fileRealmClassName = adminFileAuthRealm.getClassname();
if (fileRealmClassName != null && !fileRealmClassName.equals(FILE_REALM_CLASSNAME)) {
// we treat this as an error and instead of throwing exception return false;
return null;
}
List<Property> props = adminFileAuthRealm.getProperty();
Property keyfileProp = null;
for (Property prop : props) {
if ("file".equals(prop.getName())) {
keyfileProp = prop;
}
}
if (keyfileProp == null) {
throw new IllegalStateException("Cannot find property 'file'");
}
String keyFile = keyfileProp.getValue();
if (keyFile == null) {
throw new IllegalStateException("Cannot find key file");
}
String[] usernames = getUserNames(adminFileAuthRealm.getName());
if (usernames.length == 1) {
try {
habitat.getService(com.sun.enterprise.security.SecurityLifecycle.class);
LoginContextDriver.login(usernames[0], new char[0], ADMIN_REALM);
user = usernames[0];
} catch (Exception e) {
}
}
return user;
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class SupportsUserManagementCommand method supportsUserManagement.
private boolean supportsUserManagement(String realmName) throws BadRealmException, NoSuchRealmException {
Realm r = realmsManager.getFromLoadedRealms(config.getName(), realmName);
if (r != null) {
return r.supportsUserManagement();
}
List<AuthRealm> authRealmConfigs = config.getSecurityService().getAuthRealm();
for (AuthRealm authRealm : authRealmConfigs) {
if (realmName.equals(authRealm.getName())) {
List<Property> propConfigs = authRealm.getProperty();
Properties props = new Properties();
for (Property p : propConfigs) {
String value = p.getValue();
props.setProperty(p.getName(), value);
}
r = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
return r.supportsUserManagement();
}
}
throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", new Object[] { realmName }));
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class SynchronizeRealmFromConfig method instantiateRealm.
private boolean instantiateRealm(Config cfg, String realmName) throws BadRealmException, NoSuchRealmException {
List<AuthRealm> authRealmConfigs = cfg.getSecurityService().getAuthRealm();
for (AuthRealm authRealm : authRealmConfigs) {
if (realmName.equals(authRealm.getName())) {
List<Property> propConfigs = authRealm.getProperty();
Properties props = new Properties();
for (Property p : propConfigs) {
String value = p.getValue();
props.setProperty(p.getName(), value);
}
Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, cfg.getName());
return true;
}
}
throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", new Object[] { realmName }));
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class RealmsImpl method _loadRealms.
private void _loadRealms() {
if (realmsLoaded)
throw new IllegalStateException();
final List<AuthRealm> authRealms = getAuthRealms();
final List<String> goodRealms = new ArrayList<String>();
for (final AuthRealm authRealm : authRealms) {
final List<Property> propList = authRealm.getProperty();
final Properties props = new Properties();
for (final Property p : propList) {
props.setProperty(p.getName(), p.getValue());
}
try {
Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props);
goodRealms.add(authRealm.getName());
} catch (final Exception e) {
AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(authRealm), e.getLocalizedMessage() });
}
}
if (goodRealms.size() != 0) {
final String goodRealm = goodRealms.iterator().next();
try {
final String defaultRealm = getSecurityService().getDefaultRealm();
Realm.getInstance(defaultRealm);
Realm.setDefaultRealm(defaultRealm);
} catch (final Exception e) {
AMXLoggerInfo.getLogger().log(Level.WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(goodRealm), e.getLocalizedMessage() });
Realm.setDefaultRealm(goodRealms.iterator().next());
}
}
realmsLoaded = true;
}
use of org.jvnet.hk2.config.types.Property in project Payara by payara.
the class ModuleInfo method save.
/**
* Saves its state to the configuration. this method must be called within a transaction
* to the configured module instance.
*
* @param module the module being persisted
*/
public void save(Module module) throws TransactionFailure, PropertyVetoException {
// write out the module properties only for composite app
if (Boolean.valueOf(moduleProps.getProperty(ServerTags.IS_COMPOSITE))) {
moduleProps.remove(ServerTags.IS_COMPOSITE);
for (Iterator itr = moduleProps.keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
Property prop = module.createChild(Property.class);
module.getProperty().add(prop);
prop.setName(propName);
prop.setValue(moduleProps.getProperty(propName));
}
}
for (EngineRef ref : _getEngineRefs()) {
Engine engine = module.createChild(Engine.class);
module.getEngines().add(engine);
ref.save(engine);
}
}
Aggregations