Class: Faction::Client
- Inherits:
-
Object
- Object
- Faction::Client
- Defined in:
- lib/faction.rb
Overview
See docs.atlassian.com/crowd/current/com/atlassian/crowd/integration/service/soap/server/SecurityServer.html for Crowd SOAP API documentation.
The validation_factors
parameter is a Hash
that can contain the following keys:
-
:user_agent
-ValidationFactor.USER_AGENT
-
:remote_address
-ValidationFactor.REMOTE_ADDRESS
-
:remote_host
-ValidationFactor.REMOTE_HOST
-
:forwarded_for
-ValidationFactor.X_FORWARDED_FOR
-
:random_number
-ValidationFactor.RANDOM_NUMBER
-
:name
-ValidationFactor.NAME
Constant Summary collapse
- @@debug =
false
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Application name.
-
#app_password ⇒ Object
readonly
Application password.
-
#crowd_url ⇒ Object
readonly
Url of the Crowd SecurityServer.
Class Method Summary collapse
-
.debug=(value) ⇒ Object
Sets the global debugging for Client.
-
.debug? ⇒ Boolean
True if Faction is in debug mode.
-
.from_properties(properties_file) ⇒ Object
Instantiates a new client using a “standard”
crowd.properties
file.
Instance Method Summary collapse
- #add_principal(username, password, description, active, attributes) ⇒ Object
- #add_principal_to_group(principal, group) ⇒ Object
-
#authenticate_principal(name, password, validation_factors = nil) ⇒ Object
See
SecurityServerClient.authenticatePrincipal
. - #cache_enabled? ⇒ Boolean
- #cache_time ⇒ Object
-
#cookie_info ⇒ Object
See
SecurityServerClient.getCookieInfo
Returns aHash
containing the cookie info fields. -
#create_principal_token(name, validation_factors = nil) ⇒ Object
See
SecurityServerClient.createPrincipalToken
. - #find_group_by_name(name) ⇒ Object
- #find_group_memberships(name) ⇒ Object
- #find_principal_by_name(name) ⇒ Object
-
#find_principal_by_token(token) ⇒ Object
See
SecurityServer.findPrincipalByToken
Returns the principal information as aHash
. - #find_principal_with_attributes_by_name(name) ⇒ Object
- #get_cookie_info ⇒ Object
- #granted_authorities ⇒ Object
- #group_names ⇒ Object
-
#initialize(crowd_url, app_name, app_password, options = {}) ⇒ Client
constructor
Creates a new Crowd client.
-
#invalidate_principal_token(token) ⇒ Object
See
SecurityServerClient.invalidatePrincipalToken
. - #principal_names ⇒ Object
- #remove_principal(principal) ⇒ Object
-
#update_principal_credential(name, new_password) ⇒ Object
See
SecurityServer.updatePrincipalCredential
. -
#valid_principal_token?(token, validation_factors = nil) ⇒ Boolean
See
SecurityServerClient.isValidPrincipalToken
.
Constructor Details
#initialize(crowd_url, app_name, app_password, options = {}) ⇒ Client
Creates a new Crowd client.
Parameters:
-
crowd_url
- The URL to Crowd SecurityServer. -
app_name
- Application name. -
app_password
- Application password. -
options
- A Hash of options (described below).
Options
-
:verify_cert
- Iffalse
the peer SSL certificate is not verified.
Example:
Faction::Client.new('http://localhost:8085/crowd/services/SecurityServer', 'application', 'password')
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/faction.rb', line 67 def initialize(crowd_url, app_name, app_password, = {}) @crowd_url = crowd_url @crowd = Savon::Client.new(@crowd_url + (Client.debug? ? '?wsdl' : '')) if [:verify_cert] == false @crowd.request.http.ssl_client_auth(:verify_mode => OpenSSL::SSL::VERIFY_NONE) end @app_name = app_name @app_password = app_password @app_token = nil end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Application name
39 40 41 |
# File 'lib/faction.rb', line 39 def app_name @app_name end |
#app_password ⇒ Object (readonly)
Application password
41 42 43 |
# File 'lib/faction.rb', line 41 def app_password @app_password end |
#crowd_url ⇒ Object (readonly)
Url of the Crowd SecurityServer
37 38 39 |
# File 'lib/faction.rb', line 37 def crowd_url @crowd_url end |
Class Method Details
.debug=(value) ⇒ Object
Sets the global debugging for Client
27 28 29 |
# File 'lib/faction.rb', line 27 def self.debug=(value) @@debug = value end |
.debug? ⇒ Boolean
True if Faction is in debug mode
32 33 34 |
# File 'lib/faction.rb', line 32 def self.debug? @@debug end |
.from_properties(properties_file) ⇒ Object
Instantiates a new client using a “standard” crowd.properties
file.
44 45 46 47 48 49 50 51 |
# File 'lib/faction.rb', line 44 def self.from_properties(properties_file) props = Hash[*open(properties_file).readlines.map {|line| line.split(/=/, 2).map(&:strip)}.flatten] self.new(props['crowd.server.url'] + '/SecurityServer', props['application.name'], props['application.password'], :verify_cert => ['yes', 'true'].include?(props['ssl.verify'])) end |
Instance Method Details
#add_principal(username, password, description, active, attributes) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/faction.rb', line 180 def add_principal(username, password, description, active, attributes) soap_attributes = attributes.map do |name, value| {'p:name' => name, 'p:values' => {'wsdl:string' => value}} end soap_principal = { 'p:active' => active, 'p:name' => username, 'p:description' => description, 'p:attributes' => {'p:SOAPAttribute' => soap_attributes} } credential = { 'auth:credential' => password, 'auth:encryptedCredential' => false } simplify_soap_attributes(authenticated_crowd_call(:add_principal, soap_principal, credential)) end |
#add_principal_to_group(principal, group) ⇒ Object
172 173 174 |
# File 'lib/faction.rb', line 172 def add_principal_to_group(principal, group) authenticated_crowd_call(:add_principal_to_group, principal, group) && nil end |
#authenticate_principal(name, password, validation_factors = nil) ⇒ Object
See SecurityServerClient.authenticatePrincipal
79 80 81 82 83 84 85 |
# File 'lib/faction.rb', line 79 def authenticate_principal(name, password, validation_factors = nil) authenticated_crowd_call(:authenticate_principal, { 'auth:application' => app_name, 'auth:name' => name, 'auth:credential' => {'auth:credential' => password, 'auth:encryptedCredential' => false}, 'auth:validationFactors' => convert_validation_factors(validation_factors)}) end |
#cache_enabled? ⇒ Boolean
164 165 166 |
# File 'lib/faction.rb', line 164 def cache_enabled? authenticated_crowd_call(:is_cache_enabled) end |
#cache_time ⇒ Object
168 169 170 |
# File 'lib/faction.rb', line 168 def cache_time authenticated_crowd_call(:get_cache_time) end |
#cookie_info ⇒ Object
See SecurityServerClient.getCookieInfo
Returns a Hash
containing the cookie info fields.
102 103 104 |
# File 'lib/faction.rb', line 102 def authenticated_crowd_call(:get_cookie_info) end |
#create_principal_token(name, validation_factors = nil) ⇒ Object
See SecurityServerClient.createPrincipalToken
88 89 90 91 92 93 |
# File 'lib/faction.rb', line 88 def create_principal_token(name, validation_factors = nil) authenticated_crowd_call(:create_principal_token, { 'auth:application' => app_name, 'auth:name' => name, 'auth:validationFactors' => convert_validation_factors(validation_factors)}) end |
#find_group_by_name(name) ⇒ Object
144 145 146 |
# File 'lib/faction.rb', line 144 def find_group_by_name(name) simplify_soap_group(authenticated_crowd_call(:find_group_by_name, name)) end |
#find_group_memberships(name) ⇒ Object
148 149 150 |
# File 'lib/faction.rb', line 148 def find_group_memberships(name) arrayify(authenticated_crowd_call(:find_group_memberships, name)[:string]) end |
#find_principal_by_name(name) ⇒ Object
136 137 138 |
# File 'lib/faction.rb', line 136 def find_principal_by_name(name) simplify_soap_attributes(authenticated_crowd_call(:find_principal_by_name, name)) end |
#find_principal_by_token(token) ⇒ Object
See SecurityServer.findPrincipalByToken
Returns the principal information as a Hash
.
132 133 134 |
# File 'lib/faction.rb', line 132 def find_principal_by_token(token) simplify_soap_attributes(authenticated_crowd_call(:find_principal_by_token, token)) end |
#find_principal_with_attributes_by_name(name) ⇒ Object
140 141 142 |
# File 'lib/faction.rb', line 140 def find_principal_with_attributes_by_name(name) simplify_soap_attributes(authenticated_crowd_call(:find_principal_with_attributes_by_name, name)) end |
#get_cookie_info ⇒ Object
106 107 108 109 |
# File 'lib/faction.rb', line 106 def $stderr.puts('faction: get_cookie_info deprecated, use cookie_info instead') end |
#granted_authorities ⇒ Object
160 161 162 |
# File 'lib/faction.rb', line 160 def authenticated_crowd_call(:get_granted_authorities)[:string] end |
#group_names ⇒ Object
152 153 154 |
# File 'lib/faction.rb', line 152 def group_names authenticated_crowd_call(:find_all_group_names)[:string] end |
#invalidate_principal_token(token) ⇒ Object
See SecurityServerClient.invalidatePrincipalToken
96 97 98 |
# File 'lib/faction.rb', line 96 def invalidate_principal_token(token) authenticated_crowd_call(:invalidate_principal_token, token) && nil end |
#principal_names ⇒ Object
156 157 158 |
# File 'lib/faction.rb', line 156 def principal_names authenticated_crowd_call(:find_all_principal_names)[:string] end |
#remove_principal(principal) ⇒ Object
176 177 178 |
# File 'lib/faction.rb', line 176 def remove_principal(principal) authenticated_crowd_call(:remove_principal, principal) && nil end |
#update_principal_credential(name, new_password) ⇒ Object
See SecurityServer.updatePrincipalCredential
124 125 126 127 128 |
# File 'lib/faction.rb', line 124 def update_principal_credential(name, new_password) authenticated_crowd_call(:update_principal_credential, name, {'auth:credential' => new_password, 'auth:encryptedCredential' => false}) end |
#valid_principal_token?(token, validation_factors = nil) ⇒ Boolean
See SecurityServerClient.isValidPrincipalToken
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/faction.rb', line 112 def valid_principal_token?(token, validation_factors = nil) if (validation_factors.nil? || validation_factors.empty?) authenticated_crowd_call(:is_valid_principal_token, token,"") else authenticated_crowd_call(:is_valid_principal_token, token, {'auth:validationFactors' => convert_validation_factors(validation_factors)}) end end |