Class: SlingAuthz::Authz

Inherits:
Object
  • Object
show all
Defined in:
lib/nakamura/authz.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sling) ⇒ Authz

Returns a new instance of Authz.



11
12
13
14
15
# File 'lib/nakamura/authz.rb', line 11

def initialize(sling)
  @sling = sling
  @log = Logger.new(STDOUT)
  @log.level = Logger::WARN
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



9
10
11
# File 'lib/nakamura/authz.rb', line 9

def log
  @log
end

Instance Method Details

#delete(path, principal) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nakamura/authz.rb', line 17

def delete(path,principal)
postParams = {}
  postParams[':applyTo'] = [principal]
  urlpath = @sling.url_for(path)	  
  res = @sling.execute_post(urlpath+".deleteAce.html", postParams)
  if ( res.code != "200" )
     @log.debug(res.body)
     @log.info(" Unable to update acl at #{path} "+postParams)
	 return false 
  end 

end

#getacl(path) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nakamura/authz.rb', line 67

def getacl(path)
  urlpath = @sling.url_for(path)
  res = @sling.execute_get(urlpath+".acl.json")
  if ( res.code != "200" )
     log.info(" Unable to get ACL at path #{path} ")
	 return false
  end
  @log.info("Current ACE :"+res.body)
  
  acl = JSON.parse(res.body)
  return acl
end

#grant(path, principal, privilege) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nakamura/authz.rb', line 30

def grant(path,principal,privilege)
	  
	  acl = getacl(path)
	  ace = {}
	  if ( acl[principal] )
  @log.info(acl[principal])
		 ace = acl[principal]
	  end
	  postParams = {}
	  postParams['principalId'] = principal
	  
	  # Save the current ACE
	  ace.each do | key, value |
 if ( key == "granted" || key == "denied" )
value.each do | priv |
  postParams['privilege@'+priv] = key
end 
		end
	  end
	  
	  # Add in the new ACE
	  privilege.each do | key, value |
		postParams['privilege@'+key] = value
	  end
	  
	  @log.info("Updating ACE to :"+hashToString(postParams))

		
	  urlpath = @sling.url_for(path)	  
	  res = @sling.execute_post(urlpath+".modifyAce.html", postParams)
	  if ( res.code != "200" )
  @log.debug(res.body)
  @log.info(" Unable to update acl at #{path} "+postParams)
		 return false 
	  end 
end

#hashToString(hashVar) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/nakamura/authz.rb', line 80

def hashToString(hashVar) 
  fs = "{"
  hashVar.each do | key, value |
    fs = fs + '"' + key + '" => "'+value.to_s+'",' 
  end
  fs = fs + "}"
end