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;
23 import gr.ebs.gss.server.domain.dto.UserDTO;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.bradmcevoy.http.Auth;
29 import com.bradmcevoy.http.CopyableResource;
30 import com.bradmcevoy.http.DigestResource;
31 import com.bradmcevoy.http.HttpManager;
32 import com.bradmcevoy.http.LockInfo;
33 import com.bradmcevoy.http.LockResult;
34 import com.bradmcevoy.http.LockTimeout;
35 import com.bradmcevoy.http.LockToken;
36 import com.bradmcevoy.http.LockableResource;
37 import com.bradmcevoy.http.MoveableResource;
38 import com.bradmcevoy.http.Request;
39 import com.bradmcevoy.http.Resource;
40 import com.bradmcevoy.http.Request.Method;
41 import com.bradmcevoy.http.exceptions.NotAuthorizedException;
42 import com.bradmcevoy.http.http11.auth.DigestResponse;
49 public abstract class GssResource implements Resource, MoveableResource, CopyableResource, LockableResource, DigestResource {
50 private static final Logger log = LoggerFactory.getLogger(GssResource.class);
52 GSSResourceFactory factory;
59 public GssResource(String host, GSSResourceFactory factory, Object resource) {
62 this.resource=resource;
66 public Object authenticate(String user, String password) {
67 return factory.getSecurityManager().authenticate(user, password);
70 public Object authenticate( DigestResponse digestRequest ) {
71 return factory.getSecurityManager().authenticate(digestRequest);
75 public boolean isDigestAllowed() {
82 public boolean authorise(Request request, Method method, Auth auth) {
83 return factory.getSecurityManager().authorise(request, method, auth, this);
86 public String getRealm() {
87 return factory.getRealm(this.host);
90 public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException {
91 return factory.getLockManager().lock(timeout, lockInfo, this);
94 public LockResult refreshLock(String token) throws NotAuthorizedException {
95 return factory.getLockManager().refresh(token, this);
98 public void unlock(String tokenId) throws NotAuthorizedException {
99 factory.getLockManager().unlock(tokenId, this);
102 public LockToken getCurrentLock() {
103 if( factory.getLockManager() != null ) {
104 return factory.getLockManager().getCurrentToken( this );
106 log.warn("getCurrentLock called, but no lock manager: file: " + resource);
113 * Retrieve the currentUser.
115 * @return the currentUser
117 public UserDTO getCurrentUser() {
118 if(currentUser!=null)
120 if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
121 String username = HttpManager.request().getAuthorization().getUser();
122 //log.info("username is:"+username);
125 currentUser = factory.getService().getUserByUserName(username);
126 } catch (RpcException e) {
127 // TODO Auto-generated catch block
131 else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
132 //log.info(HttpManager.request().getAuthorization().getUser());
133 currentUser =(UserDTO) HttpManager.request().getAuthorization().getTag();//getService().getUserByUserName("past@ebs.gr");