Exemple #1
0
 private Target createTarget(OctetString userInfo) {
   if ((userInfo == null) || (userInfo.length() == 0)) {
     return defaultTarget;
   }
   if (version == SnmpConstants.version3) {
     if ((securityModel == SecurityModel.SECURITY_MODEL_USM) && (usm != null)) {
       UsmUserEntry user = usm.getUser(null, userInfo);
       UserTarget target = new UserTarget();
       if (user != null) {
         if (user.getAuthenticationKey() != null) {
           if (user.getPrivacyKey() != null) {
             target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
           } else {
             target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
           }
         } else {
           target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
         }
       }
       target.setVersion(version);
       target.setSecurityName(userInfo);
       target.setSecurityModel(securityModel);
       target.setTimeout(timeout);
       target.setRetries(retries);
       return target;
     } else if (securityModel == SecurityModel.SECURITY_MODEL_TSM) {
       CertifiedTarget target = new CertifiedTarget(userInfo);
       target.setVersion(version);
       target.setSecurityModel(securityModel);
       target.setTimeout(timeout);
       target.setRetries(retries);
       return target;
     }
   } else {
     CommunityTarget target = new CommunityTarget();
     target.setCommunity(userInfo);
     target.setVersion(version);
     target.setSecurityModel(securityModel);
     target.setTimeout(timeout);
     target.setRetries(retries);
     return target;
   }
   return null;
 }