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


Java USM.addUser方法代码示例

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


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

示例1: addUsmUser

import org.snmp4j.security.USM; //导入方法依赖的package包/类
/**
 * Adds all the necessary initial users to the USM.
 *
 * @param usm the USM instance used by this agent.
 */
@Override
protected void addUsmUser(USM usm) {
  if (securityName == null || securityName.equals("")) {
    logger.info("No security name.");
    return;
  }

  UsmUser user = new UsmUser(
    new OctetString(securityName),
    AUTHENTICATION_PROTOCOL,
    new OctetString(AUTHENTICATION_PASSWORD),
    PRIVACY_PROTOCOL,
    new OctetString(PRIVACY_PASSWORD)
  );
  usm.addUser(user.getSecurityName(), null, user);
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:22,代码来源:FileMibAgent.java

示例2: createSnmpSession

import org.snmp4j.security.USM; //导入方法依赖的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

示例3: doStart

import org.snmp4j.security.USM; //导入方法依赖的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


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