qpid::sys::ConnectionCodec* ProtocolImpl::create(const qpid::framing::ProtocolVersion& v, qpid::sys::OutputControl& out, const std::string& id, const qpid::sys::SecuritySettings& external) { if (v == qpid::framing::ProtocolVersion(1, 0)) { if (v.getProtocol() == qpid::framing::ProtocolVersion::SASL) { if (broker.getOptions().auth) { QPID_LOG(info, "Using AMQP 1.0 (with SASL layer)"); return new qpid::broker::amqp::Sasl(out, id, broker, *interconnects, qpid::SaslFactory::getInstance().createServer(broker.getOptions().realm,broker.getOptions().requireEncrypted, external), domain); } else { std::auto_ptr<SaslServer> authenticator(new qpid::NullSaslServer(broker.getOptions().realm)); QPID_LOG(info, "Using AMQP 1.0 (with dummy SASL layer)"); return new qpid::broker::amqp::Sasl(out, id, broker, *interconnects, authenticator, domain); } } else { if (broker.getOptions().auth) { throw qpid::Exception("SASL layer required!"); } else { QPID_LOG(info, "Using AMQP 1.0 (no SASL layer)"); return new qpid::broker::amqp::Connection(out, id, broker, *interconnects, false, domain); } } } return 0; }
char* SIPClient::inviteWithPassword(char const* url, char const* username, char const* password) { delete[] (char*)fUserName; fUserName = strDup(username); fUserNameSize = strlen(fUserName); Authenticator authenticator(username, password); char* inviteResult = invite(url, &authenticator); if (inviteResult != NULL) { // We are already authorized return inviteResult; } // The "realm" and "nonce" fields should have been filled in: if (authenticator.realm() == NULL || authenticator.nonce() == NULL) { // We haven't been given enough information to try again, so fail: return NULL; } // Try again (but with the same CallId): inviteResult = invite1(&authenticator); if (inviteResult != NULL) { // The authenticator worked, so use it in future requests: fValidAuthenticator = authenticator; } return inviteResult; }
// Bad password should return an authentication failure. TEST(SASL, failed1) { // Set up secrets. map<string, string> secrets; secrets["benh"] = "secret1"; sasl::secrets::load(secrets); // Launch a dummy process (somebody to send the AuthenticateMessage). UPID pid = spawn(new ProcessBase(), true); Credential credential; credential.set_principal("benh"); credential.set_secret("secret"); Authenticatee authenticatee(credential, UPID()); Future<Message> message = FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _); Future<bool> client = authenticatee.authenticate(pid); AWAIT_READY(message); Authenticator authenticator(message.get().from); Future<bool> server = authenticator.authenticate(); AWAIT_EQ(false, client); AWAIT_EQ(false, server); terminate(pid); }
void CloudConnection::reconnectionTimeout() { if (authenticator()->authenticated()) { m_connection->open(m_proxyServerUrl); } else { m_reconnectionTimer->stop(); } }
void CloudConnection::onAuthenticationChanged() { if (authenticator()->authenticated()) { qCDebug(dcCloud()) << "Connecting to" << m_proxyServerUrl.toString(); m_error = Cloud::CloudErrorNoError; m_connection->open(m_proxyServerUrl); } else { qCWarning(dcCloud()) << "Could not authenticate"; m_error = m_authenticator->error(); } }
int main() { SICInit(); // char arrays for input, command, and parameters char line[80], comm[20], p1[10], p2[10], extra[20]; // Display welcome message welcomeMessage(); do{ // These functions clear command and parameters clear(comm, 20); clear(p1, 10); clear(p2, 10); clear(extra,20); // Prompt user for command line printf("~command>: "); s_gets(line, 80); // Blank lines prompts for user input while ( line[0] == '\0' ) { printf("~command>: "); s_gets(line, 80); } // Split up the line into the command and parameters split(line, comm, p1, p2, extra); // Check for extra parameters if (extra[0] != '\0') printf("Error: Too many parameters.\n"); else // This function authenticates commands and parameters authenticator(comm, p1, p2); }while(!strcmp(comm,"exit") == 0 || p1[0] != '\0'); printf("Thank you! Bye~\n"); return 0; } // end of main
int handle_cmd(t_client *client) { size_t idx; int ret; idx = 0; ret = -1; while (idx < sizeof(g_cmd) / sizeof(*g_cmd)) { if (!strcasecmp(g_cmd[idx].cmd_in, client->cmd)) { if (authenticator(client)) return (-1); else return (g_cmd[idx].func(client)); } ++idx; } if (ret == -1) write(client->sock, BAD_CMD, strlen(BAD_CMD)); return (0); }