当前位置: 首页>>代码示例>>Java>>正文


Java SecurityProtocols类代码示例

本文整理汇总了Java中org.snmp4j.security.SecurityProtocols的典型用法代码示例。如果您正苦于以下问题:Java SecurityProtocols类的具体用法?Java SecurityProtocols怎么用?Java SecurityProtocols使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityProtocols类属于org.snmp4j.security包,在下文中一共展示了SecurityProtocols类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: snmpMessageToHumanReadable

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
static PDU snmpMessageToHumanReadable(String s) throws IOException {
    final OctetString message = OctetString.fromHexString(s, ':');
    final Address address = new UdpAddress();
    final TransportMapping transportMapping = (address instanceof UdpAddress) ?
            new DefaultUdpTransportMapping((UdpAddress) address)
            : new DefaultTcpTransportMapping((TcpAddress) address);
    final MessageDispatcher messageDispatcher = new
            MessageDispatcherImpl();
    SecurityProtocols.getInstance().addDefaultProtocols();
    final SnmpMessageAnalyzer snmpMessageAnalyzer = new SnmpMessageAnalyzer();
    final CommandResponder commandResponder = snmpMessageAnalyzer;
    messageDispatcher.addCommandResponder(commandResponder);
    messageDispatcher.addMessageProcessingModel(new MPv1());
    messageDispatcher.addMessageProcessingModel(new MPv2c());
    messageDispatcher.addMessageProcessingModel(new MPv3());
    messageDispatcher.processMessage(transportMapping, address, ByteBuffer.wrap(message.getValue()));
    PDU result = snmpMessageAnalyzer.msg;
    snmpMessageAnalyzer.msg = null;
    return result;
}
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:21,代码来源:SnmpMessageAnalyzer.java

示例2: initialize

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/**
     * Initialize for v3 communications
     */
    private static void initialize() {
        if (s_initialized) {
            return;
        }

//      LogFactory.setLogFactory(new Log4jLogFactory());
            
        MPv3.setEnterpriseID(5813);
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        
        // Enable extensibility in SNMP4J so that we can subclass some SMI classes to work around
        // agent bugs
        if (System.getProperty("org.snmp4j.smisyntaxes", null) != null) {
        	SNMP4JSettings.setExtensibilityEnabled(true);
        }
        
        if (Boolean.getBoolean("org.opennms.snmp.snmp4j.forwardRuntimeExceptions")) {
        	SNMP4JSettings.setForwardRuntimeExceptions(true);
        }
        
        s_initialized = true;
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:27,代码来源:Snmp4JStrategy.java

示例3: start

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not get any answers because the communication is asynchronous and the
 * listen() method listens for answers.
 * 
 * @throws IOException
 */

public void start() throws IOException {
	TransportMapping transport = new DefaultUdpTransportMapping();

	if (SNMPversion == 3) {
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
		SecurityModels.getInstance().addSecurityModel(usm);
	}
	snmp = new Snmp(transport);

	if (SNMPversion == 3)
		snmp.getUSM().addUser(new OctetString(ver3Username),
				new UsmUser(new OctetString(ver3Username), AuthMD5.ID, new OctetString(ver3AuthPasscode), null, null));

	// Do not forget this line!
	transport.listen();
}
 
开发者ID:dana-i2cat,项目名称:opennaas-routing-nfv,代码行数:24,代码来源:SNMPManager.java

示例4: init

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
private void init() throws UnknownHostException, IOException {
	threadPool = ThreadPool.create("Trap", 4);
	dispatcher = new MultiThreadedMessageDispatcher(threadPool,
			new MessageDispatcherImpl());

	listenAddress = GenericAddress.parse("udp:0.0.0.0/"
			+ SnmpPref.getTrapsPort());
	DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(
			(UdpAddress) listenAddress);
	snmp = new Snmp(dispatcher, transport);
	snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
	snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
	snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
	USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
			MPv3.createLocalEngineID()), 0);
	SecurityModels.getInstance().addSecurityModel(usm);
	snmp.listen();
	logger.debug("Listening for traps on "
			+ transport.getListenAddress().toString());
}
 
开发者ID:ccascone,项目名称:JNetMan,代码行数:21,代码来源:SnmpTrapReceiver.java

