|
|
|
|
1 |
|
/*
|
|
1 |
|
/*
|
|
|
|
|
2 |
|
* License
d to the A
pache Soft
ware Found
ation (ASF
) under on
e or more
|
|
2 |
|
* License
d to the A
pache Soft
ware Found
ation (ASF
) under on
e or more
|
|
|
|
|
3 |
|
* contrib
utor licen
se agreeme
nts. See
the NOTICE
file dist
ributed wi
th
|
|
3 |
|
* contrib
utor licen
se agreeme
nts. See
the NOTICE
file dist
ributed wi
th
|
|
|
|
|
4 |
|
* this wo
rk for add
itional in
formation
regarding
copyright
ownership.
|
|
4 |
|
* this wo
rk for add
itional in
formation
regarding
copyright
ownership.
|
|
|
|
|
5 |
|
* The ASF
licenses
this file
to You und
er the Apa
che Licens
e, Version
2.0
|
|
5 |
|
* The ASF
licenses
this file
to You und
er the Apa
che Licens
e, Version
2.0
|
|
|
|
|
6 |
|
* (the "L
icense");
you may no
t use this
file exce
pt in comp
liance wit
h
|
|
6 |
|
* (the "L
icense");
you may no
t use this
file exce
pt in comp
liance wit
h
|
|
|
|
|
7 |
|
* the Lic
ense. You
may obtai
n a copy o
f the Lice
nse at
|
|
7 |
|
* the Lic
ense. You
may obtai
n a copy o
f the Lice
nse at
|
|
|
|
|
8 |
|
*
|
|
8 |
|
*
|
|
|
|
|
9 |
|
* ht
tp://www.a
pache.org/
licenses/L
ICENSE-2.0
|
|
9 |
|
* ht
tp://www.a
pache.org/
licenses/L
ICENSE-2.0
|
|
|
|
|
10 |
|
*
|
|
10 |
|
*
|
|
|
|
|
11 |
|
* Unless
required b
y applicab
le law or
agreed to
in writing
, software
|
|
11 |
|
* Unless
required b
y applicab
le law or
agreed to
in writing
, software
|
|
|
|
|
12 |
|
* distrib
uted under
the Licen
se is dist
ributed on
an "AS IS
" BASIS,
|
|
12 |
|
* distrib
uted under
the Licen
se is dist
ributed on
an "AS IS
" BASIS,
|
|
|
|
|
13 |
|
* WITHOUT
WARRANTIE
S OR CONDI
TIONS OF A
NY KIND, e
ither expr
ess or imp
lied.
|
|
13 |
|
* WITHOUT
WARRANTIE
S OR CONDI
TIONS OF A
NY KIND, e
ither expr
ess or imp
lied.
|
|
|
|
|
14 |
|
* See the
License f
or the spe
cific lang
uage gover
ning permi
ssions and
|
|
14 |
|
* See the
License f
or the spe
cific lang
uage gover
ning permi
ssions and
|
|
|
|
|
15 |
|
* limitat
ions under
the Licen
se.
|
|
15 |
|
* limitat
ions under
the Licen
se.
|
|
|
|
|
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.io.IOExc
eption;
|
|
19 |
|
import jav
a.io.IOExc
eption;
|
|
|
|
|
20 |
|
import jav
a.security
.Principal
;
|
|
20 |
|
import jav
a.security
.Principal
;
|
|
|
|
|
21 |
|
import jav
a.util.Arr
ays;
|
|
21 |
|
import jav
a.util.Arr
ays;
|
|
|
|
|
22 |
|
import jav
a.util.Col
lections;
|
|
22 |
|
import jav
a.util.Col
lections;
|
|
|
|
|
23 |
|
import jav
a.util.Lis
t;
|
|
23 |
|
import jav
a.util.Lis
t;
|
|
|
|
|
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
back;
|
|
26 |
|
import jav
ax.securit
y.auth.cal
lback.Call
back;
|
|
|
|
|
27 |
|
import jav
ax.securit
y.auth.cal
lback.Call
backHandle
r;
|
|
27 |
|
import jav
ax.securit
y.auth.cal
lback.Call
backHandle
r;
|
|
|
|
|
28 |
|
import jav
ax.securit
y.auth.cal
lback.Unsu
pportedCal
lbackExcep
tion;
|
|
28 |
|
import jav
ax.securit
y.auth.cal
lback.Unsu
pportedCal
lbackExcep
tion;
|
|
|
|
|
29 |
|
import jav
ax.securit
y.auth.mes
sage.callb
ack.Caller
PrincipalC
allback;
|
|
29 |
|
import jav
ax.securit
y.auth.mes
sage.callb
ack.Caller
PrincipalC
allback;
|
|
|
|
|
30 |
|
import jav
ax.securit
y.auth.mes
sage.callb
ack.GroupP
rincipalCa
llback;
|
|
30 |
|
import jav
ax.securit
y.auth.mes
sage.callb
ack.GroupP
rincipalCa
llback;
|
|
|
|
|
31 |
|
|
|
31 |
|
|
|
|
|
|
32 |
|
import org
.apache.ca
talina.rea
lm.Generic
Principal;
|
|
32 |
|
import org
.apache.ca
talina.rea
lm.Generic
Principal;
|
|
|
|
|
33 |
|
import org
.apache.ju
li.logging
.Log;
|
|
33 |
|
import org
.apache.ju
li.logging
.Log;
|
|
|
|
|
34 |
|
import org
.apache.ju
li.logging
.LogFactor
y;
|
|
34 |
|
import org
.apache.ju
li.logging
.LogFactor
y;
|
|
|
|
|
35 |
|
import org
.apache.to
mcat.util.
res.String
Manager;
|
|
35 |
|
import org
.apache.to
mcat.util.
res.String
Manager;
|
|
|
|
|
36 |
|
|
|
36 |
|
|
|
|
|
|
37 |
|
/**
|
|
37 |
|
/**
|
|
|
|
|
38 |
|
* Impleme
nted as a
singleton
since the
class is s
tateless.
|
|
38 |
|
* Impleme
nted as a
singleton
since the
class is s
tateless.
|
|
|
|
|
39 |
|
*/
|
|
39 |
|
*/
|
|
|
|
|
40 |
|
public cla
ss Callbac
kHandlerIm
pl impleme
nts Callba
ckHandler
{
|
|
40 |
|
public cla
ss Callbac
kHandlerIm
pl impleme
nts Callba
ckHandler
{
|
|
|
|
|
41 |
|
|
|
41 |
|
|
|
|
|
|
42 |
|
privat
e static f
inal Log l
og = LogFa
ctory.getL
og(Callbac
kHandlerIm
pl.class);
|
|
42 |
|
privat
e static f
inal Log l
og = LogFa
ctory.getL
og(Callbac
kHandlerIm
pl.class);
|
|
|
|
|
43 |
|
privat
e static f
inal Strin
gManager s
m = String
Manager.ge
tManager(C
allbackHan
dlerImpl.c
lass);
|
|
43 |
|
privat
e static f
inal Strin
gManager s
m = String
Manager.ge
tManager(C
allbackHan
dlerImpl.c
lass);
|
|
|
|
|
44 |
|
|
|
44 |
|
|
|
|
|
|
45 |
|
privat
e static C
allbackHan
dler insta
nce;
|
|
45 |
|
privat
e static C
allbackHan
dler insta
nce;
|
|
|
|
|
46 |
|
|
|
46 |
|
|
|
|
|
|
47 |
|
|
|
47 |
|
|
|
|
|
|
48 |
|
static
{
|
|
48 |
|
static
{
|
|
|
|
|
49 |
|
in
stance = n
ew Callbac
kHandlerIm
pl();
|
|
49 |
|
in
stance = n
ew Callbac
kHandlerIm
pl();
|
|
|
|
|
50 |
|
}
|
|
50 |
|
}
|
|
|
|
|
51 |
|
|
|
51 |
|
|
|
|
|
|
52 |
|
|
|
52 |
|
|
|
|
|
|
53 |
|
public
static Ca
llbackHand
ler getIns
tance() {
|
|
53 |
|
public
static Ca
llbackHand
ler getIns
tance() {
|
|
|
|
|
54 |
|
re
turn insta
nce;
|
|
54 |
|
re
turn insta
nce;
|
|
|
|
|
55 |
|
}
|
|
55 |
|
}
|
|
|
|
|
56 |
|
|
|
56 |
|
|
|
|
|
|
57 |
|
|
|
57 |
|
|
|
|
|
|
58 |
|
privat
e Callbac
kHandlerIm
pl() {
|
|
58 |
|
privat
e Callbac
kHandlerIm
pl() {
|
|
|
|
|
59 |
|
//
Hide defa
ult constr
uctor
|
|
59 |
|
//
Hide defa
ult constr
uctor
|
|
|
|
|
60 |
|
}
|
|
60 |
|
}
|
|
|
|
|
61 |
|
|
|
61 |
|
|
|
|
|
|
62 |
|
|
|
62 |
|
|
|
|
|
|
63 |
|
@Overr
ide
|
|
63 |
|
@Overr
ide
|
|
|
|
|
64 |
|
public
void hand
le(Callbac
k[] callba
cks) throw
s IOExcept
ion, Unsup
portedCall
backExcept
ion {
|
|
64 |
|
public
void hand
le(Callbac
k[] callba
cks) throw
s IOExcept
ion, Unsup
portedCall
backExcept
ion {
|
|
|
|
|
65 |
|
|
|
65 |
|
|
|
|
|
|
66 |
|
St
ring name
= null;
|
|
66 |
|
St
ring name
= null;
|
|
|
|
|
67 |
|
Pr
incipal pr
incipal =
null;
|
|
67 |
|
Pr
incipal pr
incipal =
null;
|
|
|
|
|
68 |
|
Su
bject subj
ect = null
;
|
|
68 |
|
Su
bject subj
ect = null
;
|
|
|
|
|
69 |
|
St
ring[] gro
ups = null
;
|
|
69 |
|
St
ring[] gro
ups = null
;
|
|
|
|
|
70 |
|
|
|
70 |
|
|
|
|
|
|
71 |
|
if
(callback
s != null)
{
|
|
71 |
|
if
(callback
s != null)
{
|
|
|
|
|
72 |
|
// Need
to combine
data from
multiple
callbacks
so use thi
s to hold
|
|
72 |
|
// Need
to combine
data from
multiple
callbacks
so use thi
s to hold
|
|
|
|
|
73 |
|
// the d
ata
|
|
73 |
|
// the d
ata
|
|
|
|
|
74 |
|
// Proce
ss the cal
lbacks
|
|
74 |
|
// Proce
ss the cal
lbacks
|
|
|
|
|
75 |
|
for (Cal
lback call
back : cal
lbacks) {
|
|
75 |
|
for (Cal
lback call
back : cal
lbacks) {
|
|
|
|
|
76 |
|
if (
callback i
nstanceof
CallerPrin
cipalCallb
ack) {
|
|
76 |
|
if (
callback i
nstanceof
CallerPrin
cipalCallb
ack) {
|
|
|
|
|
77 |
|
CallerPrin
cipalCallb
ack cpc =
(CallerPri
ncipalCall
back) call
back;
|
|
77 |
|
CallerPrin
cipalCallb
ack cpc =
(CallerPri
ncipalCall
back) call
back;
|
|
|
|
|
78 |
|
name = cpc
.getName()
;
|
|
78 |
|
name = cpc
.getName()
;
|
|
|
|
|
79 |
|
principal
= cpc.getP
rincipal()
;
|
|
79 |
|
principal
= cpc.getP
rincipal()
;
|
|
|
|
|
80 |
|
subject =
cpc.getSub
ject();
|
|
80 |
|
subject =
cpc.getSub
ject();
|
|
|
|
|
81 |
|
} el
se if (cal
lback inst
anceof Gro
upPrincipa
lCallback)
{
|
|
81 |
|
} el
se if (cal
lback inst
anceof Gro
upPrincipa
lCallback)
{
|
|
|
|
|
82 |
|
GroupPrinc
ipalCallba
ck gpc = (
GroupPrinc
ipalCallba
ck) callba
ck;
|
|
82 |
|
GroupPrinc
ipalCallba
ck gpc = (
GroupPrinc
ipalCallba
ck) callba
ck;
|
|
|
|
|
83 |
|
groups = g
pc.getGrou
ps();
|
|
83 |
|
groups = g
pc.getGrou
ps();
|
|
|
|
|
84 |
|
} el
se {
|
|
84 |
|
} el
se {
|
|
|
|
|
85 |
|
log.error(
sm.getStri
ng("callba
ckHandlerI
mpl.jaspic
CallbackMi
ssing",
|
|
85 |
|
log.error(
sm.getStri
ng("callba
ckHandlerI
mpl.jaspic
CallbackMi
ssing",
|
|
|
|
|
86 |
|
ca
llback.get
Class().ge
tName()));
|
|
86 |
|
ca
llback.get
Class().ge
tName()));
|
|
|
|
|
87 |
|
}
|
|
87 |
|
}
|
|
|
|
|
88 |
|
}
|
|
88 |
|
}
|
|
|
|
|
89 |
|
|
|
89 |
|
|
|
|
|
|
90 |
|
// Creat
e the Gene
ricPrincip
al
|
|
90 |
|
// Creat
e the Gene
ricPrincip
al
|
|
|
|
|
91 |
|
Principa
l gp = get
Principal(
principal,
name, gro
ups);
|
|
91 |
|
Principa
l gp = get
Principal(
principal,
name, gro
ups);
|
|
|
|
|
92 |
|
if (subj
ect != nul
l && gp !=
null) {
|
|
92 |
|
if (subj
ect != nul
l && gp !=
null) {
|
|
|
|
|
93 |
|
subj
ect.getPri
vateCreden
tials().ad
d(gp);
|
|
93 |
|
subj
ect.getPri
vateCreden
tials().ad
d(gp);
|
|
|
|
|
94 |
|
}
|
|
94 |
|
}
|
|
|
|
|
95 |
|
}
|
|
95 |
|
}
|
|
|
|
|
96 |
|
}
|
|
96 |
|
}
|
|
|
|
|
97 |
|
|
|
97 |
|
|
|
|
|
|
98 |
|
|
|
98 |
|
|
|
|
|
|
99 |
|
privat
e Principa
l getPrinc
ipal(Princ
ipal princ
ipal, Stri
ng name, S
tring[] gr
oups) {
|
|
99 |
|
privat
e Principa
l getPrinc
ipal(Princ
ipal princ
ipal, Stri
ng name, S
tring[] gr
oups) {
|
|
|
|
|
100 |
|
//
If the Pr
incipal is
cached in
the sessi
on JASPIC
may simply
return it
|
|
100 |
|
//
If the Pr
incipal is
cached in
the sessi
on JASPIC
may simply
return it
|
|
|
|
|
101 |
|
if
(principa
l instance
of Generic
Principal)
{
|
|
101 |
|
if
(principa
l instance
of Generic
Principal)
{
|
|
|
|
|
102 |
|
return p
rincipal;
|
|
102 |
|
return p
rincipal;
|
|
|
|
|
103 |
|
}
|
|
103 |
|
}
|
|
|
|
|
104 |
|
if
(name ==
null && pr
incipal !=
null) {
|
|
104 |
|
if
(name ==
null && pr
incipal !=
null) {
|
|
|
|
|
105 |
|
name = p
rincipal.g
etName();
|
|
105 |
|
name = p
rincipal.g
etName();
|
|
|
|
|
106 |
|
}
|
|
106 |
|
}
|
|
|
|
|
107 |
|
if
(name ==
null) {
|
|
107 |
|
if
(name ==
null) {
|
|
|
|
|
108 |
|
return n
ull;
|
|
108 |
|
return n
ull;
|
|
|
|
|
109 |
|
}
|
|
109 |
|
}
|
|
|
|
|
110 |
|
Li
st<String>
roles;
|
|
110 |
|
Li
st<String>
roles;
|
|
|
|
|
111 |
|
if
(groups =
= null ||
groups.len
gth == 0)
{
|
|
111 |
|
if
(groups =
= null ||
groups.len
gth == 0)
{
|
|
|
|
|
112 |
|
roles =
Collection
s.emptyLis
t();
|
|
112 |
|
roles =
Collection
s.emptyLis
t();
|
|
|
|
|
113 |
|
}
else {
|
|
113 |
|
}
else {
|
|
|
|
|
114 |
|
roles =
Arrays.asL
ist(groups
);
|
|
114 |
|
roles =
Arrays.asL
ist(groups
);
|
|
|
|
|
115 |
|
}
|
|
115 |
|
}
|
|
|
|
|
116 |
|
|
|
116 |
|
|
|
|
|
|
117 |
|
re
turn new G
enericPrin
cipal(name
, null, ro
les, princ
ipal);
|
|
117 |
|
re
turn new G
enericPrin
cipal(name
, null, ro
les, princ
ipal);
|
|
|
|
|
118 |
|
}
|
|
118 |
|
}
|
|
|
|
|
119 |
|
}
|
|
119 |
|
}
|