Statistics
| Revision:

gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / repository / localdb / VCSGisRepositoryLocaldb.java @ 3625

History | View | Annotate | Download (22.4 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program 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.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

    
23
package org.gvsig.vcsgis.lib.repository.localdb;
24

    
25
import java.time.LocalDateTime;
26
import java.util.HashMap;
27
import java.util.List;
28
import java.util.Map;
29
import java.util.zip.CRC32;
30
import javax.json.JsonObject;
31
import org.apache.commons.lang3.BooleanUtils;
32
import org.apache.commons.lang3.StringUtils;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataServerExplorerParameters;
36
import org.gvsig.fmap.dal.DatabaseWorkspaceManager;
37
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYID;
38
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION;
39
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_REPOSITORY;
40
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES;
41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.feature.FeatureType;
43
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
44
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
46
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
47
import org.gvsig.json.Json;
48
import org.gvsig.json.JsonObjectBuilder;
49
import org.gvsig.tools.ToolsLocator;
50
import static org.gvsig.tools.dataTypes.DataTypeUtils.toTimestamp;
51
import org.gvsig.tools.dispose.DisposeUtils;
52
import org.gvsig.tools.task.SimpleTaskStatus;
53
import org.gvsig.vcsgis.lib.VCSGisCodeGenerator;
54
import org.gvsig.vcsgis.lib.VCSGisEntity;
55
import org.gvsig.vcsgis.lib.VCSGisLocator;
56
import org.gvsig.vcsgis.lib.VCSGisManager;
57
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_AUTHENTICATION_EXPIRED;
58
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_INVALID_AUTHENTICATION_TOKEN;
59
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_INVALID_USERCODE;
60
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
61
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_USER_NOT_AUTHORIZED;
62
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
63
import org.gvsig.vcsgis.lib.VCSGisUser;
64
import org.gvsig.vcsgis.lib.VCSGisUtils;
65
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
66
import org.gvsig.vcsgis.lib.repository.localdb.requests.AbstractRequestLocaldb;
67
import org.gvsig.vcsgis.lib.repository.localdb.requests.AuthenticateRequestLocaldb;
68
import org.gvsig.vcsgis.lib.repository.localdb.requests.CheckoutRequestLocaldb;
69
import org.gvsig.vcsgis.lib.repository.localdb.requests.CommitRequestLocaldb;
70
import org.gvsig.vcsgis.lib.repository.localdb.requests.EntitiesRequestLocaldb;
71
import org.gvsig.vcsgis.lib.repository.localdb.requests.HistoryRequestLocaldb;
72
import org.gvsig.vcsgis.lib.repository.localdb.requests.RowCreateRequestLocaldb;
73
import org.gvsig.vcsgis.lib.repository.localdb.requests.RowDeleteRequestLocaldb;
74
import org.gvsig.vcsgis.lib.repository.localdb.requests.RowUpdateRequestLocaldb;
75
import org.gvsig.vcsgis.lib.repository.localdb.requests.TopologyPlansRequestLocaldb;
76
import org.gvsig.vcsgis.lib.repository.localdb.requests.UpdateRequestLocaldb;
77
import org.gvsig.vcsgis.lib.repository.localdb.requests.UsersRequestLocaldb;
78
import org.gvsig.vcsgis.lib.repository.localdb.tables.DataRepoTable;
79
import org.gvsig.vcsgis.lib.repository.localdb.tables.EntitiesRepoTable;
80
import org.gvsig.vcsgis.lib.repository.localdb.tables.HooksRepoTable;
81
import org.gvsig.vcsgis.lib.repository.localdb.tables.RevisionsRepoTable;
82
import org.gvsig.vcsgis.lib.repository.localdb.tables.ConfigRepoTable;
83
import org.gvsig.vcsgis.lib.repository.localdb.tables.ResourcesRepoTable;
84
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable;
85
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable;
86
import org.gvsig.vcsgis.lib.repository.requests.VCSGisAuthenticateRequest;
87
import org.gvsig.vcsgis.lib.repository.requests.VCSGisCheckoutRequest;
88
import org.gvsig.vcsgis.lib.repository.requests.VCSGisCommitRequest;
89
import org.gvsig.vcsgis.lib.repository.requests.VCSGisEntitiesRequest;
90
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRequest;
91
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowCreateRequest;
92
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowDeleteRequest;
93
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowUpdateRequest;
94
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUpdateRequest;
95
import org.slf4j.Logger;
96
import org.slf4j.LoggerFactory;
97
import org.gvsig.vcsgis.lib.repository.requests.VCSGisHistoryRequest;
98
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
99
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
100
import org.gvsig.vcsgis.lib.requests.AbstractRequest;
101

    
102
/**
103
 *
104
 * @author gvSIG Team
105
 */
106
@SuppressWarnings("UseSpecificCatch")
107
public class VCSGisRepositoryLocaldb implements VCSGisRepository {
108
    private static final Logger LOGGER = LoggerFactory.getLogger(VCSGisRepositoryLocaldb.class);
109

    
110
    
111
    public static int create(JDBCServerExplorerParameters serverParameters, VCSGisCodeGenerator codeGenerator, SimpleTaskStatus status) {
112
        if( status == null ) {
113
            status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("vcsgis init");
114
            status.add();
115
        }
116
        int r = 3;
117
        status.push();
118
        DataManager dataManager = DALLocator.getDataManager();
119
        JDBCServerExplorer server = null;
120
        try {
121
            server = (JDBCServerExplorer) dataManager.openServerExplorer(
122
                    serverParameters.getProviderName(),
123
                    serverParameters
124
            );
125
        } catch (Exception ex) {
126
            throw new VCSGisRuntimeException(VCSGisManager.ERR_INVALID_REPOSITORY, "Can't open server explorer.");
127
        }
128

    
129
        try {
130
            status.setTitle("vcsgis init");
131
            
132
            DatabaseWorkspaceManager databaseWorkspaceManager = dataManager.createDatabaseWorkspaceManager(serverParameters);
133
            
134
            if(!databaseWorkspaceManager.existsTable(TABLE_CONFIGURATION)){
135
                databaseWorkspaceManager.createTable(TABLE_CONFIGURATION);
136
            }
137
            if(!databaseWorkspaceManager.existsTable(TABLE_RESOURCES)){
138
                databaseWorkspaceManager.createTable(TABLE_RESOURCES);
139
            }
140
            if(!databaseWorkspaceManager.existsTable(TABLE_REPOSITORY)){
141
                databaseWorkspaceManager.createTable(TABLE_REPOSITORY);
142
                databaseWorkspaceManager.set(CONFIG_NAME_STORESREPOSITORYID, "VCSGIS");
143
            }
144
            databaseWorkspaceManager.connect();
145
            
146
            FeatureType[] tables = new FeatureType[] {
147
                ConfigRepoTable.featureType(),
148
                UsersRepoTable.featureType(),
149
                TopologyplanRepoTable.featureType(),
150
                EntitiesRepoTable.featureType(),
151
                RevisionsRepoTable.featureType(),
152
                DataRepoTable.featureType(),
153
                ResourcesRepoTable.featureType(),
154
                HooksRepoTable.featureType(),
155
            };
156
            r = 4;
157
            status.setRangeOfValues(0, tables.length);
158
            int step = 1;
159
            for (FeatureType table : tables) {
160
                status.message(table.getLabel());
161
                status.setCurValue(step++);
162
                r = 4+step;
163
                JDBCNewStoreParameters table_params = server.getAddParameters();
164
                table_params.setDefaultFeatureType(table.getEditable());
165
                String tableName = table.getTags().getString("ID");
166
                table_params.setTable(tableName);
167
                server.add(server.getProviderName(), table_params, false);
168
                
169
                JDBCStoreParameters openParams = server.get(tableName);
170
                databaseWorkspaceManager.writeStoresRepositoryEntry(tableName, openParams);
171
            }
172
            
173
            try {
174
                server.execute(VCSGisUtils.getSqlTemplate(serverParameters.getProviderName(), "createRepositoryIndex1"));
175
                server.execute(VCSGisUtils.getSqlTemplate(serverParameters.getProviderName(), "createRepositoryIndex2"));
176
            } catch (Exception ex) {
177
                LOGGER.warn("Can't create index in workspace", ex);
178
            }
179

    
180
            VCSGisRepositoryLocaldb repo = new VCSGisRepositoryLocaldb();
181
            repo.initialize(serverParameters, codeGenerator);
182
            DisposeUtils.disposeQuietly(repo);
183
            status.terminate();
184
        } catch(Exception ex) {
185
            status.abort();
186
            LOGGER.warn("Can't init repository.",ex);
187
            status.message(ex.getMessage());
188
            return r;
189
        } finally {
190
            status.pop();
191
        }
192
        return 0;
193
    }
194
        
195
    private JDBCServerExplorer server;
196
    private JDBCServerExplorerParameters serverParameters;
197
    private Map<String,FeatureStore> stores;
198
    private VCSGisCodeGenerator codeGenerator;
199
    private String code;
200
    private HooksRepoTable hooksTable;
201
    private boolean allowAssignTheRevisionDate;
202
//    private boolean authenticationRequired;
203
//    private boolean authorizationRequired;
204
    private String token;
205
    private String userCode;
206

    
207
    public VCSGisRepositoryLocaldb() {
208
        // For persistence
209
        this.codeGenerator = null;
210
        this.stores = null;
211
        this.server = null;
212
        this.serverParameters = null;
213
        this.code = null;
214
        this.allowAssignTheRevisionDate = false;
215
//        this.authenticationRequired = false;
216
//        this.authorizationRequired = false;
217
     }
218
    
219
    public VCSGisRepositoryLocaldb(JDBCServerExplorerParameters serverParameters, VCSGisCodeGenerator codeGenerator) {
220
        this.stores = null;
221
        this.codeGenerator = codeGenerator;
222
        this.serverParameters = serverParameters;
223
        DataManager dataManager = DALLocator.getDataManager();
224
        try {
225
            this.server = (JDBCServerExplorer) dataManager.openServerExplorer(
226
                    serverParameters.getProviderName(),
227
                    serverParameters
228
            );
229
        } catch (Exception ex) {
230
            throw new VCSGisRuntimeException(VCSGisManager.ERR_INVALID_REPOSITORY, "Can't open server explorer.");
231
        }
232

    
233
        ConfigRepoTable varsTable = new ConfigRepoTable();
234
        this.code = varsTable.get(this, "REPOSITORY_CODE");
235
        if (this.code == null){
236
            throw new VCSGisRuntimeException(VCSGisManager.ERR_INVALID_REPOSITORY, "The database can't have REPOSITORY_CODE variable.");
237
        }
238
//        this.authenticationRequired = BooleanUtils.toBoolean(varsTable.get(this, "AUTHENTICATION"));
239
//        this.authorizationRequired = BooleanUtils.toBoolean(varsTable.get(this, "AUTHORIZATION"));
240
        
241
        this.hooksTable = new HooksRepoTable();
242
        hooksTable.initHooks(this);
243
    }
244
    
245
    private void initialize(JDBCServerExplorerParameters serverParameters, VCSGisCodeGenerator codeGenerator) {
246
        this.stores = null;
247
        this.codeGenerator = codeGenerator;
248
        this.serverParameters = serverParameters;
249
        DataManager dataManager = DALLocator.getDataManager();
250
        try {
251
            this.server = (JDBCServerExplorer) dataManager.openServerExplorer(
252
                    serverParameters.getProviderName(),
253
                    serverParameters
254
            );
255
        } catch (Exception ex) {
256
            throw new VCSGisRuntimeException(VCSGisManager.ERR_INVALID_REPOSITORY, "Can't open server explorer.");
257
        }
258
        this.code = this.createUniqueCode();
259
        ConfigRepoTable varsTable = new ConfigRepoTable();
260
        varsTable.set(this, "REPOSITORY_CODE", this.code);
261
    }
262

    
263
    @Override
264
    public void dispose() {
265
        if(this.stores != null){
266
            for (FeatureStore store : this.stores.values()) {
267
                DisposeUtils.disposeQuietly(store);
268
            }
269
            this.stores = null;
270
        }
271
        DisposeUtils.disposeQuietly(this.server);
272
        this.server = null;
273
    }
274

    
275
    @Override
276
    public String getUserCode() {
277
        return this.userCode;
278
    }
279
    
280
    @Override
281
    public String getLabel() {
282
        return this.server.getParameters().getUrl();
283
    }
284

    
285
    @Override
286
    public String createUniqueCode() {
287
        return this.codeGenerator.generateCode();
288
    }
289

    
290
    public JDBCServerExplorer getServerExplorer() {
291
        return this.server;
292
    }
293
    
294
    public static void selfRegister() {
295
        Json.registerSerializer(VCSGisRepositoryLocaldb.class);
296
    }
297
    
298
    @Override
299
    public VCSGisCommitRequest createCommitRequest() {
300
        return new CommitRequestLocaldb(this);
301
    }
302

    
303
    @Override
304
    public VCSGisUpdateRequest createUpdateRequest(String entityName) {
305
        return new UpdateRequestLocaldb(this, entityName);
306
    }
307

    
308

    
309
    @Override
310
    public VCSGisCheckoutRequest createCheckoutRequest(String entityName) {
311
        return new CheckoutRequestLocaldb(this, entityName);
312
    }
313
    
314
    @Override
315
    public void fromJson(JsonObject json) {
316
        try {
317
            DataManager dataManager = DALLocator.getDataManager();
318
            DataServerExplorerParameters explorerParams = (DataServerExplorerParameters) Json.toObject(json, "explorerParams");
319
            this.server = (JDBCServerExplorer) dataManager.openServerExplorer(
320
                    explorerParams.getProviderName(), 
321
                    explorerParams
322
            );
323
            this.codeGenerator = VCSGisLocator.getVCSGisManager().getCodeGenerator();
324
            this.stores = new HashMap<>();
325
            this.code = json.getString("code", null);
326
            this.allowAssignTheRevisionDate = json.getBoolean("allowAssignTheRevisionDate", false);
327
            this.hooksTable = new HooksRepoTable();
328
            hooksTable.initHooks(this);
329
//            this.authenticationRequired = json.getBoolean("authenticationRequired", false);
330
            
331
        } catch (Exception ex) {
332
            throw new RuntimeException("Can't restore repository from json object.", ex);
333
        }
334
    }
335

    
336
    @Override
337
    public JsonObject toJson() {
338
        return this.toJsonBuilder().build();
339
    }
340

    
341
    @Override
342
    public JsonObjectBuilder toJsonBuilder() {
343
        JsonObjectBuilder builder = Json.createObjectBuilder();
344
        builder.add_class(this);
345
        builder.add("explorerParams", this.server.getParameters());
346
        builder.add("code", this.code);
347
        builder.add("allowAssignTheRevisionDate", this.allowAssignTheRevisionDate);
348
//        builder.add("authenticationRequired", this.authenticationRequired);
349
        return builder;
350
    }
351
    
352
    public FeatureStore getFeatureStore(String tableName) {
353
        if( this.stores==null ) {
354
            this.stores = new HashMap<>();
355
        }
356
        FeatureStore store = this.stores.get(tableName);
357
        if( store==null ) {
358
            store = this.openFeatureStore(tableName, null);
359
            this.stores.put(tableName, store);
360
        }
361
        DisposeUtils.bind(store);
362
        return store;
363
    }
364

    
365
    public FeatureStore openFeatureStore(String tableName, String sql) {
366
        FeatureStore store;
367
        try {
368
            JDBCStoreParameters params = this.server.get(tableName);
369
            params.setSQL(sql);
370
            store = (FeatureStore) DALLocator.getDataManager().openStore(params.getProviderName(), params);
371
            return store;
372
        } catch (Exception ex) {
373
            throw new RuntimeException("Can't open store '"+tableName+"'.", ex);
374
        }
375
    }
376

    
377
    @Override
378
    public VCSGisEntitiesRequest createEntitiesRequest() {
379
        return new EntitiesRequestLocaldb(this);
380
    }
381

    
382
    @Override
383
    public VCSGisHistoryRequest createHistoryRequest(String entityName) {
384
        return new HistoryRequestLocaldb(this, entityName);
385
    }
386
    
387
    @Override
388
    public VCSGisEntity getEntityByName(String entityName) {
389
        VCSGisEntitiesRequest request = this.createEntitiesRequest();
390
        if(request.execute() != ERR_OK){
391
            return null;
392
        }
393
        for (VCSGisEntity repositoryEntity : request.getRepositoryEntities()) {
394
            if(StringUtils.equalsIgnoreCase(repositoryEntity.getEntityName(), entityName)){
395
                return repositoryEntity;
396
            }
397
        }
398
        return null;
399
    }
400

    
401
    @Override
402
    public VCSGisRowCreateRequest createRowCreateRequest(String entityName, String localRevisionCode) {
403
        VCSGisRowCreateRequest request = new RowCreateRequestLocaldb(this, entityName, localRevisionCode);
404
        return request;
405
    }
406

    
407
    @Override
408
    public VCSGisRowDeleteRequest createRowDeleteRequest(String entityName, String localRevisionCode) {
409
        VCSGisRowDeleteRequest request = new RowDeleteRequestLocaldb(this, entityName, localRevisionCode);
410
        return request;
411
    }
412

    
413
    @Override
414
    public VCSGisRowUpdateRequest createRowUpdateRequest(String entityName, String localRevisionCode) {
415
        VCSGisRowUpdateRequest request = new RowUpdateRequestLocaldb(this, entityName, localRevisionCode);
416
        return request;
417
    }
418

    
419
    @Override
420
    public VCSGisTopologyPlansRequest createTopologyPlansRequest() {
421
        VCSGisTopologyPlansRequest request = new TopologyPlansRequestLocaldb(this);
422
        return request;
423
    }
424

    
425
    @Override
426
    public VCSGisUsersRequest createUsersRequest() {
427
        VCSGisUsersRequest request = new UsersRequestLocaldb(this);
428
        return request;
429
    }
430

    
431
    @Override
432
    public void addObserver(String tableName, String type, String operation, String command) {
433
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
434
    }
435

    
436
    public void notifyObservers(VCSGisRequest request) {
437
        this.hooksTable.after_request(this.getUserCode(), request.getRequestName(), null, null);
438
    }
439

    
440
    public void notifyObservers(VCSGisRequest request, String tableName, String revisionCode) {
441
        this.hooksTable.after_request(this.getUserCode(), request.getRequestName(), tableName, revisionCode);
442
    }
443

    
444
    public boolean isAllowedToAssignTheRevisionDate() {
445
        return this.allowAssignTheRevisionDate;
446
    }
447
    
448
    public void setAllowAssignTheRevisionDate(boolean allowAssignTheRevisionDate) {
449
        this.allowAssignTheRevisionDate = allowAssignTheRevisionDate;
450
    }
451

    
452
    public String getAuthenticationToken(String userCode, int minutesToExpire) {
453
        CRC32 crc = new CRC32();
454
        crc.update(userCode.getBytes());
455
        
456
        long expireTime = 0;
457
        if( minutesToExpire>0 ) {
458
            expireTime = toTimestamp(LocalDateTime.now().plusMinutes(minutesToExpire)).getTime();
459
        }
460
        
461
        String token = String.format("%016x%016x", 
462
                crc.getValue(),
463
                expireTime
464
        );
465
        
466
        return token;
467
    }
468

    
469
    public boolean isAuthenticationRequired() {
470
        ConfigRepoTable varsTable = new ConfigRepoTable();
471
        return BooleanUtils.toBoolean(varsTable.get(this, "AUTHENTICATION"));
472
//        return this.authenticationRequired;
473
    }
474
    
475
    public boolean isAuthorizationRequired() {
476
        ConfigRepoTable varsTable = new ConfigRepoTable();
477
        return BooleanUtils.toBoolean(varsTable.get(this, "AUTHORIZATION"));
478
//        return this.authorizationRequired;
479
    }
480
    
481
    public boolean isAuthenticated(AbstractRequest request) {
482
        if( !this.isAuthenticationRequired() ) {
483
            return true;
484
        }
485
        if( StringUtils.isBlank(request.getUserCode()) ) {
486
            request.error(ERR_INVALID_USERCODE,"User is not authenticated.");
487
            return false;
488
        }
489
        String authenticationToken = request.getAuthenticationToken();
490
        if( StringUtils.isBlank(authenticationToken) || authenticationToken.length()!=32 ) {
491
            request.error(ERR_INVALID_AUTHENTICATION_TOKEN,"User '"+request.getUserCode()+"' is not authenticated.");
492
            return false;
493
        }
494
        
495
        // TODO: check expire time and CRC
496
        long expireTime_l = Long.parseLong(authenticationToken.substring(17), 16);
497
        if( expireTime_l>0 ) {
498
            long now_l = new java.util.Date().getTime();
499
            if( now_l > expireTime_l ) {
500
                request.error(ERR_AUTHENTICATION_EXPIRED,"User '"+request.getUserCode()+"' is not authorized to '"+request.getRequestName()+"'.");
501
                return false;
502
            }
503
        }
504
        
505
        return true;
506
    }
507
    
508
    public boolean isAuthorized(AbstractRequestLocaldb request) {
509
        return this.isAuthorized(request, null);
510
    }
511
    
512
    public boolean isAuthorized(AbstractRequestLocaldb request, String operation) {
513
        if( !this.isAuthenticated(request) ) {
514
            return false;
515
        }
516
        if( !this.isAuthorizationRequired() ) {
517
            return true;
518
        }
519
        if( operation == null ) {
520
            operation = request.getRequestName().toLowerCase();
521
        }
522

    
523
        VCSGisUser user = request.getUser();
524
        if( user == null ) {
525
            request.error(ERR_USER_NOT_AUTHORIZED,"User '"+request.getUserCode()+"' is not authorized to '"+request.getRequestName()+"'.");
526
            return false;
527
        }
528
        List<String> operations = user.getAllowedOperationsAsList();
529
        if( operation == null ) {
530
            return true;
531
        }
532
        if( !operations.contains(operation) ) {
533
            request.error(ERR_USER_NOT_AUTHORIZED,"User '"+request.getUserCode()+"' is not authorized to '"+request.getRequestName()+"'.");
534
            return false;
535
        }
536
        return true;
537
    }
538

    
539
    @Override
540
    public VCSGisAuthenticateRequest createAuthenticateRequest(String userId, String password) {
541
        VCSGisAuthenticateRequest request = new AuthenticateRequestLocaldb(this);
542
        request.setUserId(userId);
543
        request.setPassword(password);
544
        return request;
545
    }
546

    
547
    @Override
548
    public String getAuthenticationToken() {
549
        return this.token;
550
    }
551

    
552
    @Override
553
    public void setAuthenticationToken(String token) {
554
        this.token = token;
555
    }
556

    
557
    @Override
558
    public void setUserCode(String userCode) {
559
        this.userCode = userCode;
560
    }
561

    
562

    
563
}