idok-commit AT lists.psi.ch
Subject: Commit emails of the iDok project
List archive
- From: "AFS account Florian Huebner" <huebner AT savannah.psi.ch>
- To: idok-commit AT lists.psi.ch
- Subject: [idok-commit] idok commit r379 - trunk/java/ch/idok/common/util
- Date: Wed, 29 Jul 2009 11:50:43 +0200
- List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
- List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>
Author: huebner
Date: Wed Jul 29 11:50:42 2009
New Revision: 379
Log:
Helper class for the tickets workaround
Added:
trunk/java/ch/idok/common/util/SyncMap.java (contents, props changed)
Added: trunk/java/ch/idok/common/util/SyncMap.java
==============================================================================
--- (empty file)
+++ trunk/java/ch/idok/common/util/SyncMap.java Wed Jul 29 11:50:42 2009
@@ -0,0 +1,94 @@
+package ch.idok.common.util;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.security.auth.Subject;
+
+import ch.idok.common.config.Setup;
+
+public class SyncMap {
+
+ private static SyncMap instance;
+
+ private String[] tokenHashArray = new String[100];
+ private Subject[] subjectArray = new Subject[100];
+ private int tokenPosition = 0;
+
+ private String[] serviceArray = new String[100];
+ private String[] ticketHashArray = new String[100];
+ private int servicePosition = 0;
+
+ static Map<String,byte[]> ticketMap = new HashMap<String, byte[]>();
+ static Map<String,Subject> subjectMap = new HashMap<String,
Subject>();
+
+ static Logger logger_ = Setup.getInstance().getLogger("service.common");
+
+ public static synchronized SyncMap getInstance() {
+ if (instance == null) {
+ instance = new SyncMap();
+ }
+ return instance;
+ }
+
+ public synchronized Subject TokentoSubject(byte[] token){
+
+ return subjectMap.get(getHash(token));
+ }
+
+
+// public synchronized byte[] SubjecttoToken(Subject sub){
+//
+// return null;
+// }
+
+ public synchronized byte[] ServicetoTicket(String service){
+
+ return ticketMap.get(service);
+ }
+
+// public synchronized String TickettoService(byte[] token){
+//
+// return null;
+// }
+
+ public synchronized void newSubToken(Subject sub,byte[] token){
+ subjectMap.put(getHash(token), sub);
+ tokenPosition++;
+ logger_.fine("subjectMap increased to size: "+tokenPosition);
+// if (tokenPosition < 100) {
+// tokenHashArray[tokenPosition]=getHash(token);
+// subjectArray[tokenPosition]=sub;
+// }else{
+// tokenPosition=0;
+// tokenHashArray[tokenPosition]=getHash(token);
+// subjectArray[tokenPosition]=sub;
+// }
+ }
+
+ public synchronized void newServTicket(String service,byte[] ticket){
+ ticketMap.put(service,ticket);
+ servicePosition++;
+ logger_.fine("ticketMap increased to size: "+servicePosition);
+ }
+
+ static String getHash(byte[] array) {
+
+ MessageDigest md5;
+ byte[] digest = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+// byte[] digest = null;
+ try {
+ md5 = MessageDigest.getInstance("MD5");
+ md5.update(array);
+ digest = md5.digest();
+ } catch (NoSuchAlgorithmException e) {
+ System.err.println("Couldn't find MD5 algorithm");
+ }
+ return new String(digest);
+
+ }
+
+}
- [idok-commit] idok commit r379 - trunk/java/ch/idok/common/util, AFS account Florian Huebner, 07/29/2009
Archive powered by MHonArc 2.6.19.