KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > authentication > jlibrarylistener > SimpleAuthenticationService


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 // in this case: "org.visualcontent.authentication.jlibrarylistener.SimpleAuthenticationService"
36
private static final String JavaDoc VALID_SESSION_ID = SimplecredentialsPlugin.getDefault().getBundle().getSymbolicName();
37     private static final String JavaDoc 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         /**
57          * Don't log out the jLibrary session.
58          */

59     }
60
61     /* (non-Javadoc)
62      * @see org.visualcontent.extensionpoints.VCSession#login(org.visualcontent.extensionpoints.VCRepository)
63      * The parameter is not needed in this case because only the jLibrary Repository
64      * is usable by this plugin.
65      */

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 JavaDoc[] getValidSessions() {
85         return new String JavaDoc[]{VALID_SESSION_ID};
86     }
87     public javax.jcr.Repository getRepository() throws RepositoryThrowable {
88         return this.repository;
89     }
90
91     
92     public VCSession getCurrentVCSession() {
93         /*
94          * This is a VCRepository and a VCSession implementation. This is why
95          * this VCRepository can return the current instance as a VCSession.
96          */

97         return this;
98     }
99 }
100
Popular Tags