UnregisterInterest extends BaseCommand { @Override public void cmdExecute(Message clientMessage, ServerConnection serverConnection, SecurityService securityService, long start) throws ClassNotFoundException, IOException { Part regionNamePart, keyPart; String regionName; Object key; int interestType; String errMessage = null; serverConnection.setAsTrue(REQUIRES_RESPONSE); regionNamePart = clientMessage.getPart(0); interestType = clientMessage.getPart(1).getInt(); keyPart = clientMessage.getPart(2); Part isClosingPart = clientMessage.getPart(3); byte[] isClosingPartBytes = (byte[]) isClosingPart.getObject(); boolean isClosing = isClosingPartBytes[0] == 0x01; regionName = regionNamePart.getCachedString(); try { key = keyPart.getStringOrObject(); } catch (Exception e) { writeException(clientMessage, e, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } boolean keepAlive; try { Part keepAlivePart = clientMessage.getPart(4); byte[] keepAliveBytes = (byte[]) keepAlivePart.getObject(); keepAlive = keepAliveBytes[0] != 0x00; } catch (Exception e) { writeException(clientMessage, e, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } if (logger.isDebugEnabled()) { logger.debug( "{}: Received unregister interest request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key); } if ((key == null) && (regionName == null)) { errMessage = "The input region name and key for the unregister interest request are null."; } else if (key == null) { errMessage = "The input key for the unregister interest request is null."; } else if (regionName == null) { errMessage = "The input region name for the unregister interest request is null."; } if (errMessage != null) { logger.warn("{}: {}", serverConnection.getName(), errMessage); writeErrorResponse(clientMessage, MessageType.UNREGISTER_INTEREST_DATA_ERROR, errMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } try { if (interestType == InterestType.REGULAR_EXPRESSION) { securityService.authorize(Resource.DATA, Operation.READ, regionName); } else { securityService.authorize(Resource.DATA, Operation.READ, regionName, key); } } catch (NotAuthorizedException ex) { writeException(clientMessage, ex, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } AuthorizeRequest authorizeRequest = serverConnection.getAuthzRequest(); if (authorizeRequest != null) { if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) { try { UnregisterInterestOperationContext unregisterContext = authorizeRequest.unregisterInterestAuthorize(regionName, key, interestType); key = unregisterContext.getKey(); } catch (NotAuthorizedException ex) { writeException(clientMessage, ex, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } } } serverConnection.getAcceptor().getCacheClientNotifier().unregisterClientInterest(regionName, key, interestType, isClosing, serverConnection.getProxyID(), keepAlive); writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); if (logger.isDebugEnabled()) { logger.debug("{}: Sent unregister interest response for region {} key {}", serverConnection.getName(), regionName, key); } } UnregisterInterest(); static Command getCommand(); @Override void cmdExecute(Message clientMessage, ServerConnection serverConnection,
      SecurityService securityService, long start);  }
@Test public void noSecurityShouldSucceed() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(false); this.unregisterInterest.cmdExecute(this.message, this.serverConnection, this.securityService, 0); verify(this.replyMessage).send(this.serverConnection); }
@Test public void integratedSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(true); this.unregisterInterest.cmdExecute(this.message, this.serverConnection, this.securityService, 0); verify(this.securityService).authorize(Resource.DATA, Operation.READ, REGION_NAME, KEY); verify(this.replyMessage).send(this.serverConnection); }
@Test public void integratedSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(true); doThrow(new NotAuthorizedException("")).when(this.securityService).authorize(Resource.DATA, Operation.READ, REGION_NAME, KEY); this.unregisterInterest.cmdExecute(this.message, this.serverConnection, this.securityService, 0); verify(this.securityService).authorize(Resource.DATA, Operation.READ, REGION_NAME, KEY); verify(this.errorResponseMessage).send(eq(this.serverConnection)); }
@Test public void oldSecurityShouldSucceedIfAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); this.unregisterInterest.cmdExecute(this.message, this.serverConnection, this.securityService, 0); verify(this.authzRequest).unregisterInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt()); verify(this.replyMessage).send(this.serverConnection); }
@Test public void oldSecurityShouldFailIfNotAuthorized() throws Exception { when(this.securityService.isClientSecurityRequired()).thenReturn(true); when(this.securityService.isIntegratedSecurity()).thenReturn(false); doThrow(new NotAuthorizedException("")).when(this.authzRequest).getAuthorize(eq(REGION_NAME), eq(KEY), any()); this.unregisterInterest.cmdExecute(this.message, this.serverConnection, this.securityService, 0); verify(this.authzRequest).unregisterInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt()); verify(this.replyMessage).send(eq(this.serverConnection)); }