use of com.sun.management.snmp.SnmpStatusException in project OpenAM by OpenRock.
the class SsoServerLoggingSvcImpl method init.
private void init(SnmpMib myMib, MBeanServer server) {
if (debug == null) {
debug = Debug.getInstance("amMonitoring");
}
String classModule = "SsoServerLoggingServiceImpl.init:";
if (isBogus) {
int ind = 1;
// DB Handler
lg_dbh = new SsoServerLoggingHdlrEntryImpl(myMib);
lg_dbh.LoggingHdlrName = DB_HANDLER_NAME;
lg_dbh.LoggingHdlrIndex = new Integer(ind++);
final ObjectName dbhName = lg_dbh.createSsoServerLoggingHdlrEntryObjectName(server);
try {
SsoServerLoggingHdlrTable.addEntry(lg_dbh, dbhName);
if ((server != null) && (dbhName != null)) {
server.registerMBean(lg_dbh, dbhName);
}
handlerMap.put(DB_HANDLER_NAME, lg_dbh);
} catch (JMException ex) {
debug.error(classModule + DB_HANDLER_NAME, ex);
} catch (SnmpStatusException ex) {
debug.error(classModule + DB_HANDLER_NAME, ex);
}
// File Handler
lg_fh = new SsoServerLoggingHdlrEntryImpl(myMib);
lg_fh.LoggingHdlrName = FILE_HANDLER_NAME;
lg_fh.LoggingHdlrIndex = new Integer(ind++);
final ObjectName fhName = lg_fh.createSsoServerLoggingHdlrEntryObjectName(server);
try {
SsoServerLoggingHdlrTable.addEntry(lg_fh, fhName);
if ((server != null) && (fhName != null)) {
server.registerMBean(lg_fh, fhName);
}
handlerMap.put(FILE_HANDLER_NAME, lg_fh);
} catch (JMException ex) {
debug.error(classModule + FILE_HANDLER_NAME, ex);
} catch (SnmpStatusException ex) {
debug.error(classModule + FILE_HANDLER_NAME, ex);
}
// Secure File Handler
lg_sfh = new SsoServerLoggingHdlrEntryImpl(myMib);
lg_sfh.LoggingHdlrName = SECURE_FILE_HANDLER_NAME;
lg_sfh.LoggingHdlrIndex = new Integer(ind++);
final ObjectName sfhName = lg_sfh.createSsoServerLoggingHdlrEntryObjectName(server);
try {
SsoServerLoggingHdlrTable.addEntry(lg_sfh, sfhName);
if ((server != null) && (sfhName != null)) {
server.registerMBean(lg_sfh, sfhName);
}
handlerMap.put(SECURE_FILE_HANDLER_NAME, lg_sfh);
} catch (JMException ex) {
debug.error(classModule + SECURE_FILE_HANDLER_NAME, ex);
} catch (SnmpStatusException ex) {
debug.error(classModule + SECURE_FILE_HANDLER_NAME, ex);
}
// Remote Handler
lg_rh = new SsoServerLoggingHdlrEntryImpl(myMib);
lg_rh.LoggingHdlrName = REMOTE_HANDLER_NAME;
lg_rh.LoggingHdlrIndex = new Integer(ind++);
final ObjectName rhName = lg_rh.createSsoServerLoggingHdlrEntryObjectName(server);
try {
SsoServerLoggingHdlrTable.addEntry(lg_rh, rhName);
if ((server != null) && (rhName != null)) {
server.registerMBean(lg_rh, rhName);
}
handlerMap.put(REMOTE_HANDLER_NAME, lg_rh);
} catch (JMException ex) {
debug.error(classModule + REMOTE_HANDLER_NAME, ex);
} catch (SnmpStatusException ex) {
debug.error(classModule + REMOTE_HANDLER_NAME, ex);
}
}
}
use of com.sun.management.snmp.SnmpStatusException in project OpenAM by OpenRock.
the class Agent method realmConfigMonitoringAgent.
/**
* process configuration for a realm
*/
public static int realmConfigMonitoringAgent(SSOServerRealmInfo rlmInfo) {
String classMethod = "Agent.realmConfigMonitoringAgent:";
String realm = rlmInfo.realmName;
Map<String, String> authMods = rlmInfo.authModules;
Integer realmIndex = realm2Index.get(realm);
if (realmIndex == null) {
debug.error(classMethod + "could not find realm " + realm + " in realm2Index map");
return -1;
}
SsoServerAuthSvcImpl sig = sunMib.getAuthSvcGroup();
TableSsoServerAuthModulesTable atab = null;
if (sig != null) {
try {
atab = sig.accessSsoServerAuthModulesTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting auth table: ", ex);
return -2;
}
}
StringBuilder sb = new StringBuilder();
if (debug.messageEnabled()) {
sb.append("receiving config info for realm = ").append(realm).append(":\n Authentication Modules:\n");
}
/*
* auth module table entries have realm index, and auth module index
*/
int i = 1;
for (Map.Entry<String, String> entry : authMods.entrySet()) {
String modInst = entry.getKey();
String modType = entry.getValue();
if (debug.messageEnabled()) {
sb.append(" instance = ").append(modInst).append(", value(type) = ").append(modType).append("\n");
}
SsoServerAuthModulesEntryImpl aei = new SsoServerAuthModulesEntryImpl(sunMib);
aei.SsoServerRealmIndex = realmIndex;
aei.AuthModuleIndex = new Integer(i++);
aei.AuthModuleName = modInst;
aei.AuthModuleType = getEscapedString(modType);
aei.AuthModuleSuccessCount = 0L;
aei.AuthModuleFailureCount = 0L;
ObjectName aname = aei.createSsoServerAuthModulesEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for auth module name '" + modInst + "', type '" + modType + "'");
continue;
}
try {
atab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
/* is a Map of realm/authmodule to index needed? */
String rai = realm + "|" + modInst;
// aei is this module's SsoServerAuthModulesEntryImpl instance
realmAuthInst.put(rai, aei);
} catch (JMException ex) {
debug.error(classMethod + modInst, ex);
} catch (SnmpStatusException ex) {
debug.error(classMethod + modInst, ex);
}
}
// if no realm info added because mbean not created...
if (realmAuthInst.isEmpty()) {
return -3;
}
if (debug.messageEnabled()) {
debug.message(classMethod + sb.toString());
}
return 0;
}
use of com.sun.management.snmp.SnmpStatusException in project OpenAM by OpenRock.
the class Agent method startAgent.
/**
* This method starts up the monitoring agent from the
* common/ConfigMonitoring module (load-on-startup or at the
* end of AMSetupServlet/configuration). Since web-app startup
* is sensitive to exceptions in load-on-startup stuff, this has
* quite a few try/catch blocks.
*
* If any of HTML, SNMP, or RMI adaptors has a problem getting created
* or started, attempts to create/start the others will be made; If
* at least one adaptor is started, monitoring will be "active"
* (Agent.isRunning() will return true).
*
* @param monConfig SSOServerMonConfig structure of OpenAM configuration
* @return 0 (zero) if at least one of HTML/SNMP/RMI adaptors started up;
* MON_CONFIG_DISABLED:
* if monitoring configured as disabled
* MON_MBEANSRVR_PROBLEM:
* if MBeanServer problem encountered
* MON_RMICONNECTOR_PROBLEM:
* if RMI connector problem
* (MIB not registered with MBeanServer)
* MON_CREATEMIB_PROBLEM:
* if problem creating/registering MIB
*/
public static int startAgent(SSOServerMonConfig monConfig) {
monHtmlPort = monConfig.htmlPort;
monSnmpPort = monConfig.snmpPort;
monRmiPort = monConfig.rmiPort;
monitoringEnabled = monConfig.monitoringEnabled;
monHtmlPortEnabled = monConfig.monHtmlPortEnabled;
monSnmpPortEnabled = monConfig.monSnmpPortEnabled;
monRmiPortEnabled = monConfig.monRmiPortEnabled;
monAuthFilePath = monConfig.monAuthFilePath;
policyWindow = monConfig.policyWindow;
sessionWindow = monConfig.sessionWindow;
String classMethod = "Agent.startAgent:";
// OpenAM server port comes from WebtopNaming.siteAndServerInfo
String serverPort = agentSvrInfo.serverPort;
// Check for Legacy MonAuthFile.
if ((monAuthFilePath != null) && (monAuthFilePath.endsWith("opensso_mon_auth"))) {
// Perform a rename of the old filename to the latest naming.
File monAuthFile = new File(monAuthFilePath);
File newMonAuthFile = new File(monAuthFile.getParentFile() + "/" + "openam_mon_auth");
if (monAuthFile.renameTo(newMonAuthFile)) {
monAuthFilePath = newMonAuthFile.getAbsolutePath();
}
}
/*
* there are a lot of exception checks in this method, as
* it's invoked from a load-on-startup servlet. if it
* chokes in here, OpenAM won't start up.
*/
if (debug.messageEnabled()) {
debug.message(classMethod + "entry:\n" + " htmlPort = " + monHtmlPort + "\n" + " authFilePath = " + monAuthFilePath + "\n" + " snmpPort = " + monSnmpPort + "\n" + " rmiPort = " + monRmiPort + "\n" + " monEna = " + monitoringEnabled + "\n" + " htmlEna = " + monHtmlPortEnabled + "\n" + " snmpEna = " + monSnmpPortEnabled + "\n" + " rmiEna = " + monRmiPortEnabled + "\n" + " policyWindow = " + policyWindow + "\n" + " sessionWindow = " + sessionWindow + "\n" + " serverPort = " + serverPort + "\n");
}
if (!monitoringEnabled) {
debug.warning(classMethod + "Monitoring configured as disabled.");
return MON_CONFIG_DISABLED;
}
/*
* verify that the HTML, SNMP and RMI ports aren't the same as
* the OpenAM server port. if HTML or SNMP conflict with it,
* then they'll be disabled (warning message). if the RMI port
* conflicts, then all of monitoring is disabled. there might
* be other ports that should be checked.
*/
try {
int sport = Integer.parseInt(serverPort);
if (monRmiPort == sport) {
debug.error(classMethod + "RMI port conflicts with OpenSSO server port (" + sport + "); Monitoring disabled.");
return MON_RMICONNECTOR_PROBLEM;
}
if (monHtmlPort == sport) {
monHtmlPortEnabled = false;
if (debug.warningEnabled()) {
debug.warning(classMethod + "HTML port conflicts with OpenSSO server port (" + sport + "); Monitoring HTML port disabled.");
}
}
if (monSnmpPort == sport) {
monSnmpPortEnabled = false;
if (debug.warningEnabled()) {
debug.warning(classMethod + "SNMP port conflicts with OpenSSO server port (" + sport + "); Monitoring SNMP port disabled.");
}
}
} catch (NumberFormatException nfe) {
/*
* odd. if serverPort's not a valid int, then there'll be
* other problems
*/
debug.error(classMethod + "Server port (" + serverPort + " is invalid: " + nfe.getMessage());
}
if (debug.messageEnabled()) {
debug.message(classMethod + "config:\n" + " monitoring Enabled = " + monitoringEnabled + "\n" + " HTML Port = " + monHtmlPort + ", enabled = " + monHtmlPortEnabled + "\n" + " SNMP Port = " + monSnmpPort + ", enabled = " + monSnmpPortEnabled + "\n" + " RMI Port = " + monRmiPort + ", enabled = " + monRmiPortEnabled + "\n" + " SessionWindow size = " + sessionWindow + "\n" + " PolicyWindow size = " + policyWindow + "\n");
}
/*
* if OpenAM's deployed on a container that has MBeanServer(s),
* will the findMBeanServer(null) "find" those? if so,
* is using the first one the right thing to do?
*/
List<MBeanServer> servers = null;
try {
servers = MBeanServerFactory.findMBeanServer(null);
} catch (SecurityException ex) {
/*
* if can't find one, try creating one below, although
* if there's no findMBeanServer permission, it's unlikely
* that there's a createMBeanServer permission...
*/
if (debug.warningEnabled()) {
debug.warning(classMethod + "findMBeanServer permission error: " + ex.getMessage());
}
}
if (debug.messageEnabled()) {
debug.message(classMethod + "MBeanServer list is not empty: " + ((servers != null) && !servers.isEmpty()));
}
if ((servers != null) && !servers.isEmpty()) {
server = servers.get(0);
} else {
try {
server = MBeanServerFactory.createMBeanServer();
} catch (SecurityException ex) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "createMBeanServer permission error: " + ex.getMessage());
}
return MON_MBEANSRVR_PROBLEM;
} catch (JMRuntimeException ex) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "createMBeanServer JMRuntime error: " + ex.getMessage());
}
return MON_MBEANSRVR_PROBLEM;
} catch (ClassCastException ex) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "createMBeanServer ClassCast error: " + ex.getMessage());
}
return MON_MBEANSRVR_PROBLEM;
}
}
if (server == null) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "no MBeanServer");
}
return MON_MBEANSRVR_PROBLEM;
}
// throws no exception
String domain = server.getDefaultDomain();
// Create the MIB II (RFC 1213), add to the MBean server.
try {
sunMibObjName = new ObjectName("snmp:class=SUN_OPENSSO_SERVER_MIB");
forgerockCtsMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_CTS_MIB");
forgerockPolicyMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_POLICY_MIB");
forgerockSessionMibObjName = new ObjectName("snmp:class=FORGEROCK_OPENAM_SESSION_MIB");
if (debug.messageEnabled()) {
debug.message(classMethod + "Adding SUN_OPENSSO_SERVER_MIB to MBean server " + "with name '" + sunMibObjName + "'");
debug.message(classMethod + "Adding FORGEROCK_OPENAM_CTS_MIB to MBean server " + "with name '" + forgerockCtsMibObjName + "'");
}
} catch (MalformedObjectNameException ex) {
// from ObjectName
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error getting ObjectName for the MIB: " + ex.getMessage());
}
return MON_CREATEMIB_PROBLEM;
}
// Create an instance of the customized MIB
try {
sunMib = new SUN_OPENSSO_SERVER_MIBImpl();
forgerockCtsMib = new FORGEROCK_OPENAM_CTS_MIBImpl();
forgerockPolicyMib = new FORGEROCK_OPENAM_POLICY_MIBImpl();
forgerockSessionMib = new FORGEROCK_OPENAM_SESSION_MIBImpl();
} catch (RuntimeException ex) {
debug.error(classMethod + "Runtime error instantiating MIB", ex);
return MON_CREATEMIB_PROBLEM;
} catch (Exception ex) {
debug.error(classMethod + "Error instantiating MIB", ex);
return MON_CREATEMIB_PROBLEM;
}
try {
server.registerMBean(sunMib, sunMibObjName);
server.registerMBean(forgerockCtsMib, forgerockCtsMibObjName);
server.registerMBean(forgerockPolicyMib, forgerockPolicyMibObjName);
server.registerMBean(forgerockSessionMib, forgerockSessionMibObjName);
} catch (RuntimeOperationsException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Null parameter or no object name for MIB specified: " + ex.getMessage());
}
return MON_CREATEMIB_PROBLEM;
} catch (InstanceAlreadyExistsException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
}
// probably can just continue
} catch (MBeanRegistrationException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
}
return MON_CREATEMIB_PROBLEM;
} catch (NotCompliantMBeanException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering MIB MBean: " + ex.getMessage());
}
return MON_CREATEMIB_PROBLEM;
}
/*
* now that we have the MBeanServer, see if the HTML,
* SNMP and RMI adaptors specified will start up
*/
boolean monHTMLStarted = false;
boolean monSNMPStarted = false;
boolean monRMIStarted = false;
// HTML port adaptor
if (monHtmlPortEnabled) {
// Create and start the HTML adaptor.
try {
htmlObjName = new ObjectName(domain + ":class=HtmlAdaptorServer,protocol=html,port=" + monHtmlPort);
if (debug.messageEnabled()) {
debug.message(classMethod + "Adding HTML adaptor to MBean server with name '" + htmlObjName + "'\n " + "HTML adaptor is bound on TCP port " + monHtmlPort);
}
Map<String, String> users = MonitoringUtil.getMonAuthList(monAuthFilePath);
if (users != null) {
AuthInfo[] authInfo = new AuthInfo[users.size()];
int i = 0;
for (Map.Entry<String, String> entry : users.entrySet()) {
authInfo[i] = new AuthInfo(entry.getKey(), entry.getValue());
i++;
}
htmlAdaptor = new HtmlAdaptorServer(monHtmlPort, authInfo);
} else {
if (debug.warningEnabled()) {
debug.warning(classMethod + "HTML monitoring interface disabled; no " + "authentication file found");
}
htmlAdaptor = null;
}
if (htmlAdaptor == null) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "HTTP port " + monHtmlPort + " unavailable or invalid. " + "Monitoring HTML adaptor not started.");
}
} else {
server.registerMBean(htmlAdaptor, htmlObjName);
// throws no exception
htmlAdaptor.start();
monHTMLStarted = true;
}
} catch (MalformedObjectNameException ex) {
// from ObjectName
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error getting ObjectName for HTML adaptor: " + ex.getMessage());
}
} catch (NullPointerException ex) {
// from ObjectName
debug.error(classMethod + "NPE getting ObjectName for HTML adaptor", ex);
if (debug.warningEnabled()) {
debug.warning(classMethod + "NPE getting ObjectName for HTML adaptor: " + ex.getMessage());
}
} catch (InstanceAlreadyExistsException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
}
} catch (MBeanRegistrationException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
}
} catch (NotCompliantMBeanException ex) {
// from registerMBean
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error registering HTML adaptor MBean: " + ex.getMessage());
}
}
} else {
debug.warning(classMethod + "Monitoring HTML port not enabled in configuration.");
}
// SNMP port adaptor
if (monSnmpPortEnabled) {
/*
* Create and start the SNMP adaptor.
* Specify the port to use in the constructor.
* The standard port for SNMP is 161.
*/
try {
snmpObjName = new ObjectName(domain + ":class=SnmpAdaptorServer,protocol=snmp,port=" + monSnmpPort);
if (debug.messageEnabled()) {
debug.message(classMethod + "Adding SNMP adaptor to MBean server with name '" + snmpObjName + "'\n " + "SNMP Adaptor is bound on UDP port " + monSnmpPort);
}
// no exc
snmpAdaptor = new SnmpAdaptorServer(monSnmpPort);
if (snmpAdaptor == null) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "Unable to get SNMP adaptor.");
}
} else {
server.registerMBean(snmpAdaptor, snmpObjName);
// throws no exception
snmpAdaptor.start();
/*
* Send a coldStart SNMP Trap.
* Use port = monSnmpPort+1.
*/
if (debug.messageEnabled()) {
debug.message(classMethod + "Sending a coldStart SNMP trap to each " + "destination defined in the ACL file...");
}
snmpAdaptor.setTrapPort(new Integer(monSnmpPort + 1));
snmpAdaptor.snmpV1Trap(0, 0, null);
if (debug.messageEnabled()) {
debug.message(classMethod + "Done sending coldStart.");
}
/*
* Bind the SNMP adaptor to the MIB in order to make the
* MIB accessible through the SNMP protocol adaptor.
* If this step is not performed, the MIB will still live
* in the Java DMK agent:
* its objects will be addressable through HTML but not
* SNMP.
*/
// throws no exception
sunMib.setSnmpAdaptor(snmpAdaptor);
forgerockCtsMib.setSnmpAdaptor(snmpAdaptor);
forgerockPolicyMib.setSnmpAdaptor(snmpAdaptor);
forgerockSessionMib.setSnmpAdaptor(snmpAdaptor);
monSNMPStarted = true;
}
} catch (Exception ex) {
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error while setting up SNMP adaptor " + ex.getMessage());
}
if (ex instanceof IOException || ex instanceof SnmpStatusException) {
// should be from the snmpV1Trap call, which
//*shouldn't* affect the rest of snmp operations...
monSNMPStarted = true;
}
}
} else {
debug.warning(classMethod + "Monitoring SNMP port not enabled.");
}
// RMI port adaptor
if (monRmiPortEnabled) {
// Create an RMI connector and start it
try {
registry = LocateRegistry.createRegistry(monRmiPort);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + monRmiPort + "/server");
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
cs.start();
monRMIStarted = true;
// /*
// * Create a LinkTrapGenerator.
// * Specify the ifIndex to use in the object name.
// */
// String trapGeneratorClass = "LinkTrapGenerator";
// int ifIndex = 1;
// trapGeneratorObjName = new ObjectName("trapGenerator" +
// ":class=LinkTrapGenerator,ifIndex=" + ifIndex);
// if (debug.messageEnabled()) {
// debug.message(classMethod +
// "Adding LinkTrapGenerator to MBean server " +
// "with name '" +
// trapGeneratorObjName + "'");
// }
//
// LinkTrapGenerator trapGenerator =
// new LinkTrapGenerator(nbTraps);
// server.registerMBean(trapGenerator, trapGeneratorObjName);
//
} catch (MalformedURLException ex) {
/*
* from JMXServiceURL or
* JMXConnectorServerFactory.JMXConnectorServer
*/
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: " + ex.getMessage());
}
} catch (NullPointerException ex) {
/*
* from JMXServiceURL or
* JMXConnectorServerFactory.JMXConnectorServer
*/
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error getting JMXServiceURL or JMXConnectorServer " + "for RMI adaptor: " + ex.getMessage());
}
} catch (IOException ex) {
/*
* from JMXConnectorServerFactory.JMXConnectorServer or
* JMXConnectorServer.start
*/
if (debug.warningEnabled()) {
debug.warning(classMethod + "Error getting JMXConnectorServer for, or starting " + "RMI adaptor: " + ex.getMessage());
}
} catch (IllegalStateException ex) {
// from JMXConnectorServer.start
if (debug.warningEnabled()) {
debug.warning(classMethod + "Illegal State Error from JMXConnectorServer for " + "RMI adaptor: " + ex.getMessage());
}
} catch (Exception ex) {
/*
* compiler says that JMXProviderException and
* NullPointerException already caught
*/
debug.error(classMethod + "Error starting RMI: executing rmiregistry " + monRmiPort + ".", ex);
}
} else {
debug.warning(classMethod + "Monitoring RMI port not enabled.");
}
/*
* the HTML and SNMP adaptors may or may not be started,
* but if the RMI connector had a problem, monitoring is
* non-functional, as the opensso MIB didn't get registered.
*/
if (!monRMIStarted && !monSNMPStarted && !monHTMLStarted) {
debug.warning(classMethod + "No Monitoring interfaces started; monitoring disabled.");
return MON_RMICONNECTOR_PROBLEM;
} else {
// if all/enough has gone well
agentStarted = true;
startMonitoringAgent(agentSvrInfo);
return 0;
}
}
use of com.sun.management.snmp.SnmpStatusException in project OpenAM by OpenRock.
the class Agent method saml1TPConfig.
/**
* process saml1.x trusted partners (global)
*/
public static int saml1TPConfig(List<String> s1TPInfo) {
String classMethod = "Agent.saml1TPConfig:";
StringBuilder sb = new StringBuilder(classMethod);
int sz = s1TPInfo.size();
// until instrumentation done
boolean skipSAML1EndPoints = true;
Date startDate = new Date();
if (debug.messageEnabled()) {
sb.append("number of SAML1 Trusted Partners = ").append(sz).append("\n");
}
if (server == null) {
// can't do anything without a server
debug.error(classMethod + "no server");
return -1;
}
for (int i = 0; i < sz; i++) {
String pName = s1TPInfo.get(i);
if (debug.messageEnabled()) {
sb.append(" ").append(pName).append("\n");
}
SsoServerSAML1TrustPrtnrsEntryImpl sstpe = new SsoServerSAML1TrustPrtnrsEntryImpl(sunMib);
sstpe.SAML1TrustPrtnrIndex = new Integer(i + 1);
sstpe.SAML1TrustPrtnrName = getEscapedString(pName);
SsoServerSAML1Svc sss = (SsoServerSAML1SvcImpl) sunMib.getSaml1SvcGroup();
TableSsoServerSAML1TrustPrtnrsTable tptab = null;
if (sss != null) {
try {
tptab = sss.accessSsoServerSAML1TrustPrtnrsTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting SAML1 trusted partner table: ", ex);
// can't do anything without the table
return -2;
}
}
if (tptab == null) {
// can't do anything without the table
return -2;
}
ObjectName aname = sstpe.createSsoServerSAML1TrustPrtnrsEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 Trusted Partner '" + pName + "'");
continue;
}
try {
tptab.addEntry(sstpe, aname);
if (sstpe != null) {
server.registerMBean(sstpe, aname);
}
} catch (JMException ex) {
debug.error(classMethod + pName + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + pName + ": " + ex.getMessage());
}
}
if (debug.messageEnabled()) {
debug.message(sb.toString());
}
/*
* while we're here, setup the
* SAML1 Cache table (Artifacts and Assertions)
* SAML1 Endpoints for SOAPReceiver, POSTProfile,
* SAMLAware/ArtifactProfile
*/
// assertions
SsoServerSAML1CacheEntryImpl ssce = new SsoServerSAML1CacheEntryImpl(sunMib);
ssce.SAML1CacheIndex = Integer.valueOf(1);
ssce.SAML1CacheName = "Assertion_Cache";
ssce.SAML1CacheMisses = 0L;
ssce.SAML1CacheHits = 0L;
ssce.SAML1CacheWrites = 0L;
ssce.SAML1CacheReads = 0L;
SsoServerSAML1SvcImpl sss = sunMib.getSaml1SvcGroup();
TableSsoServerSAML1CacheTable tptab = null;
if (sss != null) {
try {
tptab = sss.accessSsoServerSAML1CacheTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting SAML1 Cache table: ", ex);
}
}
if (tptab != null) {
// if sss is null, so will tptab
sss.assertCache = ssce;
ObjectName aname = ssce.createSsoServerSAML1CacheEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 Assertion Cache");
} else {
try {
tptab.addEntry(ssce, aname);
if (ssce != null) {
server.registerMBean(ssce, aname);
}
} catch (JMException ex) {
debug.error(classMethod + "SAML1 Assertion Cache table: " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + "SAML1 Assertion Cache table: " + ex.getMessage());
}
}
// artifacts
ssce = new SsoServerSAML1CacheEntryImpl(sunMib);
ssce.SAML1CacheIndex = Integer.valueOf(2);
ssce.SAML1CacheName = "Artifact_Cache";
ssce.SAML1CacheMisses = 0L;
ssce.SAML1CacheHits = 0L;
ssce.SAML1CacheWrites = 0L;
ssce.SAML1CacheReads = 0L;
aname = ssce.createSsoServerSAML1CacheEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 Artifact Cache");
} else {
try {
tptab.addEntry(ssce, aname);
if (ssce != null) {
server.registerMBean(ssce, aname);
}
} catch (JMException ex) {
debug.error(classMethod + "SAML1 Artifact Cache table: " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + "SAML1 Artifact Cache table: " + ex.getMessage());
}
sss.artifactCache = ssce;
}
}
// SOAPReceiver endpoint
if (!skipSAML1EndPoints) {
SsoServerSAML1EndPointEntryImpl ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
ssee.SAML1EndPointIndex = Integer.valueOf(1);
ssee.SAML1EndPointName = "SOAPReceiver_EndPoint";
ssee.SAML1EndPointRqtFailed = 0L;
ssee.SAML1EndPointRqtOut = 0L;
ssee.SAML1EndPointRqtIn = 0L;
ssee.SAML1EndPointRqtAborted = 0L;
ssee.SAML1EndPointStatus = "operational";
TableSsoServerSAML1EndPointTable tetab = null;
if (sss != null) {
try {
tetab = sss.accessSsoServerSAML1EndPointTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting SAML1 EndPoint table: ", ex);
}
}
if (tetab != null) {
// if sss is null, so will tetab
ObjectName aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 SOAPReceiver_EndPoint");
} else {
try {
tetab.addEntry(ssee, aname);
if (ssee != null) {
server.registerMBean(ssee, aname);
}
} catch (JMException ex) {
debug.error(classMethod + "SAML1 SOAPReceiver EndPoint table: " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + "SAML1 SOAPReceiver EndPoint table: " + ex.getMessage());
}
sss.soapEP = ssee;
}
// POSTProfile table
ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
ssee.SAML1EndPointIndex = Integer.valueOf(2);
ssee.SAML1EndPointName = "POSTProfile_EndPoint";
ssee.SAML1EndPointRqtFailed = 0L;
ssee.SAML1EndPointRqtOut = 0L;
ssee.SAML1EndPointRqtIn = 0L;
ssee.SAML1EndPointRqtAborted = 0L;
ssee.SAML1EndPointStatus = "operational";
aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 POSTProfile_EndPoint");
} else {
try {
tetab.addEntry(ssee, aname);
if (ssee != null) {
server.registerMBean(ssee, aname);
}
} catch (JMException ex) {
debug.error(classMethod + "SAML1 POSTProfile EndPoint table: " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + "SAML1 POSTProfile EndPoint table: " + ex.getMessage());
}
sss.pprofEP = ssee;
}
// SAMLAware/ArtifactProfile table
ssee = new SsoServerSAML1EndPointEntryImpl(sunMib);
ssee.SAML1EndPointIndex = Integer.valueOf(3);
ssee.SAML1EndPointName = "SAMLAware_EndPoint";
ssee.SAML1EndPointRqtFailed = 0L;
ssee.SAML1EndPointRqtOut = 0L;
ssee.SAML1EndPointRqtIn = 0L;
ssee.SAML1EndPointRqtAborted = 0L;
ssee.SAML1EndPointStatus = "operational";
aname = ssee.createSsoServerSAML1EndPointEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for SAML1 SAMLAware_EndPoint");
} else {
try {
tetab.addEntry(ssee, aname);
if (ssee != null) {
server.registerMBean(ssee, aname);
}
} catch (JMException ex) {
debug.error(classMethod + "SAML1 SAMLAware/ArtifactProfile EndPoint table: " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + "SAML1 SAMLAware/ArtifactProfile EndPoint table: " + ex.getMessage());
}
sss.samlAwareEP = ssee;
}
}
}
// if (!skipSAML1EndPoints)
Date stopDate = new Date();
if (debug.messageEnabled()) {
String stDate = sdf.format(startDate);
String endDate = sdf.format(stopDate);
debug.message("Agent.saml1TPConfig:\n Start Time = " + stDate + "\n End Time = " + endDate);
}
return 0;
}
use of com.sun.management.snmp.SnmpStatusException in project OpenAM by OpenRock.
the class Agent method configAgentsOnly.
/**
* process realm's Agents (only)
*
* the HashMap of attributes/values:
* CLIConstants.ATTR_NAME_AGENT_TYPE
* type is extracted from the set; can be:
* J2EEAgent, 2.2_Agent
* WebAgent
* don't do "SharedAgent" (authenticators)
*
* J2EEAgent should have:
* "com.sun.identity.agents.config.login.url"
* "com.sun.identity.client.notification.url"
* "groupmembership"
* WebAgent should have:
* "com.sun.identity.agents.config.agenturi.prefix"
* "com.sun.identity.agents.config.login.url"
* "groupmembership"
* 2.2_Agent should have:
* "groupmembership"
*/
public static void configAgentsOnly(String realm, Map<String, Map<String, String>> agtAttrs) {
String classMethod = "Agent.configAgentsOnly:";
if ((agtAttrs == null) || agtAttrs.isEmpty()) {
if (debug.messageEnabled()) {
debug.message(classMethod + "got null attr map for realm " + realm);
}
return;
}
SsoServerPolicyAgents sss = sunMib.getPolicyAgentsGroup();
TableSsoServerPolicy22AgentTable t22tab = null;
TableSsoServerPolicyJ2EEAgentTable j2eetab = null;
TableSsoServerPolicyWebAgentTable watab = null;
SsoServerWSSAgents ssa = sunMib.getWssAgentsGroup();
TableSsoServerWSSAgentsSTSAgentTable ststab = null;
TableSsoServerWSSAgentsWSPAgentTable wsptab = null;
TableSsoServerWSSAgentsWSCAgentTable wsctab = null;
TableSsoServerWSSAgentsDSCAgentTable dsctab = null;
/*
* get the tables
*/
if (sss != null) {
try {
t22tab = sss.accessSsoServerPolicy22AgentTable();
j2eetab = sss.accessSsoServerPolicyJ2EEAgentTable();
watab = sss.accessSsoServerPolicyWebAgentTable();
ststab = ssa.accessSsoServerWSSAgentsSTSAgentTable();
wsptab = ssa.accessSsoServerWSSAgentsWSPAgentTable();
wsctab = ssa.accessSsoServerWSSAgentsWSCAgentTable();
dsctab = ssa.accessSsoServerWSSAgentsDSCAgentTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting Agents tables: ", ex);
// can't do anything without the tables
return;
}
}
if (ssa != null) {
try {
ststab = ssa.accessSsoServerWSSAgentsSTSAgentTable();
wsptab = ssa.accessSsoServerWSSAgentsWSPAgentTable();
wsctab = ssa.accessSsoServerWSSAgentsWSCAgentTable();
dsctab = ssa.accessSsoServerWSSAgentsDSCAgentTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting WSS Agents tables: ", ex);
// can't do anything without the tables
return;
}
}
StringBuilder sb = new StringBuilder(classMethod);
if (debug.messageEnabled()) {
sb.append("agents for realm ").append(realm).append(", # = ").append(agtAttrs.size()).append("\n");
}
// index for web agents
int wai = 1;
// index for j2ee agents
int j2eei = 1;
// index for 2.2_agents
int t22i = 1;
// index for STS agents
int stsi = 1;
// index for WSP agents
int wspi = 1;
// index for WSC agents
int wsci = 1;
// index for DSC agents
int dsci = 1;
Integer ri = getRealmIndexFromName(realm);
/*
* if the realm isn't in the table, there's not much point
* in doing the rest
*/
if (ri == null) {
debug.error(classMethod + "didn't find index for realm " + realm);
return;
}
for (Map.Entry<String, Map<String, String>> entry : agtAttrs.entrySet()) {
String agtname = entry.getKey();
Map<String, String> hm = entry.getValue();
;
String atype = hm.get(Constants.ATTR_NAME_AGENT_TYPE);
String grpmem = hm.get("groupmembership");
// group and agent name can't have ":" in it, or jdmk gags
if (grpmem == null) {
grpmem = None;
} else {
grpmem = getEscapedString(grpmem);
}
agtname = getEscapedString(agtname);
if (debug.messageEnabled()) {
sb.append(" agent name = ").append(agtname).append(", type = ").append(atype).append(", membership = ").append(grpmem).append("\n");
}
if (atype.equals("WebAgent")) {
String aurl = hm.get("com.sun.identity.agents.config.agenturi.prefix");
String lurl = hm.get("com.sun.identity.agents.config.login.url");
SsoServerPolicyWebAgentEntryImpl aei = new SsoServerPolicyWebAgentEntryImpl(sunMib);
aei.SsoServerRealmIndex = ri;
aei.PolicyWebAgentIndex = new Integer(wai++);
aei.PolicyWebAgentName = agtname;
aei.PolicyWebAgentGroup = grpmem;
aei.PolicyWebAgentAgentURL = aurl;
aei.PolicyWebAgentServerURL = lurl;
ObjectName aname = aei.createSsoServerPolicyWebAgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy WebAgent '" + agtname + "'");
continue;
}
try {
watab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("2.2_Agent")) {
SsoServerPolicy22AgentEntryImpl aei = new SsoServerPolicy22AgentEntryImpl(sunMib);
aei.SsoServerRealmIndex = ri;
aei.Policy22AgentIndex = new Integer(t22i++);
aei.Policy22AgentName = agtname;
ObjectName aname = aei.createSsoServerPolicy22AgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy 2.2 Agent '" + agtname + "'");
continue;
}
try {
t22tab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("J2EEAgent")) {
SsoServerPolicyJ2EEAgentEntryImpl aei = new SsoServerPolicyJ2EEAgentEntryImpl(sunMib);
String aurl = hm.get("com.sun.identity.client.notification.url");
if (aurl == null) {
aurl = None;
}
String lurl = hm.get("com.sun.identity.agents.config.login.url");
aei.PolicyJ2EEAgentGroup = grpmem;
aei.PolicyJ2EEAgentAgentURL = aurl;
aei.PolicyJ2EEAgentServerURL = lurl;
aei.PolicyJ2EEAgentName = agtname;
aei.PolicyJ2EEAgentIndex = new Integer(j2eei++);
aei.SsoServerRealmIndex = ri;
ObjectName aname = aei.createSsoServerPolicyJ2EEAgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy J2EE Agent '" + agtname + "'");
continue;
}
try {
j2eetab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("SharedAgent")) {
// SharedAgent type are agent authenticators
} else {
debug.error(classMethod + "agent type = " + atype + ", agent name = " + agtname + " not supported.");
}
}
if (debug.messageEnabled()) {
debug.message(sb.toString());
}
}
Aggregations