|
|
|
|
1 |
|
/**
|
|
|
|
|
2 |
|
* Licens
ed to the
Apache Sof
tware Foun
dation (AS
F) under o
ne or more
|
|
|
|
|
3 |
|
* contri
butor lice
nse agreem
ents. See
the NOTIC
E file dis
tributed w
ith
|
|
|
|
|
4 |
|
* this w
ork for ad
ditional i
nformation
regarding
copyright
ownership
.
|
|
|
|
|
5 |
|
* The AS
F licenses
this file
to You un
der the Ap
ache Licen
se, Versio
n 2.0
|
|
|
|
|
6 |
|
* (the "
License");
you may n
ot use thi
s file exc
ept in com
pliance wi
th
|
|
|
|
|
7 |
|
* the Li
cense. Yo
u may obta
in a copy
of the Lic
ense at
|
|
|
|
|
8 |
|
*
|
|
|
|
|
9 |
|
* htt
p://www.ap
ache.org/l
icenses/LI
CENSE-2.0
|
|
|
|
|
10 |
|
*
|
|
|
|
|
11 |
|
* Unless
required
by applica
ble law or
agreed to
in writin
g, softwar
e
|
|
|
|
|
12 |
|
* distri
buted unde
r the Lice
nse is dis
tributed o
n an "AS I
S" BASIS,
|
|
|
|
|
13 |
|
* WITHOU
T WARRANTI
ES OR COND
ITIONS OF
ANY KIND,
either exp
ress or im
plied.
|
|
|
|
|
14 |
|
* See th
e License
for the sp
ecific lan
guage gove
rning perm
issions an
d
|
|
|
|
|
15 |
|
* limita
tions unde
r the Lice
nse.
|
|
|
|
|
16 |
|
*/
|
|
|
|
|
17 |
|
package or
g.apache.c
atalina.au
thenticato
r.jaspic;
|
|
|
|
|
18 |
|
|
|
|
|
|
19 |
|
import jav
a.lang.ref
lect.Invoc
ationTarge
tException
;
|
|
|
|
|
20 |
|
import jav
a.util.Arr
ayList;
|
|
|
|
|
21 |
|
import jav
a.util.Has
hMap;
|
|
|
|
|
22 |
|
import jav
a.util.Lis
t;
|
|
|
|
|
23 |
|
import jav
a.util.Map
;
|
|
|
|
|
24 |
|
|
|
|
|
|
25 |
|
import jav
ax.securit
y.auth.Sub
ject;
|
|
|
|
|
26 |
|
import jav
ax.securit
y.auth.cal
lback.Call
backHandle
r;
|
|
|
|
|
27 |
|
import jav
ax.securit
y.auth.mes
sage.AuthE
xception;
|
|
|
|
|
28 |
|
import jav
ax.securit
y.auth.mes
sage.Messa
geInfo;
|
|
|
|
|
29 |
|
import jav
ax.securit
y.auth.mes
sage.confi
g.ServerAu
thConfig;
|
|
|
|
|
30 |
|
import jav
ax.securit
y.auth.mes
sage.confi
g.ServerAu
thContext;
|
|
|
|
|
31 |
|
import jav
ax.securit
y.auth.mes
sage.modul
e.ServerAu
thModule;
|
|
|
|
|
32 |
|
|
|
|
|
|
33 |
|
import org
.apache.to
mcat.util.
res.String
Manager;
|
|
|
|
|
34 |
|
|
|
|
|
|
35 |
|
/**
|
|
|
|
|
36 |
|
* Basic i
mplementat
ion primar
ily intend
ed for use
when usin
g third-pa
rty
|
|
|
|
|
37 |
|
* {@link
ServerAuth
Module} im
plementati
ons that o
nly provid
e the modu
le. This
|
|
|
|
|
38 |
|
* impleme
ntation su
pports con
figuring t
he {@link
ServerAuth
Context} w
ith
|
|
|
|
|
39 |
|
* multipl
e modules.
|
|
|
|
|
40 |
|
*/
|
|
|
|
|
41 |
|
public cla
ss SimpleS
erverAuthC
onfig impl
ements Ser
verAuthCon
fig {
|
|
|
|
|
42 |
|
|
|
|
|
|
43 |
|
privat
e static S
tringManag
er sm = St
ringManage
r.getManag
er(SimpleS
erverAuthC
onfig.clas
s);
|
|
|
|
|
44 |
|
|
|
|
|
|
45 |
|
privat
e static f
inal Strin
g SERVER_A
UTH_MODULE
_KEY_PREFI
X =
|
|
|
|
|
46 |
|
"org.apa
che.catali
na.authent
icator.jas
pic.Server
AuthModule
.";
|
|
|
|
|
47 |
|
|
|
|
|
|
48 |
|
privat
e final St
ring layer
;
|
|
|
|
|
49 |
|
privat
e final St
ring appCo
ntext;
|
|
|
|
|
50 |
|
privat
e final Ca
llbackHand
ler handle
r;
|
|
|
|
|
51 |
|
privat
e final Ma
p<String,S
tring> pro
perties;
|
|
|
|
|
52 |
|
|
|
|
|
|
53 |
|
privat
e volatile
ServerAut
hContext s
erverAuthC
ontext;
|
|
|
|
|
54 |
|
|
|
|
|
|
55 |
|
public
SimpleSer
verAuthCon
fig(String
layer, St
ring appCo
ntext, Cal
lbackHandl
er handler
,
|
|
|
|
|
56 |
|
Map<Stri
ng,String>
propertie
s) {
|
|
|
|
|
57 |
|
th
is.layer =
layer;
|
|
|
|
|
58 |
|
th
is.appCont
ext = appC
ontext;
|
|
|
|
|
59 |
|
th
is.handler
= handler
;
|
|
|
|
|
60 |
|
th
is.propert
ies = prop
erties;
|
|
|
|
|
61 |
|
}
|
|
|
|
|
62 |
|
|
|
|
|
|
63 |
|
|
|
|
|
|
64 |
|
@Overr
ide
|
|
|
|
|
65 |
|
public
String ge
tMessageLa
yer() {
|
|
|
|
|
66 |
|
re
turn layer
;
|
|
|
|
|
67 |
|
}
|
|
|
|
|
68 |
|
|
|
|
|
|
69 |
|
|
|
|
|
|
70 |
|
@Overr
ide
|
|
|
|
|
71 |
|
public
String ge
tAppContex
t() {
|
|
|
|
|
72 |
|
re
turn appCo
ntext;
|
|
|
|
|
73 |
|
}
|
|
|
|
|
74 |
|
|
|
|
|
|
75 |
|
|
|
|
|
|
76 |
|
@Overr
ide
|
|
|
|
|
77 |
|
public
String ge
tAuthConte
xtID(Messa
geInfo mes
sageInfo)
{
|
|
|
|
|
78 |
|
re
turn messa
geInfo.toS
tring();
|
|
|
|
|
79 |
|
}
|
|
|
|
|
80 |
|
|
|
|
|
|
81 |
|
|
|
|
|
|
82 |
|
@Overr
ide
|
|
|
|
|
83 |
|
public
void refr
esh() {
|
|
|
|
|
84 |
|
se
rverAuthCo
ntext = nu
ll;
|
|
|
|
|
85 |
|
}
|
|
|
|
|
86 |
|
|
|
|
|
|
87 |
|
|
|
|
|
|
88 |
|
@Overr
ide
|
|
|
|
|
89 |
|
public
boolean i
sProtected
() {
|
|
|
|
|
90 |
|
re
turn false
;
|
|
|
|
|
91 |
|
}
|
|
|
|
|
92 |
|
|
|
|
|
|
93 |
|
|
|
|
|
|
94 |
|
@Suppr
essWarning
s({"rawtyp
es", "unch
ecked"}) /
/ JASPIC A
PI uses ra
w types
|
|
|
|
|
95 |
|
@Overr
ide
|
|
|
|
|
96 |
|
public
ServerAut
hContext g
etAuthCont
ext(String
authConte
xtID, Subj
ect servic
eSubject,
|
|
|
|
|
97 |
|
Map prop
erties) th
rows AuthE
xception {
|
|
|
|
|
98 |
|
Se
rverAuthCo
ntext serv
erAuthCont
ext = this
.serverAut
hContext;
|
|
|
|
|
99 |
|
if
(serverAu
thContext
== null) {
|
|
|
|
|
100 |
|
synchron
ized (this
) {
|
|
|
|
|
101 |
|
if (
this.serve
rAuthConte
xt == null
) {
|
|
|
|
|
102 |
|
Map<String
,String> m
ergedPrope
rties = ne
w HashMap<
>();
|
|
|
|
|
103 |
|
if (this.p
roperties
!= null) {
|
|
|
|
|
104 |
|
merged
Properties
.putAll(th
is.propert
ies);
|
|
|
|
|
105 |
|
}
|
|
|
|
|
106 |
|
if (proper
ties != nu
ll) {
|
|
|
|
|
107 |
|
merged
Properties
.putAll(pr
operties);
|
|
|
|
|
108 |
|
}
|
|
|
|
|
109 |
|
|
|
|
|
|
110 |
|
List<Serve
rAuthModul
e> modules
= new Arr
ayList<>()
;
|
|
|
|
|
111 |
|
int module
Index = 1;
|
|
|
|
|
112 |
|
String key
= SERVER_
AUTH_MODUL
E_KEY_PREF
IX + modul
eIndex;
|
|
|
|
|
113 |
|
String mod
uleClassNa
me = merge
dPropertie
s.get(key)
;
|
|
|
|
|
114 |
|
while (mod
uleClassNa
me != null
) {
|
|
|
|
|
115 |
|
try {
|
|
|
|
|
116 |
|
Cl
ass<?> cla
zz = Class
.forName(m
oduleClass
Name);
|
|
|
|
|
117 |
|
Se
rverAuthMo
dule modul
e =
|
|
|
|
|
118 |
|
(Ser
verAuthMod
ule) clazz
.getConstr
uctor().ne
wInstance(
);
|
|
|
|
|
119 |
|
mo
dule.initi
alize(null
, null, ha
ndler, mer
gedPropert
ies);
|
|
|
|
|
120 |
|
mo
dules.add(
module);
|
|
|
|
|
121 |
|
} catc
h (ClassNo
tFoundExce
ption | In
stantiatio
nException
|
|
|
|
|
|
122 |
|
IllegalA
ccessExcep
tion | Ill
egalArgume
ntExceptio
n |
|
|
|
|
|
123 |
|
Invocati
onTargetEx
ception |
NoSuchMeth
odExceptio
n |
|
|
|
|
|
124 |
|
Security
Exception
e) {
|
|
|
|
|
125 |
|
Au
thExceptio
n ae = new
AuthExcep
tion();
|
|
|
|
|
126 |
|
ae
.initCause
(e);
|
|
|
|
|
127 |
|
th
row ae;
|
|
|
|
|
128 |
|
}
|
|
|
|
|
129 |
|
|
|
|
|
|
130 |
|
// Loo
k for the
next modul
e
|
|
|
|
|
131 |
|
module
Index++;
|
|
|
|
|
132 |
|
key =
SERVER_AUT
H_MODULE_K
EY_PREFIX
+ moduleIn
dex;
|
|
|
|
|
133 |
|
module
ClassName
= mergedPr
operties.g
et(key);
|
|
|
|
|
134 |
|
}
|
|
|
|
|
135 |
|
|
|
|
|
|
136 |
|
if (module
s.size() =
= 0) {
|
|
|
|
|
137 |
|
throw
new AuthEx
ception(sm
.getString
("simpleSe
rverAuthCo
nfig.noMod
ules"));
|
|
|
|
|
138 |
|
}
|
|
|
|
|
139 |
|
|
|
|
|
|
140 |
|
this.serve
rAuthConte
xt = creat
eServerAut
hContext(m
odules);
|
|
|
|
|
141 |
|
}
|
|
|
|
|
142 |
|
serv
erAuthCont
ext = this
.serverAut
hContext;
|
|
|
|
|
143 |
|
}
|
|
|
|
|
144 |
|
}
|
|
|
|
|
145 |
|
|
|
|
|
|
146 |
|
re
turn serve
rAuthConte
xt;
|
|
|
|
|
147 |
|
}
|
|
|
|
|
148 |
|
|
|
|
|
|
149 |
|
|
|
|
|
|
150 |
|
protec
ted Server
AuthContex
t createSe
rverAuthCo
ntext(List
<ServerAut
hModule> m
odules) {
|
|
|
|
|
151 |
|
re
turn new S
impleServe
rAuthConte
xt(modules
);
|
|
|
|
|
152 |
|
}
|
|
|
|
|
153 |
|
}
|