diff options
author | rautenberg <rautenberg@in-silico.ch> | 2012-05-07 17:48:06 +0200 |
---|---|---|
committer | rautenberg <rautenberg@in-silico.ch> | 2012-05-07 17:48:06 +0200 |
commit | d6f9c38c44fd6b7e41eca1f57451cc452cc4eec7 (patch) | |
tree | 23131e2f6a4d48f1af444a406479edd71d47c9bd /lib | |
parent | e55a25e9fb0c91a581f898ce894a27e8bdd3d780 (diff) | |
parent | 6f25a7f04863b4fc6dccab59d690695371f1f0c7 (diff) |
Diffstat (limited to 'lib')
-rw-r--r-- | lib/opentox.rb | 1 | ||||
-rw-r--r-- | lib/policy.rb | 19 | ||||
-rw-r--r-- | lib/rest-client-wrapper.rb | 3 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/opentox.rb b/lib/opentox.rb index 187eb08..6ce439d 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -111,6 +111,7 @@ module OpenTox end def create service_uri, subjectid=nil + #uri = uri(SecureRandom.uuid) uri = RestClientWrapper.post(service_uri, {}, {:accept => 'text/uri-list', :subjectid => subjectid}) URI.task?(service_uri) ? from_uri(uri, subjectid, false) : from_uri(uri, subjectid) end diff --git a/lib/policy.rb b/lib/policy.rb index 56a90b7..3e7c143 100644 --- a/lib/policy.rb +++ b/lib/policy.rb @@ -58,7 +58,7 @@ module OpenTox when "guest", "anonymous" then "default_guest_policy" else "default_policy" end - xml = File.read(File.join(File.dirname(__FILE__), "templates/#{template}.xml")) + xml = get_xml_template(template) self.load_xml(xml) datestring = Time.now.strftime("%Y-%m-%d-%H-%M-%S-x") + rand(1000).to_s @@ -78,6 +78,10 @@ module OpenTox return true end + def get_xml_template(template) + File.read(File.join(File.dirname(__FILE__), "templates/#{template}.xml")) + end + #loads a xml template def load_xml(xml) rexml = REXML::Document.new(xml) @@ -247,19 +251,22 @@ module OpenTox end # helper method sets value and type to opentox LDAP Distinguished Name (DN) of a user + # @param [String]Username set a username into LDAP DN def set_ot_user(username) self.value = "uid=#{username},ou=people,dc=opentox,dc=org" self.type = "LDAPUsers" true end + # @param [String]Username set a groupname into LDAP DN def set_ot_group(groupname) self.value = "cn=#{groupname},ou=groups,dc=opentox,dc=org" self.type = "LDAPGroups" true end - #rule inside a policy + # policyrule + # sets the permission for REST actions (GET, POST, PUT, DELETE) of a specific URI to allow/deny/nil class Rule attr_accessor :name, :uri, :get, :post, :put, :delete, :read, :readwrite @@ -293,14 +300,18 @@ module OpenTox @put = check_value(value, @put) end + # read getter method def read return true if @get == "allow" && (@put == "deny" || !@put) && (@post == "deny" || !@post) end + # readwrite getter method def readwrite return true if @get == "allow" && @put == "allow" && @post == "allow" end + # Set(true case) or remove read(GET=allow) permissions. + # @param [Boolean]value (true,false) def read=(value) if value @get = "allow"; @put = nil; @post = nil @@ -309,6 +320,8 @@ module OpenTox end end + # Set(true case) or remove readwrite(GET=allow,POST=allow,PUT=allow) permissions. + # @param [Boolean]value (true,false) def readwrite=(value) if value @get = "allow"; @put = "allow"; @post = "allow" @@ -324,6 +337,8 @@ module OpenTox end end + # Subject of a policy + # name(subjectname), type('LDAPUsers' or 'LDAPGroups'), value(LDAP DN e.G.:'uid=guest,ou=people,dc=opentox,dc=org') class Subject attr_accessor :name, :type, :value diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb index 479d5a5..3071432 100644 --- a/lib/rest-client-wrapper.rb +++ b/lib/rest-client-wrapper.rb @@ -18,7 +18,8 @@ module OpenTox # check input @subjectid = headers[:subjectid] ? headers[:subjectid] : nil bad_request_error "Invalid URI: '#{uri}'" unless URI.valid? uri - not_found_error "URI '#{uri}' not found." unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri) + #TODO fix for internal installations + #not_found_error "URI '#{uri}' not found." unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri) bad_request_error "Headers are not a hash: #{headers.inspect}" unless headers==nil or headers.is_a?(Hash) # make sure that no header parameters are set in the payload [:accept,:content_type,:subjectid].each do |header| |