forked from ModeShape/modeshape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JcrRepository.java
2258 lines (2038 loc) · 110 KB
/
JcrRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ModeShape (http://www.modeshape.org)
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
* ModeShape is free software. Unless otherwise indicated, all code in ModeShape
* is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* ModeShape is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.modeshape.jcr;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessControlContext;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.query.Query;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import org.modeshape.common.annotation.Immutable;
import org.modeshape.common.annotation.ThreadSafe;
import org.modeshape.common.collection.LinkedListMultimap;
import org.modeshape.common.collection.Multimap;
import org.modeshape.common.collection.UnmodifiableProperties;
import org.modeshape.common.component.ComponentConfig;
import org.modeshape.common.component.ComponentLibrary;
import org.modeshape.common.i18n.I18n;
import org.modeshape.common.text.Inflector;
import org.modeshape.common.util.CheckArg;
import org.modeshape.common.util.ClassUtil;
import org.modeshape.common.util.Logger;
import org.modeshape.graph.ExecutionContext;
import org.modeshape.graph.Graph;
import org.modeshape.graph.Graph.Batch;
import org.modeshape.graph.GraphI18n;
import org.modeshape.graph.Location;
import org.modeshape.graph.Subgraph;
import org.modeshape.graph.Workspace;
import org.modeshape.graph.connector.RepositoryConnection;
import org.modeshape.graph.connector.RepositoryConnectionFactory;
import org.modeshape.graph.connector.RepositoryContext;
import org.modeshape.graph.connector.RepositorySource;
import org.modeshape.graph.connector.RepositorySourceCapabilities;
import org.modeshape.graph.connector.RepositorySourceException;
import org.modeshape.graph.connector.federation.FederatedRepositorySource;
import org.modeshape.graph.connector.federation.Projection;
import org.modeshape.graph.connector.federation.ProjectionParser;
import org.modeshape.graph.connector.inmemory.InMemoryRepositorySource;
import org.modeshape.graph.connector.xmlfile.XmlFileRepositorySource;
import org.modeshape.graph.observe.Changes;
import org.modeshape.graph.observe.NetChangeObserver;
import org.modeshape.graph.observe.Observable;
import org.modeshape.graph.observe.Observer;
import org.modeshape.graph.property.DateTime;
import org.modeshape.graph.property.Name;
import org.modeshape.graph.property.NamespaceRegistry;
import org.modeshape.graph.property.Path;
import org.modeshape.graph.property.PathFactory;
import org.modeshape.graph.property.Property;
import org.modeshape.graph.property.PropertyFactory;
import org.modeshape.graph.property.ValueFactories;
import org.modeshape.graph.property.ValueFactory;
import org.modeshape.graph.property.basic.GraphNamespaceRegistry;
import org.modeshape.graph.query.QueryBuilder;
import org.modeshape.graph.query.QueryBuilder.ConstraintBuilder;
import org.modeshape.graph.query.QueryResults;
import org.modeshape.graph.query.model.QueryCommand;
import org.modeshape.graph.query.model.Visitors;
import org.modeshape.graph.query.parse.QueryParsers;
import org.modeshape.graph.query.plan.PlanHints;
import org.modeshape.graph.query.validate.Schemata;
import org.modeshape.graph.request.ChangeRequest;
import org.modeshape.graph.request.InvalidWorkspaceException;
import org.modeshape.jcr.RepositoryQueryManager.PushDown;
import org.modeshape.jcr.api.AnonymousCredentials;
import org.modeshape.jcr.api.Repository;
import org.modeshape.jcr.query.JcrQomQueryParser;
import org.modeshape.jcr.query.JcrSql2QueryParser;
import org.modeshape.jcr.query.JcrSqlQueryParser;
import org.modeshape.jcr.security.AnonymousProvider;
import org.modeshape.jcr.security.AuthenticationProvider;
import org.modeshape.jcr.security.AuthenticationProviders;
import org.modeshape.jcr.security.JaasProvider;
import org.modeshape.jcr.security.JaccSubjectResolver;
import org.modeshape.jcr.security.SeamSecurityProvider;
import org.modeshape.jcr.security.SecurityContextProvider;
import org.modeshape.jcr.security.ServletProvider;
import org.modeshape.jcr.xpath.XPathQueryParser;
/**
* Creates JCR {@link Session sessions} to an underlying repository (which may be a federated repository).
* <p>
* This JCR repository must be configured with the ability to connect to a repository via a supplied
* {@link RepositoryConnectionFactory repository connection factory} and repository source name. An {@link ExecutionContext
* execution context} must also be supplied to enable working with the underlying ModeShape graph implementation to which this JCR
* implementation delegates.
* </p>
* <p>
* If {@link Credentials credentials} are used to login, implementations <em>must</em> also implement one of the following
* methods:
*
* <pre>
* public {@link AccessControlContext} getAccessControlContext();
* public {@link LoginContext} getLoginContext();
* </pre>
*
* Note, {@link Session#getAttributeNames() attributes} on credentials are not supported. JCR {@link SimpleCredentials} are also
* not supported.
* </p>
*/
@SuppressWarnings( "deprecation" )
@ThreadSafe
public class JcrRepository implements Repository {
/**
* A flag that controls whether the repository uses a shared repository (or workspace) for the "/jcr:system" content in all of
* the workspaces. In production, this needs to be "true" for proper JCR functionality, but in some debugging cases it can be
* set to false to simplify the architecture by removing the federated connector layer.
* <p>
* This should be changed to 'false' only in advanced situations, and never for production. Note that this also disables query
* execution.
* </p>
*/
static final boolean WORKSPACES_SHARE_SYSTEM_BRANCH = true;
/**
* The user name for anonymous sessions
*
* @see Option#ANONYMOUS_USER_ROLES
*/
static final String ANONYMOUS_USER_NAME = "<anonymous>";
private static final Logger LOGGER = Logger.getLogger(JcrRepository.class);
private static Properties bundleProperties = null;
/**
* The available options for the {@code JcrRepository}.
*/
public enum Option {
/**
* Flag that defines whether or not the node types should be exposed as content under the "
* {@code /jcr:system/jcr:nodeTypes}" node. Value is either "<code>true</code>" or "<code>false</code>" (default).
*
* @see DefaultOption#PROJECT_NODE_TYPES
*/
PROJECT_NODE_TYPES,
/**
* The {@link Configuration#getAppConfigurationEntry(String) JAAS application configuration name} that specifies which
* login modules should be used to validate credentials.
*/
JAAS_LOGIN_CONFIG_NAME,
/**
* The name of the source (and optionally the workspace in the source) where the "/jcr:system" branch should be stored.
* The format is "<code>name of workspace@name of source</code>", or simply "<code>name of source</code>" if the default
* workspace is to be used. If this option is not used, a transient in-memory source will be used.
* <p>
* Note that all leading and trailing whitespace is removed for both the source name and workspace name. Thus, a value of
* "<code>@</code>" implies a zero-length workspace name and zero-length source name.
* </p>
* <p>
* Also, any use of the '@' character in source and workspace names must be escaped with a preceding backslash.
* </p>
*/
SYSTEM_SOURCE_NAME,
/**
* The depth of the subgraphs that should be loaded from the connectors during normal read operations. The default value
* is 1.
*/
READ_DEPTH,
/**
* The depth of the subgraphs that should be loaded from the connectors during indexing operations. The default value is
* 4.
*/
INDEX_READ_DEPTH,
/**
* A comma-delimited list of default roles provided for anonymous access. A null or empty value for this option means that
* anonymous access is disabled.
*/
ANONYMOUS_USER_ROLES,
/**
* The query system represents node types as tables that can be queried, but there are two ways to define the columns for
* each of those tables. One approach is that each table only has columns representing the (single-valued) property
* definitions explicitly defined by the node type. The other approach also adds columns for each of the (single-valued)
* property definitions inherited by the node type from all of the {@link javax.jcr.nodetype.NodeType#getSupertypes()}.
* <p>
* The default value is 'true'.
* </p>
*/
TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES,
/**
* A boolean flag that specifies whether this repository is expected to execute searches and queries. If client
* applications will never perform searches or queries, then maintaining the query indexes is an unnecessary overhead, and
* can be disabled. Note that this is merely a hint, and that searches and queries might still work when this is set to
* 'false'.
* <p>
* The default is 'true', meaning that clients can execute searches and queries.
* </p>
*/
QUERY_EXECUTION_ENABLED,
/**
* The system may maintain a set of indexes that improve the performance of searching and querying the content. These size
* of these indexes depend upon the size of the content being stored, and thus may consume a significant amount of space.
* This option defines a location on the file system where this repository may (if needed) store indexes so they don't
* consume large amounts of memory.
* <p>
* If specified, the value must be a valid path to a writable directory on the file system. If the path specifies a
* non-existant location, the repository may attempt to create the missing directories. The path may be absolute or
* relative to the location where this VM was started. If the specified location is not a readable and writable directory
* (or cannot be created as such), then this will generate an exception when the repository is created.
* </p>
* <p>
* The default value is null, meaning the search indexes may not be stored on the local file system and, if needed, will
* be stored within memory.
* </p>
*/
QUERY_INDEX_DIRECTORY,
/**
* A boolean flag that specifies whether updates to the indexes (if used) should be made synchronously, meaning that a
* call to {@link Session#save()} will not return until the search indexes have been completely updated. The benefit of
* synchronous updates is that a search or query performed immediately after a <code>save()</code> will operate upon
* content that was just changed. The downside is that the <code>save()</code> operation will take longer.
* <p>
* With asynchronous updates, however, the only work done during a <code>save()</code> invocation is that required to
* persist the changes in the underlying repository source, while changes to the search indexes are made in a different
* thread that may not run immediately. In this case, there may be an indeterminate lag before searching or querying after
* a <code>save()</code> will operate upon the changed content.
* </p>
* <p>
* The default is value 'false', meaning the updates are performed <i>asynchronously</i>.
* </p>
*/
QUERY_INDEXES_UPDATED_SYNCHRONOUSLY,
/**
* A boolean flag that specifies whether referential integrity checks should be performed upon {@link Session#save()}. By
* default, this option is enabled, meaning that referential integrity checks <i>are</i> performed to ensure that nodes
* referenced by other nodes cannot be removed.
* <p>
* If no {@link PropertyType#REFERENCE} properties are used within your content, these referential integrity checks will
* never find referring nodes. In these cases, you may be able to improve performance by skipping these checks.
* </p>
* <p>
* The default value is 'true', meaning that these checks are performed.
* </p>
*/
PERFORM_REFERENTIAL_INTEGRITY_CHECKS,
/**
* A boolean flag that indicates whether a complete list of workspace names should be exposed in the custom repository
* descriptor {@link org.modeshape.jcr.api.Repository#REPOSITORY_WORKSPACES}.
* <p>
* If this option is set to {@code true}, then any code that can access the repository can retrieve a complete list of
* workspace names through the {@link javax.jcr.Repository#getDescriptor(String)} method without
* {@link javax.jcr.Repository#login logging in}.
* </p>
* <p>
* Since some ModeShape installations may consider the list of workspace names to be restricted information and limit the
* ability of some or all users to see a complete list of workspace names, this option can be set to {@code false} to
* disable this capability. If this option is set to {@code false}, the
* {@link org.modeshape.jcr.api.Repository#REPOSITORY_WORKSPACES} descriptor will not be set. In other words, the
* following code will print {@code false}.
* </p>
*
* <pre>
* Repository repo = ...;
* System.out.println(repo.getDescriptorKeys().contains(org.modeshape.jcr.api.Repository#REPOSITORY_WORKSPACES));
* </pre>
* <p>
* The default value is 'true', meaning that the descriptor is populated.
* </p>
*/
EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR,
/**
* A String property that when specified tells the {@link JcrEngine} where to put the {@link Repository} in to JNDI.
* Assumes that you have write access to the JNDI tree. If no value set, then the {@link Repository} will not be bound to
* JNDI.
*/
REPOSITORY_JNDI_LOCATION,
/**
* The structure of the version history. There are two values allowed:
* <ul>
* <li>"<strong>flat</strong>" will store all "<code>nt:versionHistory</code>" nodes with a name matching the UUID of the
* versioned node and directly under the <code>/jcr:system/jcr:versionStorage</code> node. For example, given a "
* <code>mix:versionable</code>" node with the UUID <code>fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>, the corresponding "
* <code>nt:versionHistory</code>" node will be at
* <code>/jcr:system/jcr:versionStorage/fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>.</li>
* <li>"<strong>hierarchical</strong>" will store all "<code>nt:versionHistory</code>" nodes under a hiearchical structure
* created by the first 8 characters of the UUID string. For example, given a "<code>mix:versionable</code>" node with the
* UUID <code>fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>, the corresponding "<code>nt:versionHistory</code>" node will be
* at <code>/jcr:system/jcr:versionStorage/fa/e2/b9/29/c5ef-4ce5-9fa1-514779ca0ae3</code>.</li>
* </ul>
* <p>
* The "hierarchical" structure is used by default and in cases where the option's value does not case-independently match
* the {@link VersionHistoryOption#FLAT} or {@link VersionHistoryOption#HIERARCHICAL} values.
* </p>
*/
VERSION_HISTORY_STRUCTURE,
/**
* A boolean option that dictates whether content derived from other content (e.g., by sequencers) should be automatically
* removed when the content from which it was derived is removed from the repository.
* <p>
* For example, consider that a file is uploaded and sequenced, and that the content derived from the file is stored in
* the repository. When that file is removed, this option dictates whether the derived content should also be removed
* automatically.
* </p>
* <p>
* A value of 'true' will ensure that all content derived from deleted content is also deleted. A value of 'false' will
* leave the derived content. The default value is 'true'.
* </p>
*/
REMOVE_DERIVED_CONTENT_WITH_ORIGINAL,
/**
* Indicates whether a failed attempt to {@link #login} should automatically attempt to use anonymous access instead. If
* anonymous access is not enabled, then failed login attempts will still cause an {@link LoginException} to be thrown.
* The default value is 'false'.
*
* @see #ANONYMOUS_USER_ROLES
*/
USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN,
/**
* Indicates under what circumstances the query index should be automatically rebuilt on startup. If this is set to
* 'always', the content for the entire JCR repository will be loaded and re-indexed each time that the repository is
* started. If this is set to 'ifMissing', re-indexing will only occur if there is no existing index. The default value is
* 'ifMissing'.
*/
REBUILD_QUERY_INDEX_ON_STARTUP,
/**
* Indicates whether the query indexes should be rebuilt on startup synchronously ('true') or asynchronously ('false').
* Rebuilding the query indexes can be an expensive operation on workspaces with large amounts of content, so setting this
* value to 'false' can cause a significant decrease in repository startup time. However, if this value is set to 'false',
* the query indexes may not accurately reflect the content in the repository while the rebuild is occurring. The default
* value is 'true'.
*/
QUERY_INDEXES_REBUILT_SYNCHRONOUSLY,
/**
* Indicates whether {@link org.modeshape.jcr.api.SecurityContextCredentials} should be supported by the
* {@link Repository#login(Credentials)} and {@link Repository#login(Credentials, String)} methods. By default, this
* support is <strong>disabled</strong> and not recommended; instead, use custom {@link AuthenticationProvider}s.
*
* @deprecated Use custom AuthenticationProvider implementations instead
*/
@Deprecated
USE_SECURITY_CONTEXT_CREDENTIALS, ;
/**
* Determine the option given the option name. This does more than {@link Option#valueOf(String)}, since this method first
* tries to match the supplied string to the option's {@link Option#name() name}, then the uppercase version of the
* supplied string to the option's name, and finally if the supplied string is a camel-case version of the name (e.g.,
* "projectNodeTypes").
*
* @param option the string version of the option's name
* @return the matching Option instance, or null if an option could not be matched using the supplied value
*/
public static Option findOption( String option ) {
if (option == null) return null;
try {
return Option.valueOf(option);
} catch (IllegalArgumentException e) {
// Try an uppercased version ...
try {
return Option.valueOf(option.toUpperCase());
} catch (IllegalArgumentException e2) {
// Try a camel-case version ...
String underscored = Inflector.getInstance().underscore(option, '_');
if (underscored == null) {
throw e2;
}
try {
return Option.valueOf(underscored.toUpperCase());
} catch (IllegalArgumentException e3) {
return null;
}
}
}
}
}
/**
* The possible values for the {@link Option#REBUILD_QUERY_INDEX_ON_STARTUP} option.
*/
public static class RebuildQueryIndexOnStartupOption {
/**
* The value that indicates that the query index for each workspace should be rebuilt even if it already exists and
* appears to be valid.
*/
public static final String ALWAYS = "always";
/**
* The value that indicates that the query index for each workspace should be rebuilt only if it does not already exist.
*/
public static final String IF_MISSING = "ifMissing";
}
/**
* The possible values for the {@link Option#VERSION_HISTORY_STRUCTURE} option.
*/
public static class VersionHistoryOption {
/**
* The value that signals that all "<code>nt:versionHistory</code>" nodes with a name matching the UUID of the versioned
* node are stored directly under the <code>/jcr:system/jcr:versionStorage</code> node. For example, given a "
* <code>mix:versionable</code>" node with the UUID <code>fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>, the corresponding "
* <code>nt:versionHistory</code>" node will be at
* <code>/jcr:system/jcr:versionStorage/fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>.
*/
public static final String FLAT = "flat";
/**
* The value that signals that all "<code>nt:versionHistory</code>" nodes be stored under a 4-tier hiearchical structure
* created by the first 8 characters of the UUID string broken into 2-character pairs. For example, given a "
* <code>mix:versionable</code>" node with the UUID <code>fae2b929-c5ef-4ce5-9fa1-514779ca0ae3</code>, the corresponding "
* <code>nt:versionHistory</code>" node will be at
* <code>/jcr:system/jcr:versionStorage/fa/e2/b9/29/c5ef-4ce5-9fa1-514779ca0ae3</code>.
*/
public static final String HIERARCHICAL = "hierarchical";
}
/**
* The default values for each of the {@link Option}.
*/
public static class DefaultOption {
/**
* The default value for the {@link Option#PROJECT_NODE_TYPES} option is {@value} .
*/
public static final String PROJECT_NODE_TYPES = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#JAAS_LOGIN_CONFIG_NAME} option is {@value} .
*/
public static final String JAAS_LOGIN_CONFIG_NAME = "modeshape-jcr";
/**
* The default value for the {@link Option#READ_DEPTH} option is {@value} .
*/
public static final String READ_DEPTH = "1";
/**
* The default value for the {@link Option#INDEX_READ_DEPTH} option is {@value} .
*/
public static final String INDEX_READ_DEPTH = "4";
/**
* The default value for the {@link Option#ANONYMOUS_USER_ROLES} option is {@value} .
*/
public static final String ANONYMOUS_USER_ROLES = ModeShapeRoles.ADMIN;
/**
* The default value for the {@link Option#TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES} option is {@value} .
*/
public static final String TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#QUERY_EXECUTION_ENABLED} option is {@value} .
*/
public static final String QUERY_EXECUTION_ENABLED = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#QUERY_INDEXES_UPDATED_SYNCHRONOUSLY} option is {@value} .
*/
public static final String QUERY_INDEXES_UPDATED_SYNCHRONOUSLY = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#QUERY_INDEX_DIRECTORY} option is {@value} .
*/
public static final String QUERY_INDEX_DIRECTORY = null;
/**
* The default value for the {@link Option#PERFORM_REFERENTIAL_INTEGRITY_CHECKS} option is {@value} .
*/
public static final String PERFORM_REFERENTIAL_INTEGRITY_CHECKS = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#REPOSITORY_JNDI_LOCATION} option is {@value}
*/
public static final String REPOSITORY_JNDI_LOCATION = "";
/**
* The default value for the {@link Option#EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR} option is {@value} .
*/
public static final String EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#VERSION_HISTORY_STRUCTURE} option is {@value} .
*/
public static final String VERSION_HISTORY_STRUCTURE = VersionHistoryOption.HIERARCHICAL;
/**
* The default value for the {@link Option#REMOVE_DERIVED_CONTENT_WITH_ORIGINAL} option is {@value} .
*/
public static final String REMOVE_DERIVED_CONTENT_WITH_ORIGINAL = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN} option is {@value} .
*/
public static final String USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN = Boolean.FALSE.toString();
/**
* The default value for the {@link Option#REBUILD_QUERY_INDEX_ON_STARTUP} option is {@value} .
*/
public static final String REBUILD_QUERY_INDEX_ON_STARTUP = RebuildQueryIndexOnStartupOption.IF_MISSING;
/**
* The default value for the {@link Option#QUERY_INDEXES_REBUILT_SYNCHRONOUSLY} option is {@value} .
*/
public static final String QUERY_INDEXES_REBUILT_SYNCHRONOUSLY = Boolean.TRUE.toString();
/**
* The default value for the {@link Option#USE_SECURITY_CONTEXT_CREDENTIALS} option is {@value} .
*/
public static final String USE_SECURITY_CONTEXT_CREDENTIALS = Boolean.FALSE.toString();
}
/**
* The static unmodifiable map of default options, which are initialized in the static initializer.
*/
protected static final Map<Option, String> DEFAULT_OPTIONS;
/**
* The set of supported query language string constants.
*
* @see javax.jcr.query.QueryManager#getSupportedQueryLanguages()
* @see javax.jcr.query.QueryManager#createQuery(String, String)
*/
public static final class QueryLanguage {
/**
* The standard JCR 1.0 XPath query language.
*/
public static final String XPATH = Query.XPATH;
/**
* The SQL dialect that is based upon an enhanced version of the JCR-SQL query language defined by the JCR 1.0.1
* specification.
*/
public static final String JCR_SQL = Query.SQL;
/**
* The SQL dialect that is based upon an enhanced version of the JCR-SQL2 query language defined by the JCR 2.0
* specification.
*/
public static final String JCR_SQL2 = Query.JCR_SQL2;
/**
* The enhanced Query Object Model language defined by the JCR 2.0 specification.
*/
public static final String JCR_JQOM = Query.JCR_JQOM;
/**
* The full-text search language defined as part of the abstract query model, in Section 6.7.19 of the JCR 2.0
* specification.
*/
public static final String SEARCH = FullTextSearchParser.LANGUAGE;
}
static {
// Initialize the unmodifiable map of default options ...
EnumMap<Option, String> defaults = new EnumMap<Option, String>(Option.class);
defaults.put(Option.PROJECT_NODE_TYPES, DefaultOption.PROJECT_NODE_TYPES);
defaults.put(Option.JAAS_LOGIN_CONFIG_NAME, DefaultOption.JAAS_LOGIN_CONFIG_NAME);
defaults.put(Option.READ_DEPTH, DefaultOption.READ_DEPTH);
defaults.put(Option.INDEX_READ_DEPTH, DefaultOption.INDEX_READ_DEPTH);
defaults.put(Option.ANONYMOUS_USER_ROLES, DefaultOption.ANONYMOUS_USER_ROLES);
defaults.put(Option.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES,
DefaultOption.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES);
defaults.put(Option.QUERY_EXECUTION_ENABLED, DefaultOption.QUERY_EXECUTION_ENABLED);
defaults.put(Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY, DefaultOption.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY);
defaults.put(Option.QUERY_INDEX_DIRECTORY, DefaultOption.QUERY_INDEX_DIRECTORY);
defaults.put(Option.PERFORM_REFERENTIAL_INTEGRITY_CHECKS, DefaultOption.PERFORM_REFERENTIAL_INTEGRITY_CHECKS);
defaults.put(Option.EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR, DefaultOption.EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR);
defaults.put(Option.VERSION_HISTORY_STRUCTURE, DefaultOption.VERSION_HISTORY_STRUCTURE);
defaults.put(Option.REPOSITORY_JNDI_LOCATION, DefaultOption.REPOSITORY_JNDI_LOCATION);
defaults.put(Option.REMOVE_DERIVED_CONTENT_WITH_ORIGINAL, DefaultOption.REMOVE_DERIVED_CONTENT_WITH_ORIGINAL);
defaults.put(Option.USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN, DefaultOption.USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN);
defaults.put(Option.REBUILD_QUERY_INDEX_ON_STARTUP, DefaultOption.REBUILD_QUERY_INDEX_ON_STARTUP);
defaults.put(Option.QUERY_INDEXES_REBUILT_SYNCHRONOUSLY, DefaultOption.QUERY_INDEXES_REBUILT_SYNCHRONOUSLY);
defaults.put(Option.USE_SECURITY_CONTEXT_CREDENTIALS, DefaultOption.USE_SECURITY_CONTEXT_CREDENTIALS);
DEFAULT_OPTIONS = Collections.<Option, String>unmodifiableMap(defaults);
}
private final String sourceName;
private final Map<String, Object> descriptors = new HashMap<String, Object>();
private final ExecutionContext executionContext;
private final RepositoryConnectionFactory connectionFactory;
private final RepositoryNodeTypeManager repositoryTypeManager;
private final RepositoryLockManager repositoryLockManager;
private final Map<Option, String> options;
private final String systemSourceName;
private final String systemWorkspaceName;
private final Projection systemSourceProjection;
private final FederatedRepositorySource federatedSource;
private final GraphNamespaceRegistry persistentRegistry;
private final RepositoryObservationManager repositoryObservationManager;
private final QueryParsers queryParsers;
private final Credentials anonymousCredentialsIfSuppliedCredentialsFail;
private final AuthenticationProvider authenticator;
private Set<String> cachedWorkspaceNames = new HashSet<String>();
// Until the federated connector supports queries, we have to use a search engine ...
private final RepositoryQueryManager queryManager;
/* The location of the XML file containing the initial content for newly-created workspaces */
private final String initialContentForNewWorkspaces;
// package-scoped to facilitate testing
final WeakHashMap<JcrSession, Object> activeSessions = new WeakHashMap<JcrSession, Object>();
private final ExecutorService backgroundService = Executors.newSingleThreadExecutor();
/**
* Creates a JCR repository that uses the supplied {@link RepositoryConnectionFactory repository connection factory} to
* establish {@link Session sessions} to the underlying repository source upon {@link #login() login}.
*
* @param executionContext the execution context in which this repository is to operate
* @param connectionFactory the factory for repository connections
* @param repositorySourceName the name of the repository source (in the connection factory) that should be used
* @param repositoryObservable the repository library observable associated with this repository (never <code>null</code>)
* @param repositorySourceCapabilities the capabilities of the repository source; may be null if the capabilities are not
* known
* @param descriptors the {@link #getDescriptorKeys() descriptors} for this repository; may be <code>null</code>.
* @param options the optional {@link Option settings} for this repository; may be null
* @param initialContentForNewWorkspaces the URL, file system path, or classpath resource path to the XML file containing the
* initial content for newly-created workspaces; may be null
* @param authenticationProviders the component library of AuthenticationProvider implementations; may be null or empty
* @throws RepositoryException if there is a problem setting up this repository
* @throws IllegalArgumentException If <code>executionContext</code>, <code>connectionFactory</code>,
* <code>repositorySourceName</code>, or <code>repositoryObservable</code> is <code>null</code>.
*/
JcrRepository( ExecutionContext executionContext,
RepositoryConnectionFactory connectionFactory,
String repositorySourceName,
Observable repositoryObservable,
RepositorySourceCapabilities repositorySourceCapabilities,
Map<String, String> descriptors,
Map<Option, String> options,
String initialContentForNewWorkspaces,
ComponentLibrary<AuthenticationProvider, ComponentConfig> authenticationProviders ) throws RepositoryException {
CheckArg.isNotNull(executionContext, "executionContext");
CheckArg.isNotNull(connectionFactory, "connectionFactory");
CheckArg.isNotNull(repositorySourceName, "repositorySourceName");
CheckArg.isNotNull(repositoryObservable, "repositoryObservable");
// Set up the options ...
if (options == null) {
this.options = DEFAULT_OPTIONS;
} else {
// Initialize with defaults, then add supplied options ...
EnumMap<Option, String> localOptions = new EnumMap<Option, String>(DEFAULT_OPTIONS);
localOptions.putAll(options);
this.options = Collections.unmodifiableMap(localOptions);
}
// Set up the system source ...
String systemSourceNameValue = this.options.get(Option.SYSTEM_SOURCE_NAME);
String systemSourceName = null;
String systemWorkspaceName = null;
RepositoryConnectionFactory connectionFactoryWithSystem = connectionFactory;
if (systemSourceNameValue != null) {
// Find an existing source with the given name containing the named workspace ...
try {
SourceWorkspacePair pair = new SourceWorkspacePair(systemSourceNameValue);
// Look for a source with the given name ...
RepositoryConnection conn = connectionFactory.createConnection(pair.getSourceName());
if (conn != null) {
// We found a source that we can use for the system ...
systemSourceName = pair.getSourceName();
if (pair.getWorkspaceName() != null) {
// There should be the named workspace ...
Graph temp = Graph.create(conn, executionContext);
temp.useWorkspace(pair.getWorkspaceName());
// found it ...
systemWorkspaceName = pair.getWorkspaceName();
}
} else {
I18n msg = JcrI18n.systemSourceNameOptionValueDoesNotReferenceExistingSource;
LOGGER.warn(msg, systemSourceNameValue, systemSourceName);
}
} catch (InvalidWorkspaceException e) {
// Bad workspace name ...
systemSourceName = null;
I18n msg = JcrI18n.systemSourceNameOptionValueDoesNotReferenceValidWorkspace;
LOGGER.warn(msg, systemSourceNameValue, systemSourceName);
} catch (IllegalArgumentException e) {
// Invalid format ...
systemSourceName = null;
I18n msg = JcrI18n.systemSourceNameOptionValueIsNotFormattedCorrectly;
LOGGER.warn(msg, systemSourceNameValue);
}
}
InMemoryRepositorySource transientSystemSource = null;
if (systemSourceName == null) {
// Create the in-memory repository source that we'll use for the "/jcr:system" branch in this repository.
// All workspaces will be set up with a federation connector that projects this system repository into
// "/jcr:system", and all other content is projected to the repositories actual source (and workspace).
// (The federation connector refers to this configuration as an "offset mirror".)
systemWorkspaceName = "jcr:system";
systemSourceName = "jcr:system source";
transientSystemSource = new InMemoryRepositorySource();
transientSystemSource.setName(systemSourceName);
transientSystemSource.setDefaultWorkspaceName(systemWorkspaceName);
connectionFactoryWithSystem = new DelegatingConnectionFactory(connectionFactory, transientSystemSource);
}
// Set up the query parsers, which we have to have even though queries might be disabled ...
this.queryParsers = new QueryParsers(new JcrSql2QueryParser(), new XPathQueryParser(), new FullTextSearchParser(),
new JcrSqlQueryParser(), new JcrQomQueryParser());
assert this.queryParsers.getParserFor(Query.XPATH) != null;
assert this.queryParsers.getParserFor(Query.SQL) != null;
assert this.queryParsers.getParserFor(Query.JCR_SQL2) != null;
assert this.queryParsers.getParserFor(Query.JCR_JQOM) != null;
assert this.queryParsers.getParserFor(QueryLanguage.SEARCH) != null;
this.systemWorkspaceName = systemWorkspaceName;
this.systemSourceName = systemSourceName;
this.connectionFactory = connectionFactoryWithSystem;
assert this.systemSourceName != null;
assert this.connectionFactory != null;
this.sourceName = repositorySourceName;
this.initialContentForNewWorkspaces = initialContentForNewWorkspaces;
// Set up the "/jcr:system" branch ...
Graph systemGraph = Graph.create(this.systemSourceName, this.connectionFactory, executionContext);
systemGraph.useWorkspace(systemWorkspaceName);
initializeSystemContent(systemGraph);
// Create the namespace registry and corresponding execution context.
// Note that this persistent registry has direct access to the system workspace.
Name uriProperty = ModeShapeLexicon.URI;
Name genProperty = ModeShapeLexicon.GENERATED;
PathFactory pathFactory = executionContext.getValueFactories().getPathFactory();
Path systemPath = pathFactory.create(JcrLexicon.SYSTEM);
final Path namespacesPath = pathFactory.create(systemPath, ModeShapeLexicon.NAMESPACES);
PropertyFactory propertyFactory = executionContext.getPropertyFactory();
Property namespaceType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.NAMESPACE);
// Now create the registry implementation ...
this.persistentRegistry = new GraphNamespaceRegistry(systemGraph, namespacesPath, uriProperty, genProperty, namespaceType);
this.executionContext = executionContext.with(persistentRegistry);
// Add the built-ins, ensuring we overwrite any badly-initialized values ...
this.persistentRegistry.register(JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX);
// Set up the repository type manager ...
Path parentOfTypeNodes = null;
if (Boolean.valueOf(this.options.get(Option.PROJECT_NODE_TYPES))) {
parentOfTypeNodes = pathFactory.create(systemPath, JcrLexicon.NODE_TYPES);
}
try {
boolean includeInheritedProperties = Boolean.valueOf(this.options.get(Option.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES));
boolean includePseudoColumnInSelectStar = true;
// Create the manager for this repository's node types, initializing it from the system graph and registering the
// standard types ...
this.repositoryTypeManager = new RepositoryNodeTypeManager(this, parentOfTypeNodes, includeInheritedProperties,
includePseudoColumnInSelectStar);
if (!this.repositoryTypeManager.refreshFromSystem()) {
// Read in the built-in node types ...
CndNodeTypeReader nodeTypeReader = new CndNodeTypeReader(this.executionContext);
nodeTypeReader.readBuiltInTypes();
this.repositoryTypeManager.registerNodeTypes(nodeTypeReader, false);
}
} catch (RepositoryException re) {
throw new IllegalStateException("Could not load node type definition files", re);
} catch (IOException ioe) {
throw new IllegalStateException("Could not access node type definition files", ioe);
}
if (WORKSPACES_SHARE_SYSTEM_BRANCH) {
// Create the projection for the system repository ...
ProjectionParser projectionParser = ProjectionParser.getInstance();
String rule = "/jcr:system => /jcr:system";
Projection.Rule[] systemProjectionRules = projectionParser.rulesFromString(this.executionContext, rule);
this.systemSourceProjection = new Projection(systemSourceName, systemWorkspaceName, true, systemProjectionRules);
// Define the federated repository source. Use the same name as the repository, since this federated source
// will not be in the connection factory ...
this.federatedSource = new FederatedRepositorySource();
this.federatedSource.setName("JCR " + repositorySourceName);
this.federatedSource.initialize(new FederatedRepositoryContext(this.connectionFactory));
// Set up the workspaces corresponding to all those available in the source (except the system)
Graph graph = Graph.create(sourceName, connectionFactory, executionContext);
String defaultWorkspaceName = graph.getCurrentWorkspaceName();
for (String workspaceName : graph.getWorkspaces()) {
boolean isDefault = workspaceName.equals(defaultWorkspaceName);
addWorkspace(workspaceName, isDefault);
}
} else {
this.federatedSource = null;
this.systemSourceProjection = null;
}
if (descriptors == null) descriptors = new HashMap<String, String>();
// Determine if it's possible to manage workspaces with the underlying source ...
if (repositorySourceCapabilities != null && repositorySourceCapabilities.supportsCreatingWorkspaces()) {
// Don't overwrite (so they workspace management can be disabled) ...
if (!descriptors.containsKey(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)) {
descriptors.put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, Boolean.TRUE.toString());
}
} else {
// Not possible, so overwrite any value that might have been added ...
descriptors.put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, Boolean.FALSE.toString());
}
// Initialize required JCR descriptors.
this.descriptors.putAll(initializeDescriptors(executionContext.getValueFactories(), descriptors));
// If the repository is to support searching ...
if (Boolean.valueOf(this.options.get(Option.QUERY_EXECUTION_ENABLED)) && WORKSPACES_SHARE_SYSTEM_BRANCH) {
// Determine whether the federated source and original source support queries and searches ...
RepositorySourceCapabilities fedCapabilities = federatedSource != null ? federatedSource.getCapabilities() : null;
final boolean canQuerySource = repositorySourceCapabilities != null
&& repositorySourceCapabilities.supportsSearches()
&& repositorySourceCapabilities.supportsQueries();
final boolean canQueryFederated = fedCapabilities != null && fedCapabilities.supportsSearches()
&& fedCapabilities.supportsQueries();
// We can query the federated source if it supports queries and searches
// AND the original source supports queries and searches ...
if (canQuerySource && canQueryFederated) {
this.queryManager = new PushDown(repositoryName(), this.sourceName, this.executionContext, connectionFactory);
} else {
// Otherwise create a repository query manager that maintains its own search engine ...
String indexDirectory = this.options.get(Option.QUERY_INDEX_DIRECTORY);
boolean updateIndexesSynchronously = Boolean.valueOf(this.options.get(Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY));
boolean forceIndexRebuild = RebuildQueryIndexOnStartupOption.ALWAYS.equalsIgnoreCase(this.options.get(Option.REBUILD_QUERY_INDEX_ON_STARTUP));
boolean rebuildIndexesSynchronously = Boolean.TRUE.equals(Boolean.valueOf(this.options.get(Option.QUERY_INDEXES_REBUILT_SYNCHRONOUSLY)));
int maxDepthToRead = Integer.valueOf(this.options.get(Option.INDEX_READ_DEPTH));
this.queryManager = new RepositoryQueryManager.SelfContained(repositoryName(), this.executionContext,
this.sourceName, connectionFactory,
repositoryObservable, repositoryTypeManager,
indexDirectory, updateIndexesSynchronously,
forceIndexRebuild, rebuildIndexesSynchronously,
maxDepthToRead);
}
} else {
this.queryManager = new RepositoryQueryManager.Disabled(repositoryName(), this.sourceName);
}
// Initialize the observer, which receives events from all repository sources
this.repositoryObservationManager = new RepositoryObservationManager(repositoryObservable);
if (transientSystemSource != null) {
// The transient RepositorySource for the system content is not in the RepositoryLibrary, so we need to observe it ...
final Observer observer = this.repositoryObservationManager;
final ExecutionContext context = executionContext;
transientSystemSource.initialize(new RepositoryContext() {
public Observer getObserver() {
return observer;
}
public ExecutionContext getExecutionContext() {
return context;
}
public Subgraph getConfiguration( int depth ) {
return null; // not needed for the in-memory transient repository
}
public RepositoryConnectionFactory getRepositoryConnectionFactory() {
return null; // not needed for the in-memory transient repository
}
});
}
// Prepare to create the authenticators and authorizers ...
AuthenticationProviders authenticators = new AuthenticationProviders();
// Set up the JAAS providers ...
String policyName = this.options.get(Option.JAAS_LOGIN_CONFIG_NAME);
if (policyName != null && policyName.trim().length() != 0) {
// Per MODE-1270, see if the JACC API is available (if so, we're running in an J2EE container
// and need to provide a way to properly resolve the JAAS Subject)...
JaasProvider.SubjectResolver subjectResolver = null;
try {
// Try to find the JACC PolicyContext class, which is entirely optional and provided only in J2EE containers ...
ClassUtil.loadClassStrict("javax.security.jacc.PolicyContext");
subjectResolver = new JaccSubjectResolver();
LOGGER.debug("Enabling optional JACC approach for resolving the JAAS Subject (typically in J2EE containers)");
} catch (ClassNotFoundException cnfe) {
// Must not be able to load the class ...
LOGGER.debug("Failed to find 'javax.security.jacc.PolicyContext', so assuming not in a J2EE container.");
}
try {
JaasProvider jaasProvider = new JaasProvider(policyName, subjectResolver);
authenticators = authenticators.with(jaasProvider);
LOGGER.debug("Enabling JAAS authentication and authorization.");
} catch (java.lang.SecurityException e) {
LOGGER.warn(JcrI18n.loginConfigNotFound, policyName, Option.JAAS_LOGIN_CONFIG_NAME, repositoryName());
} catch (javax.security.auth.login.LoginException e) {
LOGGER.warn(JcrI18n.loginConfigNotFound, policyName, Option.JAAS_LOGIN_CONFIG_NAME, repositoryName());
}
}
try {
// Try to set up the Seam Security provider ...
ClassUtil.loadClassStrict("org.jboss.seam.security.Identity");
SeamSecurityProvider seamSecurityProvider = new SeamSecurityProvider();
authenticators = authenticators.with(seamSecurityProvider);
LOGGER.debug("Enabling Seam Security authentication and authorization.");
} catch (ClassNotFoundException cnfe) {
// Must not be able to load the class ...
LOGGER.debug("Failed to find 'org.jboss.seam.security.Identity' class, so not loading ModeShape's optional SeamSecurityProvider");
}
try {
// Try to set up the HTTP servlet request class, which is available only in servlet containers ...
ClassUtil.loadClassStrict("javax.servlet.http.HttpServletRequest");
ServletProvider servletProvider = new ServletProvider();
authenticators = authenticators.with(servletProvider);
LOGGER.debug("Enabling servlet authentication and authorization.");
} catch (ClassNotFoundException cnfe) {
// Must not be able to load the class ...
LOGGER.debug("Failed to find 'javax.servlet.http.HttpServletRequest' class, so not loading ModeShape's optional ServletProvider");
}
// Set up the anonymous provider (if appropriate) ...
String rawAnonRoles = this.options.get(Option.ANONYMOUS_USER_ROLES);
if (rawAnonRoles != null) {
final Set<String> roles = new HashSet<String>();
for (String role : rawAnonRoles.split("\\s*,\\s*")) {
roles.add(role);
}
if (roles.size() > 0) {
AnonymousProvider anonProvider = new AnonymousProvider(ANONYMOUS_USER_NAME, roles);
authenticators = authenticators.with(anonProvider);
LOGGER.debug("Enabling anonymous authentication and authorization.");
}
}
// Set up the SecurityContext provider (for backward compatibility) unless configured otherwise ...
// Set up the JAAS providers ...
boolean useSecurityContextCredentials = Boolean.parseBoolean(this.options.get(Option.USE_SECURITY_CONTEXT_CREDENTIALS));
if (useSecurityContextCredentials) {
SecurityContextProvider provider = new SecurityContextProvider();
authenticators = authenticators.with(provider);
}
// Set up any custom AuthenticationProvider classes ...
if (authenticationProviders != null) {
for (AuthenticationProvider provider : authenticationProviders.getInstances()) {
if (provider != null) authenticators = authenticators.with(provider);
}
}