示例5: initMessageDispatcher

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void initMessageDispatcher() {
    dispatcher = new MessageDispatcherImpl();
    
    usm = new USM(SecurityProtocols.getInstance(),
            agent.getContextEngineID(),
            updateEngineBoots());
    
    mpv3 = new MPv3(usm);
    
    SecurityProtocols.getInstance().addDefaultProtocols();
    dispatcher.addMessageProcessingModel(new MPv1());
    dispatcher.addMessageProcessingModel(new MPv2c());
    dispatcher.addMessageProcessingModel(mpv3);
    initSnmpSession();
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:18,代码来源:MockSnmpAgent.java

示例6: setUp

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    MockUtil.println("------------ Begin Test "+getName()+" --------------------------");
    final Properties p = new Properties();
    p.setProperty("log4j.logger.org.snmp4j", "DEBUG");
    p.setProperty("log4j.logger.org.snmp4j.agent", "DEBUG");
    MockLogAppender.setupLogging(true, p);

    // Create a global USM that all client calls will use
    MPv3.setEnterpriseID(5813);
    m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    m_agent = MockSnmpAgent.createAgentAndRun(new ClassPathResource("loadSnmpDataTest.properties"), "127.0.0.1/1691");	// Homage to Empire
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:17,代码来源:MockSnmpAgentTest.java

示例7: createSnmpSession

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
public Snmp createSnmpSession() throws IOException {
    TransportMapping transport = new DefaultUdpTransportMapping();
    Snmp session = new Snmp(transport);
    
    if (isSnmpV3()) {
        // Make a new USM
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        // Add the specified user to the USM
        usm.addUser(
            getSecurityName(),
            new UsmUser(
                getSecurityName(),
                getAuthProtocol(),
                getAuthPassPhrase(),
                getPrivProtocol(),
                getPrivPassPhrase()
            )
        );
        // Remove the old SNMPv3 MessageProcessingModel. If you don't do this, you'll end up with
        // two SNMPv3 MessageProcessingModel instances in the dispatcher and connections will fail.
        MessageProcessingModel oldModel = session.getMessageDispatcher().getMessageProcessingModel(MessageProcessingModel.MPv3);
        if (oldModel != null) {
            session.getMessageDispatcher().removeMessageProcessingModel(oldModel);
        }
        // Add a new SNMPv3 MessageProcessingModel with the newly-created USM
        session.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
    }
    
    return session;
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:31,代码来源:Snmp4JAgentConfig.java

示例8: start

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
public void start() throws IOException 
{
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	if("3".equals(this.version))//add v3 support
	{
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);  
		SecurityModels.getInstance().addSecurityModel(usm);  
	}
	// Do not forget this line!
	transport.listen();
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:19,代码来源:SNMPClient.java

示例9: initMessageDispatcher

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void initMessageDispatcher() {
    dispatcher = new MessageDispatcherImpl();

    usm = new USM(SecurityProtocols.getInstance(),
                  agent.getContextEngineID(),
                  updateEngineBoots());

    mpv3 = new MPv3(usm);

    SecurityProtocols.getInstance().addDefaultProtocols();
    dispatcher.addMessageProcessingModel(new MPv1());
    dispatcher.addMessageProcessingModel(new MPv2c());
    dispatcher.addMessageProcessingModel(mpv3);
    initSnmpSession();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:18,代码来源:MockSnmpAgent.java

示例10: setUp

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    MPv3.setEnterpriseID(5813);
    m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), "127.0.0.1/1691");	// Homage to Empire
    
    m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:12,代码来源:BrocadeMibTest.java

示例11: setUp

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    MPv3.setEnterpriseID(5813);
    m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("loadSnmpDataTest.properties"), "127.0.0.1/1691");	// Homage to Empire

    m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:12,代码来源:MockSnmpAgentTest.java

示例12: setUp

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    MPv3.setEnterpriseID(5813);
    m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("penrose-lldp-mib.properties"), "127.0.0.1/1691");	
    
    m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:12,代码来源:LLDPMibTest.java

示例13: sendTrapV3

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
public static void sendTrapV3(String port) {
    try {
        Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
                MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();

        snmp.getUSM().addUser(new OctetString("MD5DES"),
                new UsmUser(new OctetString("MD5DES"), null, null, null, null));

        // Create Target
        UserTarget target = new UserTarget();
        target.setAddress(targetAddress);
        target.setRetries(1);
        target.setTimeout(11500);
        target.setVersion(SnmpConstants.version3);
        target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
        target.setSecurityName(new OctetString("MD5DES"));

        // Create PDU for V3
        ScopedPDU pdu = new ScopedPDU();
        pdu.setType(ScopedPDU.NOTIFICATION);
        pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
        pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
        pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));

        // Send the PDU
        snmp.send(pdu, target);

        transport.close();
        snmp.close();
    } catch (Exception e) {
        System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
        System.err.println("Exception Message = " + e.getMessage());
    }
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:40,代码来源:SNMPUtils.java

