private void addToObjectPartList(ObjectPartList serializedObjs, Object res, CollectionType collectionType, boolean lastChunk, ServerConnection servConn, boolean isStructs, final SecurityService securityService) throws IOException { if (isStructs && (res instanceof Struct)) { Object[] values = ((Struct) res).getFieldValues(); // create another ObjectPartList for the struct ObjectPartList serializedValueObjs = new ObjectPartList(values.length, false); for (Object value : values) { addObjectToPartList(serializedValueObjs, null, value, securityService); } serializedObjs.addPart(null, serializedValueObjs, ObjectPartList.OBJECT, null); } else if (res instanceof Object[]) {// for CQ key-value pairs Object[] values = ((Object[]) res); // create another ObjectPartList for the Object[] ObjectPartList serializedValueObjs = new ObjectPartList(values.length, false); for (int i = 0; i < values.length; i += 2) { Object key = values[i]; Object value = values[i + 1]; addObjectToPartList(serializedValueObjs, key, value, securityService); } serializedObjs.addPart(null, serializedValueObjs, ObjectPartList.OBJECT, null); } else { // for deserialized objects addObjectToPartList(serializedObjs, null, res, securityService); } }
@Override public void addAll(ObjectPartList other) { if (logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE)) { logger.trace(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE, "VOL.addAll(other={}; this={}", other, this); } int myTypeArrayLength = this.hasKeys ? this.keys.size() : this.objects.size(); int otherTypeArrayLength = other.hasKeys ? other.keys.size() : other.objects.size(); super.addAll(other); VersionedObjectList vother = (VersionedObjectList) other; this.regionIsVersioned |= vother.regionIsVersioned; this.versionTags.addAll(vother.versionTags); if (myTypeArrayLength > 0 || otherTypeArrayLength > 0) { int newSize = myTypeArrayLength + otherTypeArrayLength; if (this.objectTypeArray != null) { newSize = Math.max(newSize, this.objectTypeArray.length); if (this.objectTypeArray.length < newSize) { // need more room byte[] temp = this.objectTypeArray; this.objectTypeArray = new byte[newSize]; System.arraycopy(temp, 0, this.objectTypeArray, 0, temp.length); } } else { this.objectTypeArray = new byte[newSize]; } if (other.objectTypeArray != null) { System.arraycopy(other.objectTypeArray, 0, this.objectTypeArray, myTypeArrayLength, otherTypeArrayLength); } } }
@Override public void clear() { super.clear(); this.versionTags.clear(); }
ObjectPartList values = new ObjectPartList(MAXIMUM_CHUNK_SIZE, keys == null); AuthorizeRequest authzRequest = servConn.getAuthzRequest(); AuthorizeRequestPP postAuthzRequest = servConn.getPostAuthzRequest(); for (int i = 0; i < numKeys; i++) { if (values.size() == MAXIMUM_CHUNK_SIZE) { values.clear(); new Object[] {servConn.getName(), key}), ex); values.addExceptionPart(key, ex); continue; new Object[] {servConn.getName(), key}), ex); values.addExceptionPart(key, ex); continue; new Object[] {servConn.getName(), key}), ex); values.addExceptionPart(key, ex); continue; values.addObjectPart(key, value, isObject, null);
@Test public void oldSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); this.getAll.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPart(argument.capture(), eq(false)); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object key : argument.getValue().getKeys()) { assertThat(key).isIn(KEYS); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
private void checkObjectValues(ObjectPartList newList) { assertEquals(5, newList.size()); assertNull(newList.getKeysForTest()); List values = newList.getObjects(); assertEquals("value1", new String((byte[]) values.get(0))); assertEquals("value2", values.get(1)); assertEquals("value3", values.get(2)); assertEquals(new AssertionError("hello"), values.get(3)); assertNull(values.get(4)); }
@Test public void oldSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); for (Object key : KEYS) { doThrow(new NotAuthorizedException("")).when(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } this.getAll.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPart(argument.capture(), eq(false)); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object o : argument.getValue().getObjects()) { assertThat(o).isExactlyInstanceOf(NotAuthorizedException.class); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
@Test public void testValueAsObjectByteArray() throws Exception { ObjectPartList list = new VersionedObjectList(100, false, false, true); byte[] normalBytes = "value1".getBytes(); list.addObjectPart("key", normalBytes, false, null); list.addObjectPart("key", "value2", true, null); byte[] serializedObjectBytes = BlobHelper.serializeToBlob("value3"); list.addObjectPart("key", serializedObjectBytes, true, null); list.addExceptionPart("key", new AssertionError("hello")); list.addObjectPartForAbsentKey("key", null); // Create a clone of the this list. ObjectPartList newList = CopyHelper.copy(list); checkSerializedValues(newList); // Create another copy, just to double check // all the info was perserved newList = CopyHelper.copy(newList); checkSerializedValues(newList); }
public void addExceptionPart(Object key, Exception ex) { addPart(key, ex, EXCEPTION, null); }
logger.trace("{}: Creating chunk: {}", servConn.getName(), j); ObjectPartList serializedObjs = new ObjectPartList(MAXIMUM_CHUNK_SIZE, false); for (int i = 0; i < MAXIMUM_CHUNK_SIZE; i++) { if ((resultIndex) == objs.size()) {
@Test public void integratedSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(true); this.getAll70.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPartNoCopying(argument.capture()); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object key : argument.getValue().getKeys()) { assertThat(key).isIn(KEYS); } for (Object key : KEYS) { verify(this.securityService).authorize(Resource.DATA, Operation.READ, REGION_NAME, key.toString()); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
private void checkSerializedValues(ObjectPartList newList) throws IOException, ClassNotFoundException { assertEquals(5, newList.size()); assertNull(newList.getKeysForTest()); List values = newList.getObjects(); assertEquals("value1", new String((byte[]) values.get(0))); assertEquals("value2", BlobHelper.deserializeBlob((byte[]) values.get(1))); assertEquals("value3", BlobHelper.deserializeBlob((byte[]) values.get(2))); assertEquals(new AssertionError("hello"), values.get(3)); assertNull(values.get(4)); }
@Test public void oldSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); for (Object key : KEYS) { doThrow(new NotAuthorizedException("")).when(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } this.getAll651.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPart(argument.capture(), eq(false)); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object o : argument.getValue().getObjects()) { assertThat(o).isExactlyInstanceOf(NotAuthorizedException.class); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
public void addObjectPart(Object key, Object value, boolean isObject, VersionTag versionTag) { addPart(key, value, isObject ? OBJECT : BYTES, versionTag); }
@Test public void oldSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); this.getAll651.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPart(argument.capture(), eq(false)); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object key : argument.getValue().getKeys()) { assertThat(key).isIn(KEYS); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
@Test public void oldSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); for (Object key : KEYS) { doThrow(new NotAuthorizedException("")).when(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } this.getAll70.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPartNoCopying(argument.capture()); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object o : argument.getValue().getObjects()) { assertThat(o).isExactlyInstanceOf(NotAuthorizedException.class); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
private void addObjectToPartList(ObjectPartList objPartList, Object key, Object value, final SecurityService securityService) { Object object = value; boolean isObject = true; if (value instanceof CachedDeserializable) { object = ((CachedDeserializable) value).getSerializedValue(); } else if (value instanceof byte[]) { isObject = false; } object = securityService.postProcess(null, key, object, isObject); if (key != null) { objPartList.addPart(null, key, ObjectPartList.OBJECT, null); } objPartList.addPart(null, object, isObject ? ObjectPartList.OBJECT : ObjectPartList.BYTES, null); }
@Test public void oldSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); this.getAll70.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPartNoCopying(argument.capture()); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object key : argument.getValue().getKeys()) { assertThat(key).isIn(KEYS); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
@Test public void oldSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); for (Object key : KEYS) { doThrow(new NotAuthorizedException("")).when(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } this.getAll70.cmdExecute(this.message, this.serverConnection, this.securityService, 0); ArgumentCaptor<ObjectPartList> argument = ArgumentCaptor.forClass(ObjectPartList.class); verify(this.chunkedResponseMessage).addObjPartNoCopying(argument.capture()); assertThat(argument.getValue().getObjects()).hasSize(KEYS.length); for (Object o : argument.getValue().getObjects()) { assertThat(o).isExactlyInstanceOf(NotAuthorizedException.class); } for (Object key : KEYS) { verify(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(key.toString()), eq(null)); } verify(this.chunkedResponseMessage).sendChunk(eq(this.serverConnection)); }
@Override public void addPart(Object key, Object value, byte objectType, VersionTag versionTag) { if (logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE)) { logger.trace(LogMarker.VERSIONED_OBJECT_LIST_VERBOSE, "addPart({}; {}; {}; {}", key, value, objectType, versionTag); } super.addPart(key, value, objectType, versionTag); if (this.regionIsVersioned) { int tagsSize = this.versionTags.size(); if (keys != null && (tagsSize != this.keys.size() - 1)) { // this should not happen - either all or none of the entries should have tags throw new InternalGemFireException(); } if (this.objects != null && (this.objects.size() > 0) && (tagsSize != this.objects.size() - 1)) { // this should not happen - either all or none of the entries should have tags throw new InternalGemFireException(); } // Assert.assertTrue(versionTag != null); this.versionTags.add(versionTag); } }