| 1 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 2 |
# or more contributor license agreements. See the NOTICE file |
| 3 |
# distributed with this work for additional information |
| 4 |
# regarding copyright ownership. The ASF licenses this file |
| 5 |
# to you under the Apache License, Version 2.0 (the |
| 6 |
# "License"); you may not use this file except in compliance |
| 7 |
# with the License. You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, |
| 12 |
# software distributed under the License is distributed on an |
| 13 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 |
# KIND, either express or implied. See the License for the |
| 15 |
# specific language governing permissions and limitations |
| 16 |
# under the License. |
| 17 |
|
| 18 |
|
| 19 |
module Qpid::Proton |
| 20 |
|
| 21 |
# The SASL layer is responsible for establishing an authenticated and/or |
| 22 |
# encrypted tunnel over which AMQP frames are passed between peers. |
| 23 |
# |
| 24 |
# The peer acting as the SASL client must provide authentication |
| 25 |
# credentials. |
| 26 |
# |
| 27 |
# The peer acting as the SASL server must provide authentication against the |
| 28 |
# received credentials. |
| 29 |
# |
| 30 |
# @note Do not instantiate directly, use {Transport#sasl} to create a SASL object. |
| 31 |
class SASL |
| 32 |
include Util::Deprecation |
| 33 |
|
| 34 |
# Negotation has not completed. |
| 35 |
NONE = Cproton::PN_SASL_NONE |
| 36 |
# Authentication succeeded. |
| 37 |
OK = Cproton::PN_SASL_OK |
| 38 |
# Authentication failed due to bad credentials. |
| 39 |
AUTH = Cproton::PN_SASL_AUTH |
| 40 |
|
| 41 |
private |
| 42 |
|
| 43 |
extend Util::SWIGClassHelper |
| 44 |
PROTON_METHOD_PREFIX = "pn_sasl" |
| 45 |
|
| 46 |
public |
| 47 |
|
| 48 |
# @private |
| 49 |
# @note Do not instantiate directly, use {Transport#sasl} to create a SASL object. |
| 50 |
def initialize(transport) |
| 51 |
@impl = Cproton.pn_sasl(transport.impl) |
| 52 |
end |
| 53 |
|
| 54 |
# @!attribute allow_insecure_mechs |
| 55 |
# @return [Bool] true if clear text authentication is allowed on insecure connections. |
| 56 |
proton_set_get :allow_insecure_mechs |
| 57 |
|
| 58 |
# @!attribute user [r] |
| 59 |
# @return [String] the authenticated user name |
| 60 |
proton_get :user |
| 61 |
|
| 62 |
# Set the mechanisms allowed for SASL negotation |
| 63 |
# @param mechanisms [String] space-delimited list of allowed mechanisms |
| 64 |
def allowed_mechs=(mechanisms) |
| 65 |
Cproton.pn_sasl_allowed_mechs(@impl, mechanisms) |
| 66 |
end |
| 67 |
|
| 68 |
# @deprecated use {#allowed_mechs=} |
| 69 |
deprecated_alias :mechanisms, :allowed_mechs= |
| 70 |
|
| 71 |
# True if extended SASL negotiation is supported |
| 72 |
# |
| 73 |
# All implementations of Proton support ANONYMOUS and EXTERNAL on both |
| 74 |
# client and server sides and PLAIN on the client side. |
| 75 |
# |
| 76 |
# Extended SASL implememtations use an external library (Cyrus SASL) |
| 77 |
# to support other mechanisms. |
| 78 |
# |
| 79 |
# @return [Bool] true if extended SASL negotiation is supported |
| 80 |
def self.extended?() |
| 81 |
Cproton.pn_sasl_extended() |
| 82 |
end |
| 83 |
|
| 84 |
class << self |
| 85 |
include Util::Deprecation |
| 86 |
|
| 87 |
# Set the sasl configuration path |
| 88 |
# |
| 89 |
# This is used to tell SASL where to look for the configuration file. |
| 90 |
# In the current implementation it can be a colon separated list of directories. |
| 91 |
# |
| 92 |
# The environment variable PN_SASL_CONFIG_PATH can also be used to set this path, |
| 93 |
# but if both methods are used then this pn_sasl_config_path() will take precedence. |
| 94 |
# |
| 95 |
# If not set the underlying implementation default will be used. |
| 96 |
# |
| 97 |
# @param path the configuration path |
| 98 |
# |
| 99 |
def config_path=(path) |
| 100 |
Cproton.pn_sasl_config_path(nil, path) |
| 101 |
path |
| 102 |
end |
| 103 |
|
| 104 |
# Set the configuration file name, without extension |
| 105 |
# |
| 106 |
# The name with an a ".conf" extension will be searched for in the |
| 107 |
# configuration path. If not set, it defaults to "proton-server" or |
| 108 |
# "proton-client" for a server (incoming) or client (outgoing) connection |
| 109 |
# respectively. |
| 110 |
# |
| 111 |
# @param name the configuration file name without extension |
| 112 |
# |
| 113 |
def config_name=(name) |
| 114 |
Cproton.pn_sasl_config_name(nil, name) |
| 115 |
end |
| 116 |
|
| 117 |
# @deprecated use {config_path=} |
| 118 |
deprecated_alias :config_path, :config_path= |
| 119 |
# @deprecated use {config_name=} |
| 120 |
deprecated_alias :config_name, :config_name= |
| 121 |
end |
| 122 |
end |
| 123 |
end |