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