source: TI12-security/tags/start/AccessToken.py @ 380

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/tags/start/AccessToken.py@8760
Revision 380, 2.1 KB checked in by lawrence, 15 years ago (diff)

Creating NDG security directory

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#Copyright (C) 2004 CCLRC & NERC
2#    This software may be distributed under the terms of the
3#    Q Public License, version 1.0 or later
4#
5# Version 0.1 BNL November 12, 2004
6
7from X500DN import X500DN
8
9class Validity:
10  def __init__(self,start=(0,0,0,0,0),finish=(0,0,0,0,0)):
11    self.start=start
12    self.finish=finish
13  def checkvalid(now=None):
14    valid=0
15    if now is None:
16      pass
17      #really what we should do is get the current time
18    else:
19      valid=1
20      #for i in range(5):
21      #  if now[i]<self.start[i] or now[i]>self.finish[i]:valid=0
22    return valid
23
24class AccessToken(Validity):
25  ''' Handle an NDG token
26      Version 0.1, BNL, November 12, 2004 '''
27
28  def __init__(self,holder=None,issuer=None,dpat=None):
29    self.holder=X500DN()
30    self.issuer=X500DN()
31    self.signature=''
32    self.attributes=[]
33    Validity.__init__(self)
34    if dpat!=None:
35      self.xmlset(dpat)
36    else:
37      self.set(holder,issuer)
38
39  def set(self,holder=None,issuer=None):
40    if holder is not None: self.holder.update(holder)
41    if issuer is not None: self.issuer.update(issuer)
42
43
44  def sign(self):
45    pass    # for now
46
47  def checkSig(self):
48    return 1  #for now
49   
50  def add(self,args):
51    self.attributes.extend(args)
52
53  def show(self):
54    lines='___________________'
55    print lines,'  Holder  ',lines
56    for i in self.holder.keys():
57      if self.holder[i] !='': print i,self.holder[i]
58    print lines,'  Issuer  ', lines
59    for i in self.issuer.keys():
60      if self.issuer[i] !='': print i,self.issuer[i]
61    print lines,'  Validity  ',lines[:-2]
62    print 'Valid from :', self.start,' to ',self.finish
63
64  def xmlset(self,dpat):
65    ''' This piece of code parses an XML CLRC Data Portal Access Token
66    and sets this Access Token accordingly'''
67    pass
68
69  def xmlout(self):
70    ''' This piece of code write a CCLRC Data Portal Access Token encoded in
71    XML '''
72    dpat=''
73    return dpat
74    pass
75
76if __name__=='__main__':
77  print 'demonstrate use of Access Token'
78  holder=X500DN({'DN':'Bryan Lawrence','O':'NERC DataGrid','C':'UK'})
79  issuer=X500DN({'DN':'NDG Data Provider','O':'BADC','C':'UK'})
80  at=AccessToken(holder=holder,issuer=issuer)
81  at.show()
Note: See TracBrowser for help on using the repository browser.