Class: OpenTox::TBAccount

Inherits:
Object
  • Object
show all
Includes:
OpenTox
Defined in:
tbaccount.rb

Overview

Get RDF representation for a user, organisation or project from the ToxBank service

Examples:

TBAccount

require "opentox-server"
OpenTox::Authorization.authenticate("user", "password")
User1 = OpenTox::TBAccount.new("http://uri_to_toxbankservice/toxbank/user/U123")
puts User1.ldap_dn #=> "uid=username,ou=people,dc=opentox,dc=org"
User1.send_policy("http://uri_toprotect/bla/foo") #=> creates new read policy for http://uri_toprotect/bla/foo

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search_organisation(organisation) ⇒ String

Search an organisation URI in the user service

Parameters:

  • organisation (String)

    organisation-name

  • subjectid (String)

Returns:

  • (String)

    userURI


53
54
55
56
57
# File 'tbaccount.rb', line 53

def self.search_organisation organisation
  result = `curl -Lk -X GET -H "Accept:text/uri-list" -H "subjectid:#{RestClientWrapper.subjectid}" #{$user_service[:uri]}/organisation?search=#{organisation}`.chomp.sub("\n","")
  return result if !result.match("Not Found")
  false
end

.search_project(project) ⇒ String

Search a project URI in the user service

Parameters:

  • project (String)

    projectname

  • subjectid (String)

Returns:

  • (String)

    userURI


43
44
45
46
47
# File 'tbaccount.rb', line 43

def self.search_project project
  result = `curl -Lk -X GET -H "Accept:text/uri-list" -H "subjectid:#{RestClientWrapper.subjectid}" #{$user_service[:uri]}/project?search=#{project}`.chomp.sub("\n","")
  return result if !result.match("Not Found")
  false
end

.search_user(user) ⇒ String

Search a user URI in the user service

Parameters:

  • user (String)

    username

  • subjectid (String)

Returns:

  • (String)

    userURI


33
34
35
36
37
# File 'tbaccount.rb', line 33

def self.search_user user
  result = `curl -Lk -X GET -H "Accept:text/uri-list" -H "subjectid:#{RestClientWrapper.subjectid}" #{$user_service[:uri]}/user?username=#{user}`.chomp.sub("\n","")
  return result if !result.match("Not Found")
  false
end

Instance Method Details

#accountString

Get hasAccount value of a user,organisation or project from ToxBank service

Returns:

  • (String)

    username


61
62
63
# File 'tbaccount.rb', line 61

def 
  @account ||= 
end

#get_policy(uri, type = "read") ⇒ String

GET policy XML

Parameters:

  • uri (String)

    URI

  • type (String) (defaults to: "read")

    Type URI to protect, Access-rights < “all”, “readwrite”, “read” (default) >

Returns:

  • (String)

    policy in XML


81
82
83
# File 'tbaccount.rb', line 81

def get_policy uri, type="read"
  policy(uri, type)
end

#ldap_dnString

Generates LDAP Distinguished Name (DN)

Returns:

  • (String)

    LDAP Distinguished Name (DN)


67
68
69
# File 'tbaccount.rb', line 67

def ldap_dn
  @uri.match(RDF::TBU.to_s) ? "uid=#{self.},ou=people,dc=opentox,dc=org" : "cn=#{self.},ou=groups,dc=opentox,dc=org"
end

#ldap_typeString

Get LDAP type - returns 'LDAPUsers' if the TBAccount.uri is a user URI

Returns:

  • (String)

    'LDAPUsers' or 'LDAPGroups'


73
74
75
# File 'tbaccount.rb', line 73

def ldap_type
  @uri.match(RDF::TBU.to_s) ? "LDAPUsers" : "LDAPGroups"
end

#ns_uriString

Change account URI into RDF prefixed Version e.G.: “toxbanktest1.opentox.org:8080/toxbank/user/U2” becomes “TBU:U2”

Examples:

user = OpenTox::TBAccount.new("http://uri_to_toxbankservice/toxbank/user/U2")
puts user.ns_uri #=> "RDF::TBU:U2"

Returns:

  • (String)

    prefixed URI of a user/organisation/project


96
97
98
99
100
101
# File 'tbaccount.rb', line 96

def ns_uri
  out = "TBU:#{@uri.split('/')[-1]}"  if @uri.match(RDF::TBU.to_s)
  out = "TBO:#{@uri.split('/')[-1]}"  if @uri.match(RDF::TBO.to_s)
  out = "TBPT:#{@uri.split('/')[-1]}" if @uri.match(RDF::TBPT.to_s)
  out
end

#send_policy(uri, type = "read") ⇒ Object

sends policy to opensso server

Parameters:

  • uri (String)

    URI

  • type (String) (defaults to: "read")

    Type URI to protect, Access-rights < “all”, “readwrite”, “read” (default) >


87
88
89
# File 'tbaccount.rb', line 87

def send_policy uri, type="read"
  OpenTox::Authorization.create_policy(policy(uri, type))
end