@Test public void securityContextSerialization() throws Exception { Transformer transformer = createSerializableToByteArrayTransformer(); transformer.setMuleContext(muleContext); CoreEvent event = CoreEvent.builder(testEvent()).securityContext(createTestAuthentication()).build(); Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(event); assertNotNull(serialized); ByteArrayToObject trans = new ByteArrayToObject(); trans.setMuleContext(muleContext); CoreEvent deserialized = (CoreEvent) trans.transform(serialized); assertThat(deserialized.getSecurityContext().getAuthentication().getPrincipal(), is(event.getSecurityContext().getAuthentication().getPrincipal())); assertThat(deserialized.getSecurityContext().getAuthentication().getProperties().get("key1"), is(event.getSecurityContext().getAuthentication().getProperties().get("key1"))); assertThat(deserialized.getSecurityContext().getAuthentication().getCredentials(), is(event.getSecurityContext().getAuthentication().getCredentials())); }
@Test public void securityContextCopy() throws Exception { SecurityContext securityContext = mock(SecurityContext.class); CoreEvent event = CoreEvent.builder(testEvent()).securityContext(securityContext).build(); CoreEvent eventCopy = CoreEvent.builder(event).message(Message.of("copy")).build(); assertThat(securityContext, sameInstance(eventCopy.getSecurityContext())); }
@Override public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) { return from(publisher).map(event -> { try { return CoreEvent.builder(event).securityContext(filter.doFilter(event)).build(); } catch (Exception e) { throw propagate(e); } }); }
/** * If the {@code value} is a {@link Message}, then a new one is created merging the contents of the returned value with the ones * of the input message. The merging criteria is as follows: * <li> * <ul> * The {@code value}'s payload and DataType is set on the output message * </ul> * <ul> * If the {@code value} has a not {@code null} output for {@link Message#getAttributes()}, then that value is set on the * outbound message. Otherwise, whatever value the input message had is maintained * </ul> * </li> * <p> * If the {@code value} is of any other type, then it's set as the payload of the outgoing message {@inheritDoc} */ @Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { return value instanceof EventedResult ? ((EventedResult) value).getEvent() : CoreEvent.builder(operationContext.getEvent()) .securityContext(operationContext.getSecurityContext()) .message(toMessage(value, operationContext)).build(); } }
@Test public void securityContextSerialization() throws Exception { Transformer transformer = createSerializableToByteArrayTransformer(); transformer.setMuleContext(muleContext); CoreEvent event = CoreEvent.builder(testEvent()).securityContext(createTestAuthentication()).build(); Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(event); assertNotNull(serialized); ByteArrayToObject trans = new ByteArrayToObject(); trans.setMuleContext(muleContext); CoreEvent deserialized = (CoreEvent) trans.transform(serialized); assertThat(deserialized.getSecurityContext().getAuthentication().getPrincipal(), is(event.getSecurityContext().getAuthentication().getPrincipal())); assertThat(deserialized.getSecurityContext().getAuthentication().getProperties().get("key1"), is(event.getSecurityContext().getAuthentication().getProperties().get("key1"))); assertThat(deserialized.getSecurityContext().getAuthentication().getCredentials(), is(event.getSecurityContext().getAuthentication().getCredentials())); }
@Test public void securityContextCopy() throws Exception { SecurityContext securityContext = mock(SecurityContext.class); CoreEvent event = CoreEvent.builder(testEvent()).securityContext(securityContext).build(); CoreEvent eventCopy = CoreEvent.builder(event).message(Message.of("copy")).build(); assertThat(securityContext, sameInstance(eventCopy.getSecurityContext())); }
@Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { TypedValue result = operationContext.getMuleContext().getExpressionManager() .evaluate(targetValue, getTargetBindingContext(toMessage(value, operationContext))); return CoreEvent.builder(operationContext.getEvent()) .securityContext(operationContext.getSecurityContext()) .addVariable(this.target, result.getValue(), result.getDataType()) .build(); } }
/** * {@inheritDoc} * * @return {@link ExecutionContextAdapter#getEvent()} */ @Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { return CoreEvent.builder(operationContext.getEvent()).securityContext(operationContext.getSecurityContext()).build(); } }
/** * If the {@code value} is a {@link Message}, then a new one is created merging the contents of the returned value with the ones * of the input message. The merging criteria is as follows: * <li> * <ul> * The {@code value}'s payload and DataType is set on the output message * </ul> * <ul> * If the {@code value} has a not {@code null} output for {@link Message#getAttributes()}, then that value is set on the * outbound message. Otherwise, whatever value the input message had is maintained * </ul> * </li> * <p> * If the {@code value} is of any other type, then it's set as the payload of the outgoing message {@inheritDoc} */ @Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { return value instanceof EventedResult ? ((EventedResult) value).getEvent() : CoreEvent.builder(operationContext.getEvent()) .securityContext(operationContext.getSecurityContext()) .message(toMessage(value, operationContext)).build(); } }
@Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { TypedValue result = expressionManager .evaluate(targetValue, getTargetBindingContext(toMessage(value, operationContext))); return CoreEvent.builder(operationContext.getEvent()) .securityContext(operationContext.getSecurityContext()) .addVariable(this.target, result.getValue(), result.getDataType()) .build(); } }
/** * {@inheritDoc} * * @return {@link ExecutionContextAdapter#getEvent()} */ @Override public CoreEvent asReturnValue(Object value, ExecutionContextAdapter operationContext) { return CoreEvent.builder(operationContext.getEvent()).securityContext(operationContext.getSecurityContext()).build(); } }