📄 vacmmib.java
字号:
* the security level
* @param match
* indicates whether exact context match ({@link #vacmExactMatch})
* or prefix context match ({@link #vacmPrefixMatch}) should
* be used by the new entry.
* @param readView
* the view name for read access (use a zero length OctetString to disable
* access).
* @param writeView
* the view name for write access (use a zero length OctetString to disable
* access).
* @param notifyView
* the view name for notify access (use a zero length OctetString to
* disable access).
* @param storageType
* the {@link StorageType} for this access entry.
*/
public void addAccess(OctetString groupName, OctetString contextPrefix,
int securityModel, int securityLevel,
int match,
OctetString readView, OctetString writeView,
OctetString notifyView, int storageType) {
OID index = createAccessIndex(groupName, contextPrefix, securityModel,
securityLevel);
Variable[] values = new Variable[vacmAccessTable.getColumnCount()];
values[idxVacmAccessContextMatch] = new Integer32(match);
values[idxVacmAccessReadViewName] = readView;
values[idxVacmAccessWriteViewName] = writeView;
values[idxVacmAccessNotifyViewName] = notifyView;
values[idxVacmAccessStorageType] = new Integer32(storageType);
values[idxVacmAccessRowStatus] = new Integer32(RowStatus.active);
vacmAccessTableModel.addRow(vacmAccessTableModel.createRow(index, values));
}
/**
* Removes an access entry from this VACM.
* @param groupName
* the group for which access rights are to be added.
* @param contextPrefix
* the context or context prefix.
* @param securityModel
* the security model
* @param securityLevel
* the security level
* @return
* <code>true</code> when the entry has been removed or <code>false</code>
* if no such entry could be found.
*/
public boolean removeAccess(OctetString groupName, OctetString contextPrefix,
int securityModel, int securityLevel) {
OID index = createAccessIndex(groupName, contextPrefix, securityModel,
securityLevel);
return (vacmAccessTableModel.removeRow(index) != null);
}
private static OID createAccessIndex(OctetString groupName,
OctetString contextPrefix,
int securityModel, int securityLevel) {
OID index = groupName.toSubIndex(false);
index.append(contextPrefix.toSubIndex(false));
index.append(securityModel);
index.append(securityLevel);
return index;
}
/**
* Adds a new view to this VACM. An already existing entry with the same
* view name and subtree OID will be replaced silently.
* @param viewName
* the view name.
* @param subtree
* the subtree OID.
* @param mask
* the bit mask which, in combination with <code>subtree</code>,
* defines a family of view subtrees.
* @param type
* indicates whether the view defined by <code>subtree</code> and
* <code>mask</code> is included ({@link #vacmViewIncluded}) or excluded
* (@link #vacmViewExcluded}) from the MIB view.
* @param storageType
* the {@link StorageType} for this access entry.
*/
public void addViewTreeFamily(OctetString viewName, OID subtree,
OctetString mask, int type, int storageType) {
OID index = createViewIndex(viewName, subtree);
Variable[] values = new Variable[vacmViewTreeFamilyTable.getColumnCount()];
values[idxVacmViewTreeFamilyMask] = mask;
values[idxVacmViewTreeFamilyType] = new Integer32(type);
values[idxVacmViewTreeFamilyStorageType] = new Integer32(storageType);
values[idxVacmViewTreeFamilyRowStatus] = new Integer32(RowStatus.active);
MOTableRow row = vacmViewTreeFamilyTableModel.createRow(index, values);
vacmViewTreeFamilyTableModel.addRow(row);
}
/**
* Removes a view tree family from this VACM.
* @param viewName
* the view name.
* @param subtree
* the subtree OID.
* @return
* <code>true</code> when the entry has been removed or <code>false</code>
* if no such entry could be found.
*/
public boolean removeViewTreeFamily(OctetString viewName, OID subtree) {
OID index = createViewIndex(viewName, subtree);
return (vacmViewTreeFamilyTableModel.removeRow(index) != null);
}
private static OID createViewIndex(OctetString viewName, OID subtree) {
OID index = viewName.toSubIndex(false);
index.append(subtree.toSubIndex(false));
return index;
}
/**
* Checks whether bit n of the supplied OctetString is set or not.
* @param n
* denotes the bit to check starting from zero.
* @param os OctetString
* @return boolean
*/
private static boolean isBitSet(final int n, final OctetString os) {
if (os.length() <= n/8) {
return true;
}
return (os.get(n/8) & (0x01 << (7 - (n % 8)))) > 0;
}
private List getAccessEntries(OctetString groupName) {
OctetString upperBound = new OctetString(groupName);
byte last = -1;
if (upperBound.length() > 0) {
last = upperBound.get(upperBound.length() - 1);
}
if (last == -1) {
upperBound.append((byte)0);
}
else {
upperBound.set(upperBound.length()-1, (byte)(last+1));
}
OID lowerOID = groupName.toSubIndex(false);
OID upperOID = upperBound.toSubIndex(false);
List views = vacmAccessTableModel.getRows(lowerOID, upperOID);
return views;
}
private List getViews(OctetString viewName) {
OctetString upperBound = new OctetString(viewName);
byte last = upperBound.get(upperBound.length()-1);
if (last == -1) {
upperBound.append((byte)0);
}
else {
upperBound.set(upperBound.length()-1, (byte)(last+1));
}
OID lowerOID = viewName.toSubIndex(false);
OID upperOID = upperBound.toSubIndex(false);
List views = vacmViewTreeFamilyTableModel.getRows(lowerOID, upperOID);
return views;
}
public static class VacmContextIterator implements Iterator {
private int index = 0;
private OctetString[] contexts;
VacmContextIterator(OctetString[] contexts, int offset) {
this.contexts = contexts;
this.index = offset;
}
public void remove() {
throw new UnsupportedOperationException();
}
public boolean hasNext() {
return (index < contexts.length);
}
public Object next() {
if (index < contexts.length) {
OctetString context = contexts[index++];
DefaultMOTableRow row =
new DefaultMOTableRow(context.toSubIndex(false),
new Variable[] { context });
return row;
}
throw new NoSuchElementException();
}
}
private static OctetString getContextFromIndex(OID index) {
if (index.size() > 0) {
return new OctetString(index.toByteArray(), 1, index.size() - 1);
}
return new OctetString();
}
class VacmContextTableModel implements MOTableModel {
public int getColumnCount() {
return 1;
}
public int getRowCount() {
return server.getContexts().length;
}
public boolean containsRow(OID index) {
return server.isContextSupported(getContextFromIndex(index));
}
public MOTableRow getRow(OID index) {
if (index == null) {
return null;
}
OctetString context = getContextFromIndex(index);
if (server.isContextSupported(context)) {
DefaultMOTableRow row =
new DefaultMOTableRow(index, new Variable[] { context });
return row;
}
return null;
}
public Iterator iterator() {
return tailIterator(new OID());
}
public Iterator tailIterator(OID lowerBound) {
OctetString[] contexts = server.getContexts();
if (contexts == null) {
return new VacmContextIterator(new OctetString[0], 0);
}
Arrays.sort(contexts, new LexicographicOctetStringComparator());
int offset = 0;
if (lowerBound != null) {
offset = Arrays.binarySearch(contexts, getContextFromIndex(lowerBound));
}
if (offset < 0) {
offset = -(offset+1);
}
return new VacmContextIterator(contexts, offset);
}
public OID lastIndex() {
OctetString[] contexts = server.getContexts();
if ((contexts == null) || (contexts.length == 0)) {
return null;
}
Arrays.sort(contexts, new LexicographicOctetStringComparator());
return contexts[contexts.length-1].toSubIndex(false);
}
public OID firstIndex() {
OctetString[] contexts = server.getContexts();
if ((contexts == null) || (contexts.length > 0)) {
return null;
}
Arrays.sort(contexts, new LexicographicOctetStringComparator());
return contexts[0].toSubIndex(false);
}
public MOTableRow firstRow() {
return getRow(firstIndex());
}
public MOTableRow lastRow() {
return getRow(lastIndex());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -