📄 usmmib.java
字号:
entry.getAuthenticationKey() :
entry.getPrivacyKey();
}
public class UsmTableModel extends DefaultMOMutableTableModel {
private MOTableIndex indexDef;
public UsmTableModel(MOTableIndex indexDef) {
super();
this.indexDef = indexDef;
}
public MOTableRow createRow(OID index, Variable[] values) {
return new UsmTableRow(this, index, values);
}
public MOTableIndex getIndexDef() {
return indexDef;
}
}
private static boolean isKeyChanged(MOTableRow changeSet, int keyChangeColumn) {
OctetString value = (OctetString) changeSet.getValue(keyChangeColumn);
if ((value != null) && (value.length() > 0)) {
return true;
}
return false;
}
private static boolean isKeyChanged(MOTableRow changeSet) {
return ((isKeyChanged(changeSet, colUsmUserOwnAuthKeyChange)) ||
(isKeyChanged(changeSet, colUsmUserAuthKeyChange)) ||
(isKeyChanged(changeSet, colUsmUserOwnPrivKeyChange)) ||
(isKeyChanged(changeSet, colUsmUserPrivKeyChange)));
}
public class UsmTableRow extends DefaultMOMutableRow2PC {
private UsmTableModel tableModel;
private boolean cloned = false;
public UsmTableRow(UsmTableModel model, OID index, Variable[] values) {
super(index, values);
this.tableModel = model;
}
public void setCloned(boolean cloned) {
this.cloned = cloned;
}
public boolean isCloned() {
return cloned;
}
public MOTableIndex getIndexDef() {
return tableModel.getIndexDef();
}
public AuthenticationProtocol getAuthProtocol(MOTableRow changeSet)
{
OID authOID = getAuthProtocolOID(changeSet);
AuthenticationProtocol a =
securityProtocols.getAuthenticationProtocol(authOID);
return a;
}
public PrivacyProtocol getPrivProtocol(MOTableRow changeSet)
{
OID privOID = getPrivProtocolOID(changeSet);
PrivacyProtocol p =
securityProtocols.getPrivacyProtocol(privOID);
return p;
}
public OID getPrivProtocolOID(MOTableRow preparedChanges)
{
OID privID = null;
if (preparedChanges.getValue(colUsmUserCloneFrom) == null) {
privID = (OID) preparedChanges.getValue(colUsmUserPrivProtocol);
}
if (privID == null) {
privID = (OID) getValue(colUsmUserPrivProtocol);
}
return privID;
}
public void prepare(SubRequest subRequest,
MOTableRow preparedChanges, int column) {
switch (column) {
case colUsmUserAuthProtocol: {
OID authProtocol = (OID) subRequest.getVariableBinding().getVariable();
if (!authProtocol.equals(noAuthProtocol)) {
subRequest.getStatus().setErrorStatus(PDU.inconsistentValue);
}
else {
OID privProtocol = null;
Variable privProtocolVariable =
preparedChanges.getValue(colUsmUserPrivProtocol);
if (privProtocolVariable instanceof OID) {
privProtocol = (OID) privProtocolVariable;
}
else if (privProtocolVariable == null) {
privProtocol = (OID) getValue(colUsmUserPrivProtocol);
}
if ((privProtocol == null) ||
(!privProtocol.equals(noPrivProtocol))) {
subRequest.getStatus().setErrorStatus(PDU.inconsistentValue);
}
}
break;
}
case colUsmUserPrivProtocol: {
OID privProtocol = (OID)subRequest.getVariableBinding().getVariable();
if (!privProtocol.equals(noPrivProtocol)) {
subRequest.getStatus().setErrorStatus(PDU.inconsistentValue);
}
break;
}
}
}
private OID getCloneFromIndex(MOTableRow changeSet) {
OID cloneFrom = (OID) changeSet.getValue(colUsmUserCloneFrom);
if (cloneFrom == null) {
cloneFrom = (OID) getValue(colUsmUserCloneFrom);
}
if ((cloneFrom == null) || (cloneFrom.size() <= usmUserEntryOID.size())) {
return null;
}
return new OID(cloneFrom.getValue(), usmUserEntryOID.size()+1,
cloneFrom.size() - (usmUserEntryOID.size()+1));
}
public synchronized void commitRow(SubRequest subRequest,
MOTableRow changeSet) {
if (subRequest.hasError()) {
return;
}
Variable[] indexValues = getIndexDef().getIndexValues(getIndex());
OctetString engineID = (OctetString) indexValues[0];
OctetString userName = (OctetString) indexValues[1];
UsmUserEntry oldUserEntry;
OID cloneFromUserIndex = getCloneFromIndex(changeSet);
if (cloneFromUserIndex != null) {
Variable[] cloneFromIndexValues =
getIndexDef().getIndexValues(cloneFromUserIndex);
OctetString cloneFromEngineID = (OctetString) cloneFromIndexValues[0];
OctetString cloneFromUserName = (OctetString) cloneFromIndexValues[1];
oldUserEntry = usm.getUser(cloneFromEngineID, cloneFromUserName);
// assign protocols
if (oldUserEntry != null) {
setValue(colUsmUserAuthProtocol,
oldUserEntry.getUsmUser().getAuthenticationProtocol());
setValue(colUsmUserPrivProtocol,
oldUserEntry.getUsmUser().getPrivacyProtocol());
}
}
else {
oldUserEntry = usm.getUser(engineID, userName);
}
Integer32 newStatus =
(Integer32)changeSet.getValue(colUsmUserStatus);
if (((newStatus != null) &&
((newStatus.getValue() == RowStatus.active) ||
(newStatus.getValue() == RowStatus.createAndGo))) ||
((getValue(colUsmUserStatus) != null) &&
(((Integer32)getValue(colUsmUserStatus)).getValue() == RowStatus.active) &&
(isKeyChanged(changeSet)))) {
if (cloneFromUserIndex != null) {
// save undo value
setUserObject(oldUserEntry);
}
if (oldUserEntry == null) {
subRequest.getStatus().setErrorStatus(PDU.commitFailed);
return;
}
OctetString[] newKeys = new OctetString[2];
OctetString[] oldKeys = new OctetString[2];
AuthenticationProtocol a = getAuthProtocol(changeSet);
if (a != null) {
for (int p=0; p<2; p++) {
oldKeys[p] = new OctetString(getKey(oldUserEntry, p));
for (int i = 0; i < keyChangeColumns[p].length; i++) {
OctetString keyChange =
(OctetString)getValue(keyChangeColumns[p][i]);
if ((keyChange != null) && (keyChange.length() > 0)) {
int keyLength = a.getDigestLength();
if (p == 1) {
// privacy protocol key change
PrivacyProtocol privProtocol = getPrivProtocol(changeSet);
keyLength =
Math.min(keyLength, privProtocol.getMaxKeyLength());
}
newKeys[p] =
KeyChange.changeKey(a, oldKeys[p],
keyChange, keyLength);
break; // only one key change per protocol
}
}
}
}
UsmUserEntry newEntry =
new UsmUserEntry(engineID.getValue(), userName,
getAuthProtocolOID(changeSet),
(newKeys[0] == null) ?
((oldKeys[0] == null) ? null : oldKeys[0].getValue())
: newKeys[0].getValue(),
getPrivProtocolOID(changeSet),
(newKeys[1] == null) ?
((oldKeys[1] == null) ? null : oldKeys[1].getValue())
: newKeys[1].getValue());
usm.updateUser(newEntry);
setValue(colUsmUserCloneFrom, null);
setValue(colUsmUserAuthKeyChange, null);
setValue(colUsmUserOwnAuthKeyChange, null);
setValue(colUsmUserPrivKeyChange, null);
setValue(colUsmUserOwnPrivKeyChange, null);
}
if (newStatus != null) {
switch (newStatus.getValue()) {
case RowStatus.createAndWait:
case RowStatus.createAndGo: {
setValue(colUsmUserSecurityName, userName);
break;
}
}
}
}
public OID getAuthProtocolOID(MOTableRow changeSet) {
OID authID = null;
if (changeSet.getValue(colUsmUserCloneFrom) == null) {
authID = (OID) changeSet.getValue(colUsmUserAuthProtocol);
}
if (authID == null) {
authID = (OID) getValue(colUsmUserAuthProtocol);
}
return authID;
}
public void cleanupRow(SubRequest subRequest, ChangeSet changeSet) {
setUserObject(null);
}
public void undoRow(SubRequest subRequest, ChangeSet changeSet) {
if (getUserObject() != null) {
usm.updateUser((UsmUserEntry)getUserObject());
}
}
}
class UsmRowPointer extends RowPointer {
public UsmRowPointer(int columnID, MOAccess access, OID defaultValue,
boolean mutableInService) {
super(columnID, access, defaultValue, mutableInService);
}
public void prepare(SubRequest subRequest, MOTableRow row,
MOTableRow changeSet, int column) {
super.prepare(subRequest, row, changeSet, column);
if (!subRequest.hasError()) {
OID rowPointer = (OID) subRequest.getVariableBinding().getVariable();
MOTableCellInfo cell = getTargetTable().getCellInfo(rowPointer);
if (cell.getIndex().equals(row.getIndex())) {
// cannot clone from self
subRequest.getStatus().setErrorStatus(PDU.inconsistentValue);
}
}
}
public Variable getValue(MOTableRow row, int column) {
return SnmpConstants.zeroDotZero;
}
}
public void rowStatusChanged(RowStatusEvent event) {
if (event.isDeniable()) {
/**@todo what to implement here?*/
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -