1 6 7 package org.exoplatform.services.jcr.impl.core; 8 9 import java.util.HashMap ; 10 11 import javax.jcr.Credentials; 12 import javax.jcr.LoginException; 13 import javax.jcr.NoSuchWorkspaceException; 14 import javax.jcr.Repository; 15 import javax.jcr.RepositoryException; 16 import javax.jcr.Ticket; 17 18 import org.apache.commons.logging.Log; 19 import org.exoplatform.services.jcr.storage.RepositoryManager; 20 import org.exoplatform.services.jcr.storage.WorkspaceContainer; 21 import org.exoplatform.services.log.LogUtil; 22 import org.exoplatform.services.organization.OrganizationService; 23 24 30 public class RepositoryImpl implements Repository { 31 32 private HashMap workspaceContainers; 33 34 private RepositoryManager repositoryManager; 35 36 private String defaultWorkspaceName; 37 38 protected Log log; 39 40 private String name; 41 42 private OrganizationService organizationService; 43 44 public RepositoryImpl(String name, OrganizationService organizationService) 45 throws RepositoryException { 46 this.name = name; 47 this.organizationService = organizationService; 48 log = LogUtil.getLog("org.exoplatform.services.jcr"); 49 } 50 51 73 public Ticket login(Credentials credentials, String workspaceName) 74 throws LoginException, NoSuchWorkspaceException { 75 log.debug("login"); 76 if (workspaceName == null) { 77 if (defaultWorkspaceName == null) 78 throw new NoSuchWorkspaceException( 79 "Both workspace and default-workspace name are null! "); 80 else 81 workspaceName = defaultWorkspaceName; 82 } 83 84 if (credentials != null) { 85 if (workspaceContainers.get(workspaceName) == null) 86 throw new NoSuchWorkspaceException("Workspace '" + workspaceName 87 + "' not found "); 88 89 boolean success = false; 90 try { 91 success = organizationService.authenticate(credentials 92 .getUserId(), new String (credentials.getPassword())); 93 } catch (Exception e1) { 94 throw new LoginException("Can not authorize the user : " 95 + credentials.getUserId(), e1); 96 } 97 if (!success) 98 throw new LoginException("Can not authorize the user : " 99 + credentials.getUserId()); 100 } 101 try { 102 return new TicketImpl(this, credentials, workspaceName); 103 } catch (RepositoryException e) { 104 throw new LoginException("Unexpected problems with Ticket creation.", e); 105 } 106 } 107 108 public WorkspaceContainer getContainer(String workspaceName) 109 throws RepositoryException { 110 WorkspaceContainer container = (WorkspaceContainer) workspaceContainers 111 .get(workspaceName); 112 if (container == null) 113 throw new RepositoryException("No container found for workspace '" 114 + workspaceName + "'!"); 115 return container; 116 } 117 118 public RepositoryManager getRepositoryManager() { 119 return repositoryManager; 120 } 121 122 public void setRepositoryManager(RepositoryManager repositoryManager) { 123 this.repositoryManager = repositoryManager; 124 } 125 126 public void setWorkspaceContainers(HashMap containers) { 127 this.workspaceContainers = containers; 128 } 129 130 public void setDefaultWorkspaceName(String name) { 131 this.defaultWorkspaceName = name; 132 } 133 134 public String getName() { 135 return name; 136 } 137 } | Popular Tags |