示例14: doStart

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();

    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());

    // either tcp or udp
    if ("tcp".equals(endpoint.getProtocol())) {
        this.transport = new DefaultTcpTransportMapping();
    } else if ("udp".equals(endpoint.getProtocol())) {
        this.transport = new DefaultUdpTransportMapping();
    } else {
        throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
    }

    this.snmp = new Snmp(this.transport);

    if (SnmpConstants.version3 == endpoint.getSnmpVersion()) {
        UserTarget userTarget = new UserTarget();
        
        userTarget.setSecurityLevel(endpoint.getSecurityLevel());
        userTarget.setSecurityName(convertToOctetString(endpoint.getSecurityName()));
        userTarget.setAddress(targetAddress);
        userTarget.setRetries(endpoint.getRetries());
        userTarget.setTimeout(endpoint.getTimeout());
        userTarget.setVersion(endpoint.getSnmpVersion());
        
        this.target = userTarget;
        
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        
        OID authProtocol = convertAuthenticationProtocol(endpoint.getAuthenticationProtocol());
        
        OctetString authPwd = convertToOctetString(endpoint.getAuthenticationPassphrase());
        
        OID privProtocol = convertPrivacyProtocol(endpoint.getPrivacyProtocol());
        
        OctetString privPwd = convertToOctetString(endpoint.getPrivacyPassphrase());
        
        UsmUser user = new UsmUser(convertToOctetString(endpoint.getSecurityName()), authProtocol, authPwd, privProtocol, privPwd);
        
        usm.addUser(convertToOctetString(endpoint.getSecurityName()), user);
        
        ScopedPDU scopedPDU = new ScopedPDU();
        
        if (endpoint.getSnmpContextEngineId() != null) {
            scopedPDU.setContextEngineID(new OctetString(endpoint.getSnmpContextEngineId()));
        }
        
        if (endpoint.getSnmpContextName() != null) {
            scopedPDU.setContextName(new OctetString(endpoint.getSnmpContextName()));
        }
        
        this.pdu = scopedPDU;
    } else {
        CommunityTarget communityTarget = new CommunityTarget();
        
        communityTarget.setCommunity(convertToOctetString(endpoint.getSnmpCommunity()));
        communityTarget.setAddress(targetAddress);
        communityTarget.setRetries(endpoint.getRetries());
        communityTarget.setTimeout(endpoint.getTimeout());
        communityTarget.setVersion(endpoint.getSnmpVersion());
        
        this.target = communityTarget;
        
        this.pdu = new PDU();
    }

    // listen to the transport
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
    }
    this.transport.listen();
    if (LOG.isInfoEnabled()) {
        LOG.info("Started OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:79,代码来源:SnmpOIDPoller.java

示例15: setUpTarget

import org.snmp4j.security.SecurityProtocols; //导入依赖的package包/类
/**
 * Helper method that initializes the snmp target to listening mode. This
 * method is explicitly for V3 messages. This method will create and set up
 * the TransportMapping and target for SNMP V3. It creates a
 * TransportMapping and puts it in the listening mode. Also Creates
 * CommunityTarget object and sets SNMP target properties.
 *
 * @param targetIP
 *            IP address of Target machine
 * @param portNumber
 *            Port number
 * @param userName
 *            The security name of the user
 * @param authenticatePassword
 *            The authentication password
 * @param privacyPassword
 *            The privacy password
 * @return The created UserTarget
 * @throws IOException
 *             IOException
 */
private UserTarget setUpTarget( final String targetIP, final int portNumber, final String userName,
        final String authenticatePassword, final String privacyPassword ) throws IOException
{

    // Creates a TransportMapping and puts the transport mapping in to
    // listen mode
    final TransportMapping transportMapping = new DefaultUdpTransportMapping();
    snmp = new Snmp( transportMapping );
    transportMapping.listen();

    // Creating a USM with the support for the supplied security protocols
    final SecurityProtocols securityProtocols = SecurityProtocols.getInstance();
    securityProtocols.addDefaultProtocols();
    final OctetString engineId = new OctetString( MPv3.createLocalEngineID() );
    final USM usm = new USM( securityProtocols, engineId, DEFAULT_ENGINE_REBOOTS );
    SecurityModels.getInstance().addSecurityModel( usm );
    final OctetString username = new OctetString( userName );
    final OctetString authenticationPassphrase = new OctetString( authenticatePassword );
    final OctetString privacyPassphrase = new OctetString( privacyPassword );

    // Creating UsmUser and adds the UsmUser to the internal user name table
    // TODO Need to confirm, whether AuthMD5 and PrivDES needs to be changed
    final UsmUser usmuser = new UsmUser( username, AuthMD5.ID, authenticationPassphrase, PrivDES.ID,
            privacyPassphrase );
    snmp.getUSM().addUser( username, usmuser );

    // Create a target for a user based security model target and setting
    // its properties
    final UserTarget userTarget = new UserTarget();
    final InetAddress inetAddress = InetAddress.getByName( targetIP );
    final Address address = new UdpAddress( inetAddress, portNumber );
    userTarget.setAddress( address );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
    userTarget.setVersion( SnmpConstants.version3 );
    // TODO Need to confirm, whether this value needs to be configures
    userTarget.setSecurityLevel( SecurityLevel.AUTH_PRIV );
    userTarget.setSecurityName( username );

    return userTarget;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:65,代码来源:SnmpManagerImpl.java


注:本文中的org.snmp4j.security.SecurityProtocols类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。