use of com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class GetGroupNamesCommand method getGroupNames.
private String[] getGroupNames(String realmName, String userName) throws NoSuchRealmException, BadRealmException, InvalidOperationException, NoSuchUserException {
// account for updates to file-realm contents from outside this config
// which are sharing the same keyfile
realmsManager.refreshRealm(config.getName(), realmName);
Realm realm = realmsManager.getFromLoadedRealms(config.getName(), realmName);
if (realm != null) {
return getGroupNames(realm, userName);
}
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);
}
realm = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
return getGroupNames(realm, userName);
}
}
throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", 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(WARNING, AMXLoggerInfo.cantInstantiateRealm, new Object[] { StringUtil.quote(authRealm), e.getLocalizedMessage() });
}
}
if (!goodRealms.isEmpty()) {
String goodRealm = goodRealms.iterator().next();
try {
String defaultRealm = getSecurityService().getDefaultRealm();
Realm.getInstance(defaultRealm);
Realm.setDefaultRealm(defaultRealm);
} catch (final Exception e) {
AMXLoggerInfo.getLogger().log(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 GenericAdminAuthenticator method postConstruct.
@Override
public synchronized void postConstruct() {
secureAdmin = domain.getSecureAdmin();
// Ensure that the admin password is set as required
if (as.usesFileRealm()) {
try {
AuthRealm ar = as.getAssociatedAuthRealm();
if (FileRealm.class.getName().equals(ar.getClassname())) {
String adminKeyFilePath = ar.getPropertyValue("file");
FileRealm fr = new FileRealm(adminKeyFilePath);
if (!fr.hasAuthenticatableUser()) {
ADMSEC_LOGGER.log(Level.SEVERE, AdminLoggerInfo.mSecureAdminEmptyPassword);
throw new IllegalStateException(ADMSEC_LOGGER.getResourceBundle().getString(AdminLoggerInfo.mSecureAdminEmptyPassword));
}
}
} catch (Exception ex) {
ADMSEC_LOGGER.log(Level.SEVERE, AdminLoggerInfo.mUnexpectedException, ex);
throw new RuntimeException(ex);
}
}
}
use of com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class VirtualServer method configureAuthRealm.
/**
* Configures this virtual server with its authentication realm.
*
* Checks if this virtual server specifies any authRealm property, and if so, ensures that its value identifies a valid
* realm.
*
* @param securityService The security-service element from domain.xml
*/
void configureAuthRealm(SecurityService securityService) {
_logger.finest(() -> String.format("configureAuthRealm(securityService=%s)", securityService));
List<Property> properties = vsBean.getProperty();
if (properties != null && !properties.isEmpty()) {
for (Property property : properties) {
if (property != null && "authRealm".equals(property.getName())) {
authRealmName = property.getValue();
if (authRealmName != null) {
AuthRealm validAuthRealm = null;
List<AuthRealm> authRealms = securityService.getAuthRealm();
if (authRealms != null && authRealms.size() > 0) {
for (AuthRealm authRealm : authRealms) {
if (authRealm != null && authRealm.getName().equals(authRealmName)) {
_logger.config(() -> "Using realm '" + authRealmName + "' for the security service '" + securityService + "'");
validAuthRealm = authRealm;
break;
}
}
}
if (validAuthRealm == null) {
_logger.log(SEVERE, INVALID_AUTH_REALM, new Object[] { getID(), authRealmName });
}
}
break;
}
}
}
}
use of com.sun.enterprise.config.serverbeans.AuthRealm in project Payara by payara.
the class SupportsUserManagementCommand method supportsUserManagement.
private boolean supportsUserManagement(String realmName) throws BadRealmException, NoSuchRealmException {
Realm realm = realmsManager.getFromLoadedRealms(config.getName(), realmName);
if (realm != null) {
return realm.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);
}
realm = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
return realm.supportsUserManagement();
}
}
throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", realmName));
}
Aggregations