1 18 package org.visualcontent.authentication.simplecredentials; 19 20 21 import javax.jcr.LoginException; 22 import javax.jcr.RepositoryException; 23 import javax.jcr.Session; 24 import javax.jcr.SimpleCredentials; 25 26 import org.eclipse.jface.preference.IPreferenceStore; 27 import org.visualcontent.authentication.simplecredentials.preferences.PreferenceConstants; 28 import org.visualcontent.extensionpoints.RepositoryThrowable; 29 import org.visualcontent.extensionpoints.SessionThrowable; 30 import org.visualcontent.extensionpoints.VCRepository; 31 import org.visualcontent.extensionpoints.VCSession; 32 33 public class SimpleAuthenticationService implements VCSession { 34 VCRepository repositoryConnector = null; 35 Session session = null; 36 37 public SimpleAuthenticationService() throws LoginException, RepositoryException, SessionThrowable { 38 39 } 40 41 public Session login(VCRepository repository) throws SessionThrowable, RepositoryThrowable { 42 Session session = null; 43 IPreferenceStore prefStore = SimplecredentialsPlugin.getDefault().getPreferenceStore(); 44 String repAuthConfig = prefStore.getString(PreferenceConstants.P_REP_AUTH_CONFIG); 45 System.setProperty("java.security.auth.login.config", repAuthConfig); 46 String userName = prefStore.getString(PreferenceConstants.P_REP_USER_NAME); 47 String password = prefStore.getString(PreferenceConstants.P_REP_PASSWORD); 48 String workspace = prefStore.getString(PreferenceConstants.P_REP_WORKSPACE); 49 if ("".equals(workspace)){ 50 workspace=null; } 52 try { 53 session = repository.getRepository().login(new SimpleCredentials(userName, password.toCharArray()),workspace); 54 } catch (LoginException e) { 55 SimplecredentialsPlugin.getDefault().showError("It was not possible to login. Please check the credentials.",e); 56 repository.releaseRepository(); 57 } catch (RepositoryException e) { 58 SimplecredentialsPlugin.getDefault().showError("It was not possible to login. Please check the credentials.",e); 59 repository.releaseRepository(); 60 } catch (RepositoryThrowable e) { 61 SimplecredentialsPlugin.getDefault().showError("It was not possible to login. Please check the credentials.",e); 62 repository.releaseRepository(); 63 } 64 return session; 65 } 66 67 public void shutdownRepository() { 68 if (this.repositoryConnector!=null){ 69 try { 70 this.repositoryConnector.releaseRepository(); 71 } catch (RepositoryThrowable e) { 72 SimplecredentialsPlugin.getDefault().showError("Could not release the repository.",e); 73 } 74 } 75 } 76 77 public void logout() { 78 if (this.session!=null){ 79 session.logout(); 80 } 81 } 82 83 } 107 | Popular Tags |