summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/server/ServerHandler.java
blob: 1671b893095a592f18d998c678d8fd95b85b5c8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
package server;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import models.Configuration;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;

import server.generated.Image;
import server.generated.Lecture;
import server.generated.Person;
import server.generated.Server;
import server.generated.User;

import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
import org.openslx.imagemaster.thrift.iface.InvalidTokenException;
import thrift.MasterThriftConnection;
import thrift.SessionData;

import sql.SQL;
//import util.XMLCreator;

public class ServerHandler implements Server.Iface 
{
	
	private static Logger log = Logger.getLogger(ServerHandler.class);
	static SQL sql = new SQL();
	Client client = null;

	 
	public void setTokenForSession(String token)
	{
		SessionData.session.setAuthToken(token);
	}
	
	
	public boolean checkSession(String authToken) throws InvalidTokenException
	{
		//cached proof. if session is valid, return
		if(SessionData.session.getAuthToken().equals(authToken))
		{
			return true;
		}
		
		//else, set session to current token and check against masterserver
		//TODO change calls from functions
		SessionData.session.setAuthToken(authToken);
		
		return authenticated();
	}
	
	
	public boolean authenticated() throws InvalidTokenException
	{
			//start initial authentication with the masterserver
			MasterThriftConnection thrift = new MasterThriftConnection();
			client = thrift.getMasterThriftConnection();
			try {
				if(client.getUserFromToken(SessionData.session.getAuthToken()) != null)
				{
					return true; 
				}
			} catch (TException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			log.info("User not authenticated.");
			
		return false;
	}


	

	@Override
	public User getFtpUser() throws TException 
	{
		if(authenticated())
		{
			log.info("returning FTPUser...");
			User user = new User();
			user.setUserName(UUID.randomUUID().toString().substring(0, 8));
			user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString()
					.substring(0, 8)));
			if (Configuration.config.getAbsolute_path().endsWith("/")) {
				user.setPath(Configuration.config.getAbsolute_path());
			} else {
				user.setPath(Configuration.config.getAbsolute_path() + "/");
			}
	
			// check if folder temp and folder prod exist
			if (folderTempExists() == true && folderProdExists() == true) {
				sql.writeFTPUser(user.getUserName(), user.getPassword());
				return user;
			} else {
				log.info("Error: returning null user");
				return null;
			}
		}
		return null;
		
	}

	
	public boolean folderTempExists() 
	{
		// check if folder temp exists, otherwise create it
		Path path = null;
		if (Configuration.config.getAbsolute_path().endsWith("/")) {
			path = Paths.get(Configuration.config.getAbsolute_path() + "temp");
		} else {
			path = Paths.get(Configuration.config.getAbsolute_path() + "/temp");
		}

		if (Files.exists(path) == true) {
			log.info("folder '" + path	+ "' exists, no further action");
			return true;
		} else {
			// create directory and set permissions
			boolean success = (new File(path + "")).mkdirs();

			if (!success) {
				log.info("failed to create folder '" + path
						+ "'");
				return false;
			} else {
				// set permissions
				try {
					Runtime.getRuntime().exec("chmod 777 " + path);
				} catch (IOException e) {
					e.printStackTrace();
				}
				log.info("folder '" + path	+ "' successfully created");
				return true;
			}
		}

	}// end folderTempExists()
	

	public boolean folderProdExists() {
		// check if folder temp exists, otherwise create it
		Path path = null;
		if (Configuration.config.getAbsolute_path().endsWith("/")) {
			path = Paths.get(Configuration.config.getAbsolute_path() + "prod");
		} else {
			path = Paths.get(Configuration.config.getAbsolute_path() + "/prod");
		}

		if (Files.exists(path) == true) {
			log.info("folder '" + path	+ "' exists, no further action");
			return true;
		} else {
			// create directory and set permissions
			boolean success = (new File(path + "")).mkdirs();

			if (!success) {
				log.info("failed to create folder '" + path
						+ "'");
				return false;
			} else {
				// set permissions
				try {
					Runtime.getRuntime().exec("chmod 777 " + path);
				} catch (IOException e) {
					e.printStackTrace();
				}
				log.info("folder '" + path
						+ "' successfully created");
				return true;
			}
		}

	}// end folderProdExists()

	
	public String getEncodedSha1Sum(String key) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA1");
			md.update(key.getBytes());
			log.info("successfully returned EncodedSha1Sum");
			return new BigInteger(1, md.digest()).toString(16);
		} catch (NoSuchAlgorithmException e) {
			// handle error case to taste
		}
		return null;
	}

	@Override
	public long DeleteFtpUser(String user) throws TException 
	{
		if(authenticated())
		{
			return sql.DeleteUser(user);
		}
		return -1;
	}

	@Override
	public String getPathOfImage(String image_id, String version) throws TException 
	{
		if(authenticated())
		{
			log.info("successfully returned PathOfImage: " + sql.getPathOfImage(image_id, version));
			return sql.getPathOfImage(image_id, version);
		}
		return null;
	}

	
	@Override
	public String setInstitution(String university) throws InvalidTokenException 
	{
		if(authenticated())
		{
		return sql.setInstitution(university);
		}
		return null;
	}

	@Override
	public boolean writeVLdata(String imagename, String desc, String login,
			String firstname, String lastname, String university, String Mail,
			String Tel, String Fak, boolean license, boolean internet,
			long ram, long cpu, String imagePath, boolean isTemplate,
			long filesize, long shareMode, String os, String uid) throws TException 
	{
		
		if(authenticated())
		{
			String mode = null;
	
			if (shareMode == 0) {
				mode = "only_local";
			} else {
				mode = "to_be_published";
			}
	
			// String pk_institution = sql.setInstitution(university);
			// String pk_person = sql.setPerson(login, lastname, firstname, Mail,
			// new Date(), pk_institution);
	
			// OS impl Select and write
			// ACHTUNG: Anzahl der Leerzeichen muss eingehalten werden: 'Windows 7
			// 32 bit"
			String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)), os
					.substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
					.replace(" ", ""));
	
			// sql.setImageData(pk_person, license, internet, cpu, ram,
			// imagename,desc, imagePath, filesize,mode,pk_os);
	
			sql.setImageData(login, license, internet, cpu, ram, imagename, desc,
					imagePath, filesize, mode, pk_os, uid);
	
			log.info("written VLdata");
			return true;
		}
		return false;
	}

	
	@Override
	public List<Image> getImageListPermissionWrite(String userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getImageListPermissionWrite(userID);
		}
		return null;
	}

	
	@Override
	public List<Image> getImageListPermissionRead(String userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getImageListPermissionRead(userID);
		}
		return null;
	}

	
	@Override
	public List<Image> getImageListPermissionLink(String userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getImageListPermissionLink(userID);
		}
		return null;
	}
	
	
	@Override
	public List<Image> getImageListPermissionAdmin(String userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getImageListPermissionAdmin(userID);
		}
		return null;
	}
	
	@Override
	public List<Image> getImageListAllTemplates() throws TException 
	{
		if(authenticated())
		{
			return sql.getImageListAllTemplates();
		}
		return null;
	}
	

	@Override
	public List<String> getAllOS() throws TException 
	{
		if(authenticated())
		{
			return sql.getAllOS();
		}
		return null;
	}

	@Override
	public Map<String, String> getPersonData(String Vorname, String Nachname) throws TException 
	{
		if(authenticated())
		{
			return sql.getPersonData(Vorname, Nachname);
		}
		return null;
	}

	public void setPerson(String login, String lastname, String firstname,String mail, String Institution) throws InvalidTokenException 
	{
		if(authenticated())
		{
			sql.setPerson(login, lastname, firstname, mail, new Date(), Institution);
		}
	}

	@Override
	public boolean writeLecturedata(String name, String shortdesc, String desc,
			String startDate, String endDate, boolean isActive,
			String imageID, String login, String firstname, String lastname,
			String university, String Mail, String Tel, String Fak, String lectureID)
			throws TException 
	{
		if(authenticated())
		{
		
			//String pk_image = imageID;
			Map<String, String> map = new HashMap<String, String>();
			int imageversion = 0;
			String pk_institution = sql.setInstitution(university);
			String pk_person = sql.setPerson(login, lastname, firstname, Mail,
					new Date(), pk_institution);
	
			map = sql.getImageIDandVersion(imageID);
	
			//pk_image = map.get("GUID");
			imageversion = Integer.parseInt(map.get("version"));
			
			sql.setLectureData(pk_person, imageID, imageversion, name, desc,
					shortdesc, startDate, endDate, isActive, lectureID);
		}
			return false;
		
	}
	

	@Override
	public boolean startFileCopy(String filename) throws TException 
	{
		if(authenticated())
		{
			// copy file from folder temp to folder prod
			String file = Configuration.config.getAbsolute_path() + "temp/"
					+ filename;
			File tmpFile = new File(file);
	
			log.info("Trying to move file to '/srv/openslx/nfs/prod/"
					+ tmpFile.getName() + "'");
			try {
				FileUtils.moveFile(tmpFile,
						new File(Configuration.config.getAbsolute_path() + "prod/"
								+ filename));
				// int ret = sql.UpdateImagePath(filename);
				if (sql.UpdateImagePath(filename) == 0) {
					log.info("file moved and database updated.");
				}
	
			} catch (IOException e) {
				log.info("Failed to move file.");
				e.printStackTrace();
			}
		}
		return true;
	}

	@Override
	public Map<String, String> getImageData(String imageid, String imageversion) throws TException 
	{
		if(authenticated())
		{
			//log.info("returning ImageData: "+ sql.getImageData(imageid, imageversion).size() + "items.");
			return sql.getImageData(imageid, imageversion);
		}
		return null;
	}

	@Override
	public boolean updateImageData(String name, String newName, String desc,
			String image_path, boolean license, boolean internet, long ram,
			long cpu, String id, String version, boolean isTemplate,
			long filesize, long shareMode, String os) throws TException 
	{
		if(authenticated())
		{
			String mode = null;
	
			if (shareMode == 0) {
				mode = "only_local";
			} else {
				mode = "to_be_published";
			}
			String pk_os = sql.getOSpk(os.substring(0, nthIndexOf(os, " ", 2)), os
					.substring(nthIndexOf(os, " ", 2), os.lastIndexOf(" "))
					.replace(" ", ""));
			sql.UpdateImageData(name, newName, desc, image_path, license, internet,
					cpu, ram, id, version, isTemplate, filesize, mode, pk_os);
		}
		return false;
	}

	@Override
	public List<Lecture> getLectureList() throws TException 
	{
		if(authenticated())
		{
			//log.info("returning LectureList");
			return sql.getLectureList();
		}
		return null;
	}

	@Override
	public List<Lecture> getLectureListPermissionRead(String userID) throws InvalidTokenException 
	{
		if(authenticated())
		{
			//log.info("returning LectureListRead");
			return sql.getLectureListPermissionRead(userID);
		}
		return null;
	}// end getLectureListPermissionRead

	
	@Override
	public List<Lecture> getLectureListPermissionWrite(String userID) throws InvalidTokenException 
	{
		if(authenticated())
		{
			//log.info("returning LectureListWrite");
			return sql.getLectureListPermissionWrite(userID);
		}
		return null;
	}// end getLectureListPermissionRead

	@Override
	public List<Lecture> getLectureListPermissionAdmin(String userID) throws InvalidTokenException 
	{
		if(authenticated())
		{
			//log.info("returning LectureListAdmin");
			return sql.getLectureListPermissionAdmin(userID);
		}
		return null;
	}// end getLectureListPermissionRead

	
	@Override
	public boolean updateLecturedata(String name, String newName,
			String shortdesc, String desc, String startDate, String endDate,
			boolean isActive, String imageid, String imageversion, String user,
			String firstname, String lastname, String university, String Mail,
			String Tel, String Fak, String id) throws TException 
	{
		if(authenticated())
		{
			Map<String, String> map = new HashMap<String, String>();
			map = sql.getDeleteXMLData(id);
			sql.updateLectureData(imageid, imageversion, lastname, newName, desc,
					shortdesc, startDate, endDate, isActive, id);
	
			String path = Configuration.config.getAbsolute_path() + "prod/"
					+ map.get("date").substring(0, map.get("date").length() - 2)
					+ "_" + university + "_" + user + "_" + map.get("name")
					+ ".xml";
			File tmpFile = new File(path);
			try {
				FileUtils.forceDelete(tmpFile);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		return false;
	}

	
	@Override
	public boolean deleteImageServer(String imageid, String imageversion) throws TException 
	{
		if(authenticated())
		{
			String stringFile = sql.getFile(imageid, imageversion);
			log.info("File to Delete: " + stringFile);
	
			File tmpFile = new File(Configuration.config.getAbsolute_path()
					+ stringFile);
	
			try {
				// File wird von Server gelöscht
				FileUtils.forceDelete(tmpFile);
				return true;
	
			} catch (IOException e) {
				log.info("Failed to execute deleteImageServer.");
				e.printStackTrace();
	
			}
		}
		return false;
	}

	
	@Override
	public boolean deleteImageData(String id, String version) throws TException 
	{
		boolean success=false;
		
		if(authenticated())
		{
			if(sql.deleteImage(id, version)==true)
			{
				success=true;
				log.info("Image '"+id+"' and permissions successfully deleted.");
			}
		}
		return success;
	}

	@Override
	public boolean connectedToLecture(String id, String version) throws TException 
	{
		if(authenticated())
		{
			return sql.connectedToLecture(id, version);
		}
		return true;
	}

	public boolean deleteLecture(String id, String hs, String user) throws InvalidTokenException 
	{
		boolean success = false;
		
		if(authenticated())
		{
			Map<String, String> map = new HashMap<String, String>();
			map = sql.getDeleteXMLData(id);
			try {
	
				String path = Configuration.config.getAbsolute_path()
						+ "prod/"
						+ map.get("date")
								.substring(0, map.get("date").length() - 2) + "_"
						+ hs + "_" + user + "_" + map.get("name") + ".xml";
				File xmlFile = new File(path);
				FileUtils.forceDelete(xmlFile);
			} catch (IOException e) {
				log.info("Failed to execute deleteLecture.");
				e.printStackTrace();
			}
			
			if(sql.deleteLecture(id) == true){
				success = true;
				log.info("Lecture '"+id+"' and permissions successfully deleted.");
			}
		}
		return success;
	}

	@Override
	public List<String> getAllUniversities() throws TException 
	{
		if(authenticated())
		{
			return sql.getAllUniversities();
		}
		return null;
	}

	@Override
	public Map<String, String> getLectureData(String lectureid) throws TException 
	{
		if(authenticated())
		{
			//log.info("returning LectureData");
			return sql.getLectureData(lectureid);
		}
		return null;
	}

	public static int nthIndexOf(final String string, final String token,final int index) 
	{
		int j = 0;

		for (int i = 0; i < index; i++) 
		{
			j = string.indexOf(token, j + 1);
			if (j == -1)
				break;
		}

		return j;
	}

	@Override
	public boolean checkUser(String username) throws TException 
	{
		if(authenticated())
		{
			return sql.checkUser(username);
		}
		return false;

	}

	@Override
	public boolean createUser(String loginName, String lastName,String firstName, String mail, String university) throws TException 
	{
		if(authenticated())
		{
			String pk_institution = sql.setInstitution(university);
			String pk_person = sql.setPerson(loginName, lastName, firstName, mail, new Date(), pk_institution);
			return true;
		}
		return false;
	}

	@Override
	public boolean writeImageRights(String imageID, String username,
			String lastName, String firstName, String mail, String university,
			String role) throws TException 
	{
		if(authenticated())
		{
			String pk_image = null;
			Map<String, String> map = new HashMap<String, String>();
			int imageversion = 0;
			String pk_institution = sql.setInstitution(university);
			String pk_person = sql.setPerson(username, lastName, firstName, mail,
					new Date(), pk_institution);
	
			map = sql.getImageIDandVersion(imageID);
	
	
			pk_image = map.get("GUID");
			imageversion = Integer.parseInt(map.get("version"));
	
			if (role.equals("Dozent")) {
				int read = 1;
				int write = 1;
				// int changePermission=0;
				int admin = 1;
				int linkallowed = 1;
				int roleID = sql.getRoleID(role);
	
				sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
						linkallowed);
	
			} else if (role.equals("Admin")) {
				int read = 1;
				int write = 1;
				// int changePermission=1;
				int admin = 1;
				int linkallowed = 1;
				int roleID = sql.getRoleID(role);
	
				sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
						linkallowed);
			} else {
				int read = 1;
				int write = 0;
				// int changePermission=0;
				int admin = 0;
				int linkallowed = 0;
				int roleID = sql.getRoleID(role);
	
				sql.setImageRights(pk_person, pk_image, roleID, read, write, admin,
						linkallowed);
			}
	
			log.info("Written image rights");
			return true;
		}
		return false;
	}

	@Override
	public boolean writeLectureRights(String lectureID, String username,
			String lastName, String firstName, String mail, String university,
			String role) throws TException 
	{
		if(authenticated())
		{
			//String pk_lecture = null;
	
			String pk_institution = sql.setInstitution(university);
			String pk_person = sql.setPerson(username, lastName, firstName, mail,
					new Date(), pk_institution);
			//pk_lecture = sql.getLectureID(lectureID);
	
			if (role.equals("Dozent")) {
				int read = 1;
				int write = 1;
				// int changePermission=0;
				int admin = 1;
				int roleID = sql.getRoleID(role);
	
				sql.setLectureRights(pk_person, lectureID, roleID, read, write,
						admin);
	
			} else if (role.equals("Admin")) {
				int read = 1;
				int write = 1;
				// int changePermission=1;
				int admin = 1;
				int roleID = sql.getRoleID(role);
	
				sql.setLectureRights(pk_person, lectureID, roleID, read, write,
						admin);
			} else {
				int read = 0;
				int write = 0;
				// int changePermission=0;
				int admin = 0;
				int roleID = sql.getRoleID(role);
	
				sql.setLectureRights(pk_person, lectureID, roleID, read, write,
						admin);
			}
	
			return true;
		}
		return false;
	}

	@Override
	public List<Person> getAllOtherSatelliteUsers(List<String> userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getAllOtherSatelliteUsers(userID);
			// return null;
		}
		return null;
	}

	//set permissions for users which are !=userID
	public boolean writeAdditionalImageRights(String imageID, String userID,
			boolean isRead, boolean isWrite, boolean isLinkAllowed,
			boolean isAdmin) throws InvalidTokenException 
	{
		boolean success = false;
		if(authenticated())
		{

			Map<String, String> map = new HashMap<String, String>();
			map = sql.getImageIDandVersion(imageID);
			//String imageID = map.get("GUID");
	
			sql.writeAdditionalImageRights(imageID, userID, isRead, isWrite,
					isLinkAllowed, isAdmin);
			log.info("Written additional image rights for "	+ userID);
		}
		return success;
	}

	
	public boolean writeAdditionalLectureRights(String lectureID,
			String userID, boolean isRead, boolean isWrite, boolean isAdmin) throws InvalidTokenException 
	{
		if(authenticated())
		{
			Map<String, String> map = new HashMap<String, String>();
			//String lectureID = sql.getLectureID(lectureID);
	
			sql.writeAdditionalLectureRights(lectureID, userID, isRead, isWrite,
					isAdmin);
			log.info("Written additional lecture rights for "+ userID);
	
			return true;
		}
		return false;
	}

	@Override
	public List<Person> getPermissionForUserAndImage(String userID,
			String imageID) throws TException 
	{
		if(authenticated())
		{
			return sql.getPermissionForUserAndImage(userID, imageID);
		}
		return null;
	}

	public List<Person> getPermissionForUserAndLecture(String userID,String lectureID) throws InvalidTokenException 
	{
		if(authenticated())
		{
			return sql.getPermissionForUserAndLecture(userID, lectureID);
		}
		return null;
	}

	@Override
	public void deleteAllAdditionalImagePermissions(String imageID,String userID) throws TException 
	{
		if(authenticated())
		{
			sql.deleteAllAdditionalImagePermissions(imageID, userID);
		}
		return;
	}

	@Override
	public void deleteAllAdditionalLecturePermissions(String lectureID,String userID) throws TException 
	{
		if(authenticated())
		{
			sql.deleteAllAdditionalLecturePermissions(lectureID, userID);
		}
		
		return;
	}

	@Override 
	public List<Image> getImageList(String userID) throws TException 
	{
		if(authenticated())
		{
			return sql.getImageList(userID);
		}
		return null;
	}

	@Override
	public List<String> getAdditionalImageContacts(String imageID) throws TException 
	{
		if(authenticated())
		{
			return sql.getAdditionalImageContacts(imageID);
		}
		return null;
	}

	@Override
	public String getOsNameForGuestOs(String guestOS) throws TException 
	{
		if(authenticated())
		{
			return sql.getOsNameForGuestOs(guestOS);
		}
		return null;
	}

	@Override

	public String createRandomUUID() throws TException 
	{
		if(authenticated())
		{
			return sql.createRandomUUID();
		}
		return null;
	}

	public Map<String, String> getItemOwner(String itemID) throws TException 
	{
		if(authenticated())
		{
			return sql.getItemOwner(itemID);
		}
		return null;

	}



	@Override
	public boolean userIsImageAdmin(String userID, String imageID)
			throws TException {
		
		if(authenticated())
		{
			return sql.userIsImageAdmin(userID,imageID);
		}
		return false;
		
	}



	@Override
	public boolean userIsLectureAdmin(String userID, String lectureID)
			throws TException {
		if(authenticated())
		{
			return sql.userIsLectureAdmin(userID,lectureID);
		}
		return false;
	}



}// end class