View Javadoc

1   package fr.in2p3.jsaga.adaptor.security;
2   
3   import fr.in2p3.jsaga.adaptor.security.impl.GSSCredentialSecurityCredential;
4   import fr.in2p3.jsaga.adaptor.security.impl.UserPassSecurityCredential;
5   import org.ogf.saga.context.Context;
6   import org.ogf.saga.error.NoSuccessException;
7   import org.ogf.saga.error.NotImplementedException;
8   
9   import java.io.PrintStream;
10  
11  /* ***************************************************
12  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
13  * ***             http://cc.in2p3.fr/             ***
14  * ***************************************************
15  * File:   UserPassExpirableSecurityCredential
16  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
17  * Date:   24 sept. 2007
18  * ***************************************************
19  * Description:                                      */
20  /**
21   *
22   */
23  public class UserPassExpirableSecurityCredential extends UserPassSecurityCredential {
24      private int m_expiryDate;
25  
26      public UserPassExpirableSecurityCredential(String userId, String userPass, int expiryDate) {
27          super(userId, userPass);
28          // set expiration date
29          m_expiryDate = expiryDate;
30      }
31  
32      /** override super.getAttribute() */
33      public String getAttribute(String key) throws NotImplementedException, NoSuccessException {
34          if (Context.LIFETIME.equals(key)) {
35              return ""+this.getLifeTime();
36          } else {
37              return super.getAttribute(key);
38          }
39      }
40  
41      public void dump(PrintStream out) throws Exception {
42          super.dump(out);
43          out.println("  LifeTime : "+ GSSCredentialSecurityCredential.format(this.getLifeTime()));
44      }
45  
46      private int getLifeTime() {
47          int currentDate = (int) (System.currentTimeMillis()/1000);
48          int lifeTime = m_expiryDate - currentDate;
49          return (lifeTime>0 ? lifeTime : 0);
50      }
51  }