This project has retired. For details please refer to its
Attic page.
RepositoryMap xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.fileshare;
2021import java.util.Collection;
22import java.util.HashMap;
23import java.util.Map;
2425import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
26import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
27import org.apache.chemistry.opencmis.commons.server.CallContext;
2829/**30 * Repository map.31 */32publicclassRepositoryMap {
3334privatefinal Map<String, FileShareRepository> map;
35privatefinal Map<String, String> logins;
3637publicRepositoryMap() {
38 map = new HashMap<String, FileShareRepository>();
39 logins = new HashMap<String, String>();
40 }
4142/**43 * Adds a repository object.44 */45publicvoid addRepository(FileShareRepository fsr) {
46if ((fsr == null) || (fsr.getRepositoryId() == null)) {
47return;
48 }
4950 map.put(fsr.getRepositoryId(), fsr);
51 }
5253/**54 * Gets a repository object by id.55 */56publicFileShareRepository getRepository(String repositoryId) {
57// get repository object58FileShareRepository result = map.get(repositoryId);
59if (result == null) {
60thrownew CmisObjectNotFoundException("Unknown repository '" + repositoryId + "'!");
61 }
6263return result;
64 }
6566/**67 * Takes user and password from the CallContext and checks them.68 */69publicvoid authenticate(CallContext context) {
70// check user and password first71if (!authenticate(context.getUsername(), context.getPassword())) {
72thrownew CmisPermissionDeniedException();
73 }
74 }
7576/**77 * Returns all repository objects.78 */79public Collection<FileShareRepository> getRepositories() {
80return map.values();
81 }
8283/**84 * Adds a login.85 */86publicvoid addLogin(String username, String password) {
87if ((username == null) || (password == null)) {
88return;
89 }
9091 logins.put(username.trim(), password);
92 }
9394/**95 * Authenticates a user against the configured logins.96 */97privateboolean authenticate(String username, String password) {
98 String pwd = logins.get(username);
99if (pwd == null) {
100return false;
101 }
102103return pwd.equals(password);
104 }
105 }