2 * Copyright 2011 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.webdav.milton;
21 import gr.ebs.gss.client.exceptions.RpcException;
22 import gr.ebs.gss.server.domain.User;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.bradmcevoy.http.Auth;
28 import com.bradmcevoy.http.CopyableResource;
29 import com.bradmcevoy.http.DigestResource;
30 import com.bradmcevoy.http.HttpManager;
31 import com.bradmcevoy.http.LockInfo;
32 import com.bradmcevoy.http.LockResult;
33 import com.bradmcevoy.http.LockTimeout;
34 import com.bradmcevoy.http.LockToken;
35 import com.bradmcevoy.http.LockableResource;
36 import com.bradmcevoy.http.MoveableResource;
37 import com.bradmcevoy.http.Request;
38 import com.bradmcevoy.http.Resource;
39 import com.bradmcevoy.http.Request.Method;
40 import com.bradmcevoy.http.exceptions.NotAuthorizedException;
41 import com.bradmcevoy.http.http11.auth.DigestResponse;
48 public abstract class GssResource implements Resource, MoveableResource, CopyableResource, LockableResource, DigestResource {
49 private static final Logger log = LoggerFactory.getLogger(GssResource.class);
51 GSSResourceFactory factory;
58 public GssResource(String host, GSSResourceFactory factory, Object resource) {
61 this.resource=resource;
65 public Object authenticate(String user, String password) {
66 return factory.getSecurityManager().authenticate(user, password);
69 public Object authenticate( DigestResponse digestRequest ) {
70 return factory.getSecurityManager().authenticate(digestRequest);
74 public boolean isDigestAllowed() {
81 public boolean authorise(Request request, Method method, Auth auth) {
82 return factory.getSecurityManager().authorise(request, method, auth, this);
85 public String getRealm() {
86 return factory.getRealm(this.host);
89 public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException {
90 return factory.getLockManager().lock(timeout, lockInfo, this);
93 public LockResult refreshLock(String token) throws NotAuthorizedException {
94 return factory.getLockManager().refresh(token, this);
97 public void unlock(String tokenId) throws NotAuthorizedException {
98 factory.getLockManager().unlock(tokenId, this);
101 public LockToken getCurrentLock() {
102 if( factory.getLockManager() != null ) {
103 return factory.getLockManager().getCurrentToken( this );
105 log.warn("getCurrentLock called, but no lock manager: file: " + resource);
112 * Retrieve the currentUser.
114 * @return the currentUser
116 public User getCurrentUser() {
117 if(currentUser!=null)
119 if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
120 String username = HttpManager.request().getAuthorization().getUser();
121 //log.info("username is:"+username);
124 currentUser = factory.getService().getUserByUserName(username);
125 } catch (RpcException e) {
126 // TODO Auto-generated catch block
130 else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
131 //log.info(HttpManager.request().getAuthorization().getUser());
132 currentUser =(User) HttpManager.request().getAuthorization().getTag();//getService().getUserByUserName("past@ebs.gr");