Class: Faction::Client

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 - If false 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, options = {})
  @crowd_url = crowd_url
  @crowd = Savon::Client.new(@crowd_url + (Client.debug? ? '?wsdl' : ''))
  if options[: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_nameObject (readonly)

Application name



39
40
41
# File 'lib/faction.rb', line 39

def app_name
  @app_name
end

#app_passwordObject (readonly)

Application password



41
42
43
# File 'lib/faction.rb', line 41

def app_password
  @app_password
end

#crowd_urlObject (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

Returns:

  • (Boolean)


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



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/faction.rb', line 175

def add_principal(username, password, description, active, attributes)
  soap_attributes = attributes.map do |name, value|
    {'p:SOAPAttribute' => {'p:name' => name, 'p:values' => {'wsdl:string' => value}}}
  end
  soap_principal = {
      'p:active'      => active,
      'p:name'        => username,
      'p:description' => description,
      'p:attributes'  => 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



167
168
169
# File 'lib/faction.rb', line 167

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

Returns:

  • (Boolean)


159
160
161
# File 'lib/faction.rb', line 159

def cache_enabled?
  authenticated_crowd_call(:is_cache_enabled)
end

#cache_timeObject



163
164
165
# File 'lib/faction.rb', line 163

def cache_time
  authenticated_crowd_call(:get_cache_time)
end

See SecurityServerClient.getCookieInfo Returns a Hash containing the cookie info fields.



102
103
104
# File 'lib/faction.rb', line 102

def cookie_info
  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



139
140
141
# File 'lib/faction.rb', line 139

def find_group_by_name(name)
  simplify_soap_group(authenticated_crowd_call(:find_group_by_name, name))
end

#find_group_memberships(name) ⇒ Object



143
144
145
# File 'lib/faction.rb', line 143

def find_group_memberships(name)
  arrayify(authenticated_crowd_call(:find_group_memberships, name)[:string])
end

#find_principal_by_name(name) ⇒ Object



131
132
133
# File 'lib/faction.rb', line 131

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.



127
128
129
# File 'lib/faction.rb', line 127

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



135
136
137
# File 'lib/faction.rb', line 135

def find_principal_with_attributes_by_name(name)
  simplify_soap_attributes(authenticated_crowd_call(:find_principal_with_attributes_by_name, name))
end


106
107
108
109
# File 'lib/faction.rb', line 106

def get_cookie_info
  $stderr.puts('faction: get_cookie_info deprecated, use cookie_info instead')
  cookie_info
end

#granted_authoritiesObject



155
156
157
# File 'lib/faction.rb', line 155

def granted_authorities
  authenticated_crowd_call(:get_granted_authorities)[:string]
end

#group_namesObject



147
148
149
# File 'lib/faction.rb', line 147

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_namesObject



151
152
153
# File 'lib/faction.rb', line 151

def principal_names
  authenticated_crowd_call(:find_all_principal_names)[:string]
end

#remove_principal(principal) ⇒ Object



171
172
173
# File 'lib/faction.rb', line 171

def remove_principal(principal)
  authenticated_crowd_call(:remove_principal, principal) && nil
end

#update_principal_credential(name, new_password) ⇒ Object

See SecurityServer.updatePrincipalCredential



119
120
121
122
123
# File 'lib/faction.rb', line 119

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

Returns:

  • (Boolean)


112
113
114
115
116
# File 'lib/faction.rb', line 112

def valid_principal_token?(token, validation_factors = nil)
  authenticated_crowd_call(:is_valid_principal_token,
                           token,
                           {'auth:validationFactors' => convert_validation_factors(validation_factors)})
end