/** @see MULE-4720 */
public void testSecurityContext() throws Exception
{
DefaultMuleMessage message = new DefaultMuleMessage("Test Message", muleContext);
SessionHandler handler = new SerializeAndEncodeSessionHandler();
MuleSession session = new DefaultMuleSession(muleContext);
Credentials credentials = new MuleCredentials("joe", "secret".toCharArray());
SecurityContext sc = new DefaultSecurityContextFactory().create(new DefaultMuleAuthentication(credentials));
session.setSecurityContext(sc);
handler.storeSessionInfoToMessage(session, message);
// store save session to outbound, move it to the inbound
// for retrieve to deserialize
Object s = message.removeProperty(MuleProperties.MULE_SESSION_PROPERTY);
message.setInboundProperty(MuleProperties.MULE_SESSION_PROPERTY, s);
session = handler.retrieveSessionInfoFromMessage(message);
sc = session.getSecurityContext();
assertEquals("joe", sc.getAuthentication().getPrincipal());
}