1 18 19 package org.visualcontent.authentication.jlibrarylistener; 20 21 22 import javax.jcr.Session; 23 24 import org.eclipse.ui.IViewPart; 25 import org.eclipse.ui.PlatformUI; 26 import org.jlibrary.client.ui.repository.views.RepositoryView; 27 import org.jlibrary.core.entities.Repository; 28 import org.jlibrary.core.jcr.RepositoryManager; 29 import org.jlibrary.core.jcr.SessionManager; 30 import org.visualcontent.extensionpoints.RepositoryThrowable; 31 import org.visualcontent.extensionpoints.VCRepository; 32 import org.visualcontent.extensionpoints.VCSession; 33 34 public class SimpleAuthenticationService implements VCSession,VCRepository { 35 private static final String VALID_SESSION_ID = SimplecredentialsPlugin.getDefault().getBundle().getSymbolicName(); 37 private static final String JLIBRARY_VIEW_ID = "org.jlibrary.client.ui.repository.views.repositoryView"; 38 private Session session = null; 39 private javax.jcr.Repository repository=null; 40 41 private void setSession(org.jlibrary.core.entities.Repository repositoryInstance) { 42 org.jlibrary.core.entities.Ticket ticket = repositoryInstance.getTicket(); 43 SessionManager sessionManager = SessionManager.getInstance(); 44 this.session=sessionManager.getSession(ticket); 45 } 46 private void setRepository(org.jlibrary.core.entities.Repository repositoryInstance) { 47 org.jlibrary.core.entities.Ticket ticket = repositoryInstance.getTicket(); 48 RepositoryManager repositoryManager = RepositoryManager.getInstance(); 49 this.repository=repositoryManager.getRepository(ticket); 50 } 51 52 public void shutdownRepository() { 53 } 54 55 public void logout() { 56 59 } 60 61 66 public Session login(VCRepository repository) { 67 IViewPart jLibraryRepoBrowserView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(JLIBRARY_VIEW_ID); 68 RepositoryView jLibraryRepoBrowser = (RepositoryView) jLibraryRepoBrowserView; 69 if (jLibraryRepoBrowserView!=null) { 70 Repository jLibraryRepo = jLibraryRepoBrowser.getCurrentRepository(); 71 if (jLibraryRepo!=null){ 72 setSession(jLibraryRepo); 73 setRepository(jLibraryRepo); 74 } else { 75 SimplecredentialsPlugin.getDefault().showError("Please choose a jLibrary repository to login.",null); 76 } 77 } else { 78 SimplecredentialsPlugin.getDefault().showError("Please choose a jLibrary repository to login.",null); 79 } 80 return this.session; 81 } 82 public void releaseRepository() throws RepositoryThrowable { 83 } 84 public String [] getValidSessions() { 85 return new String []{VALID_SESSION_ID}; 86 } 87 public javax.jcr.Repository getRepository() throws RepositoryThrowable { 88 return this.repository; 89 } 90 91 92 public VCSession getCurrentVCSession() { 93 97 return this; 98 } 99 } 100 | Popular Tags |