/** * Copies the subject from a message to another message * * @param from the message with the subject * @param to the message to which the subject is added * @throws MessagingException if an attachment could not be added */ public static void copySecuritySubject(NormalizedMessage from, NormalizedMessage to) throws MessagingException { to.setSecuritySubject(from.getSecuritySubject()); }
private static void copySubject(NormalizedMessage from, NormalizedMessage to) { to.setSecuritySubject(from.getSecuritySubject()); }
public static void transfer(NormalizedMessage source, NormalizedMessage dest) throws MessagingException { dest.setContent(source.getContent()); for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } dest.setSecuritySubject(source.getSecuritySubject()); }
public static void transfer(NormalizedMessage source, NormalizedMessage dest) throws MessagingException { dest.setContent(source.getContent()); for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } dest.setSecuritySubject(source.getSecuritySubject()); }
private void propagateSubject(MessageExchange exchange) { NormalizedMessage msg; if (exchange instanceof InOnly) { msg = ((InOnly) exchange).getInMessage(); } else if (exchange instanceof InOut) { msg = ((InOut) exchange).getInMessage(); } else { throw new RuntimeException("Unable to determine message type to propagate subject: " + exchange.getClass().getName()); } if (msg.getSecuritySubject() == null && JBIContext.getMessageExchange() != null && JBIContext.getMessageExchange().getMessage("in") != null) { msg.setSecuritySubject(JBIContext.getMessageExchange().getMessage("in").getSecuritySubject()); } } }
public void checkSecurity(MessageExchangeImpl exchange) throws SecurityException, JBIException { if (exchange.getDestinationId() == null) { resolveAddress(exchange); } ServiceEndpoint se = exchange.getEndpoint(); if (se != null) { LOGGER.debug("service name: {}", se.getServiceName()); LOGGER.debug("operation name: {}", exchange.getOperation()); Set<Principal> acls = authorizationMap.getAcls(se, exchange.getOperation()); if (!acls.contains(GroupPrincipal.ANY)) { Subject subject = exchange.getMessage("in").getSecuritySubject(); if (subject == null) { throw new SecurityException("User not authenticated"); } LOGGER.debug("authorization for {}", subject); acls.retainAll(subject.getPrincipals()); if (acls.size() == 0) { throw new SecurityException("Endpoint is not authorized for this user"); } } } }
/** * Copies content, headers, security subject and attachments from the JBI NormalizedMessage to the Camel Message. * * @param from the source {@link NormalizedMessage} * @param to the target {@link Message} */ public void copyFromJbiToCamel(NormalizedMessage from, Message to) { to.setBody(from.getContent()); Subject securitySubject = from.getSecuritySubject(); if (securitySubject != null) { to.setHeader(SECURITY_SUBJECT, securitySubject); } Exchange exchange = to.getExchange(); for (Object object : from.getPropertyNames()) { String key = object.toString(); Object value = from.getProperty(key); if (!strategies.applyFilterToCamelHeaders(key, value, exchange)) { to.setHeader(key, value); } } for (Object id : from.getAttachmentNames()) { to.addAttachment(id.toString(), from.getAttachment(id.toString())); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { DOMSource domSource = (DOMSource)sourceTransformer.toDOMSource(message); if (domSource != null) { this.content = domSource; } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
/** * If enabled the properties and attachments are copied to the destination message */ protected void copyPropertiesAndAttachments(NormalizedMessage source, NormalizedMessage dest) throws Exception { if (isCopyProperties()) { for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } } if (isCopyAttachments()) { for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } } if (isCopySubject()) { dest.setSecuritySubject(source.getSecuritySubject()); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { String str = new SourceTransformer().contentToString(message); if (str != null) { this.content = new StringSource(str); } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
final Subject subject = exchange.getMessage("in").getSecuritySubject(); if (subject == null) { throw new SecurityException(
fake.setSecuritySubject(concrete.getSecuritySubject());
NormalizedMessage oldMsg = (oldMe != null) ? oldMe.getMessage("in") : null; if (oldMsg != null) { msg.setSecuritySubject(oldMsg.getSecuritySubject());