diff options
author | mr <mr@mrautenberg.de> | 2010-12-09 10:46:13 +0100 |
---|---|---|
committer | mr <mr@mrautenberg.de> | 2010-12-09 10:46:13 +0100 |
commit | c4504c72ffb2920de65399a2dc0a2c29fe04a52d (patch) | |
tree | badc015e7f3f66ddd2f0fdef9d1e05d7d80a5341 | |
parent | bb99bb49636db1d3f07b6f540dc8624a677ade2f (diff) |
A&A implementation
-rw-r--r-- | lib/dataset.rb | 12 | ||||
-rw-r--r-- | lib/helper.rb | 4 | ||||
-rw-r--r-- | lib/model.rb | 4 | ||||
-rw-r--r-- | lib/templates/default_guest_policy.xml | 53 | ||||
-rw-r--r-- | lib/templates/default_policy.xml | 53 |
5 files changed, 118 insertions, 8 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index c5704ae..bbd8b8b 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -6,6 +6,7 @@ module OpenTox include OpenTox attr_reader :features, :compounds, :data_entries, :metadata + attr_accessor :token_id # Create dataset with optional URI. Does not load data into the dataset - you will need to execute one of the load_* methods to pull data from a service or to insert it from other representations. # @example Create an empty dataset @@ -14,8 +15,9 @@ module OpenTox # dataset = OpenTox::Dataset.new("http:://webservices.in-silico/ch/dataset/1") # @param [optional, String] uri Dataset URI # @return [OpenTox::Dataset] Dataset object - def initialize(uri=nil) + def initialize(uri=nil,token_id=nil) super uri + @token_id = token_id @features = {} @compounds = [] @data_entries = {} @@ -26,8 +28,9 @@ module OpenTox # dataset = OpenTox::Dataset.create # @param [optional, String] uri Dataset URI # @return [OpenTox::Dataset] Dataset object - def self.create(uri=CONFIG[:services]["opentox-dataset"]) + def self.create(uri=CONFIG[:services]["opentox-dataset"], token_id=nil) dataset = Dataset.new + dataset.token_id = token_id if token_id dataset.save dataset end @@ -252,7 +255,7 @@ module OpenTox @compounds.uniq! if @uri if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) - RestClientWrapper.post(@uri,{:content_type => "application/x-yaml"},self.to_yaml) + RestClientWrapper.post(@uri,{:content_type => "application/x-yaml", :token_id => @token_id},self.to_yaml) else File.open("ot-post-file.rdf","w+") { |f| f.write(self.to_rdfxml); @path = f.path } task_uri = RestClient.post(@uri, {:file => File.new(@path)},{:accept => "text/uri-list"}).to_s.chomp @@ -262,7 +265,7 @@ module OpenTox end else # create dataset if uri is empty - self.uri = RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{}).to_s.chomp + self.uri = RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:token_id => @token_id}).to_s.chomp end @uri end @@ -279,6 +282,7 @@ module OpenTox @data_entries = dataset.data_entries @compounds = dataset.compounds @features = dataset.features + @token_id = dataset.token_id if @uri self.uri = @uri else diff --git a/lib/helper.rb b/lib/helper.rb index b69f9b4..11f790b 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -17,7 +17,7 @@ helpers do ret = OpenTox::Authorization.authorize(request.env['SCRIPT_URI'], request.env['REQUEST_METHOD'], token_id) LOGGER.debug "OpenTox helpers OpenTox::Authorization authorized? method: #{request.env['REQUEST_METHOD']} , URI: #{request.env['SCRIPT_URI']}, token_id: #{token_id} with return #{ret}." return ret - when "POST" + when "POST", "HEAD" if OpenTox::Authorization.is_token_valid(token_id) LOGGER.debug "OpenTox helpers OpenTox::Authorization.is_token_valid: true" return true @@ -25,7 +25,6 @@ helpers do LOGGER.warn "OpenTox helpers POST on #{request.env['SCRIPT_URI']} with token_id: #{token_id} false." end LOGGER.debug "Not authorized for: 1. #{request['SCRIPT_URI']} 2. #{request.env['SCRIPT_URI']} with Method: #{request.env['REQUEST_METHOD']} with Token #{token_id}" - LOGGER.debug "Request infos: #{request.inspect}" return false end @@ -55,6 +54,7 @@ before do token_id = params[:token_id] if params[:token_id] and !check_token_id(token_id) token_id = request.env['HTTP_TOKEN_ID'] if request.env['HTTP_TOKEN_ID'] and !check_token_id(token_id) # see http://rack.rubyforge.org/doc/SPEC.html + token_id = CGI.unescape(token_id) if token_id.include?("%23") rescue LOGGER.debug "OpenTox api wrapper: helper before filter: NO token_id." token_id = "" diff --git a/lib/model.rb b/lib/model.rb index 5654bcc..5dc4d4a 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -32,7 +32,7 @@ module OpenTox include Model include Algorithm - attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :min_sim + attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :min_sim, :token_id def initialize(uri=nil) @@ -258,7 +258,7 @@ module OpenTox # Save model at model service def save - self.uri = RestClientWrapper.post(@uri,{:content_type => "application/x-yaml"},self.to_yaml) + self.uri = RestClientWrapper.post(@uri,{:content_type => "application/x-yaml", :token_id => @token_id},self.to_yaml) end # Delete model at model service diff --git a/lib/templates/default_guest_policy.xml b/lib/templates/default_guest_policy.xml new file mode 100644 index 0000000..a778070 --- /dev/null +++ b/lib/templates/default_guest_policy.xml @@ -0,0 +1,53 @@ +<!DOCTYPE Policies PUBLIC "-//Sun Java System Access Manager7.1 2006Q3 + Admin CLI DTD//EN" "jar://com/sun/identity/policy/policyAdmin.dtd"> + +<Policies> +<Policy name="policy_user" referralPolicy="false" active="true"> + <Rule name="rule_user"> + <ServiceName name="iPlanetAMWebAgentService" /> + <ResourceName name="uri"/> + <AttributeValuePair> + <Attribute name="GET" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="POST" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="PUT" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="DELETE" /> + <Value>allow</Value> + </AttributeValuePair> + </Rule> + <Subjects name="subjects_user" description=""> + <Subject name="subject_user" type="LDAPUsers" includeType="inclusive"> + <AttributeValuePair> + <Attribute name="Values"/> + <Value>uid=guest,ou=people,dc=opentox,dc=org</Value> + </AttributeValuePair> + </Subject> + </Subjects> +</Policy> +<Policy name="policy_group" referralPolicy="false" active="true"> + <Rule name="rule_group"> + <ServiceName name="iPlanetAMWebAgentService" /> + <ResourceName name="uri"/> + <AttributeValuePair> + <Attribute name="GET" /> + <Value>allow</Value> + </AttributeValuePair> + </Rule> + <Subjects name="subjects_group" description=""> + <Subject name="subject_group" type="LDAPGroups" includeType="inclusive"> + <AttributeValuePair> + <Attribute name="Values"/> + <Value>cn=member,ou=groups,dc=opentox,dc=org</Value> + </AttributeValuePair> + </Subject> + </Subjects> +</Policy> +</Policies> diff --git a/lib/templates/default_policy.xml b/lib/templates/default_policy.xml new file mode 100644 index 0000000..a778070 --- /dev/null +++ b/lib/templates/default_policy.xml @@ -0,0 +1,53 @@ +<!DOCTYPE Policies PUBLIC "-//Sun Java System Access Manager7.1 2006Q3 + Admin CLI DTD//EN" "jar://com/sun/identity/policy/policyAdmin.dtd"> + +<Policies> +<Policy name="policy_user" referralPolicy="false" active="true"> + <Rule name="rule_user"> + <ServiceName name="iPlanetAMWebAgentService" /> + <ResourceName name="uri"/> + <AttributeValuePair> + <Attribute name="GET" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="POST" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="PUT" /> + <Value>allow</Value> + </AttributeValuePair> + <AttributeValuePair> + <Attribute name="DELETE" /> + <Value>allow</Value> + </AttributeValuePair> + </Rule> + <Subjects name="subjects_user" description=""> + <Subject name="subject_user" type="LDAPUsers" includeType="inclusive"> + <AttributeValuePair> + <Attribute name="Values"/> + <Value>uid=guest,ou=people,dc=opentox,dc=org</Value> + </AttributeValuePair> + </Subject> + </Subjects> +</Policy> +<Policy name="policy_group" referralPolicy="false" active="true"> + <Rule name="rule_group"> + <ServiceName name="iPlanetAMWebAgentService" /> + <ResourceName name="uri"/> + <AttributeValuePair> + <Attribute name="GET" /> + <Value>allow</Value> + </AttributeValuePair> + </Rule> + <Subjects name="subjects_group" description=""> + <Subject name="subject_group" type="LDAPGroups" includeType="inclusive"> + <AttributeValuePair> + <Attribute name="Values"/> + <Value>cn=member,ou=groups,dc=opentox,dc=org</Value> + </AttributeValuePair> + </Subject> + </Subjects> +</Policy> +</Policies> |