use of com.sun.enterprise.config.serverbeans.AuthRealm 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 com.sun.enterprise.config.serverbeans.AuthRealm 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 com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class EmbeddedSecurityUtil method getKeyFileNames.
public List<String> getKeyFileNames(SecurityService securityService) {
List<String> keyFileNames = new ArrayList<String>();
List<AuthRealm> authRealms = securityService.getAuthRealm();
for (AuthRealm authRealm : authRealms) {
String className = authRealm.getClassname();
if ("com.sun.enterprise.security.auth.realm.file.FileRealm".equals(className)) {
List<Property> props = authRealm.getProperty();
for (Property prop : props) {
if ("file".equals(prop.getName())) {
keyFileNames.add(prop.getValue());
}
}
}
}
return keyFileNames;
}
use of com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class SecureAdminHelperImpl method adminRealm.
private FileRealm adminRealm() throws BadRealmException, NoSuchRealmException {
final AuthRealm ar = as.getAssociatedAuthRealm();
if (FileRealm.class.getName().equals(ar.getClassname())) {
String adminKeyFilePath = ar.getPropertyValue("file");
FileRealm fr = new FileRealm(adminKeyFilePath);
return fr;
}
return null;
}
use of com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class RealmConfig method createRealms.
public static void createRealms(String defaultRealm, List<AuthRealm> realms, String configName) {
assert (realms != null);
// need at least one good realm
String goodRealm = null;
for (AuthRealm aRealm : realms) {
String realmName = aRealm.getName();
String realmClass = aRealm.getClassname();
assert (realmName != null);
assert (realmClass != null);
try {
List<Property> realmProps = aRealm.getProperty();
/*V3 Commented ElementProperty[] realmProps =
aRealm.getElementProperty();*/
Properties props = new Properties();
for (Property realmProp : realmProps) {
props.setProperty(realmProp.getName(), realmProp.getValue());
}
Realm.instantiate(realmName, realmClass, props, configName);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Configured realm: " + realmName);
}
if (goodRealm == null) {
goodRealm = realmName;
}
} catch (Exception e) {
logger.log(Level.WARNING, SecurityLoggerInfo.realmConfigDisabledError, realmName);
logger.log(Level.WARNING, SecurityLoggerInfo.securityExceptionError, e);
}
}
if (goodRealm == null) {
logger.severe(SecurityLoggerInfo.noRealmsError);
} else {
try {
Realm.getInstance(defaultRealm);
} catch (Exception e) {
defaultRealm = goodRealm;
}
Realm.setDefaultRealm(defaultRealm);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Default realm is set to: " + defaultRealm);
}
}
}
Aggregations