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 package net.sf.jguard.core.authentication.bindings;
29
30
31 import net.sf.jguard.core.CoreConstants;
32 import net.sf.jguard.core.authentication.AccessContext;
33 import net.sf.jguard.core.authentication.AuthenticationUtils;
34
35 import javax.security.auth.login.Configuration;
36
37
38 public abstract class AbstractAuthenticationBindings implements AuthenticationBindings {
39
40
41 protected String authScheme = null;
42 private String scope;
43 protected AccessContext context;
44 protected AuthenticationBindingsFactory factory;
45
46 public AbstractAuthenticationBindings(AuthenticationBindingsFactory factory, String authenticationScope, AccessContext context) {
47 super();
48 if (CoreConstants.JVM_SCOPE.equalsIgnoreCase(authenticationScope)) {
49 scope = CoreConstants.JVM_SCOPE;
50 } else {
51 scope = CoreConstants.LOCAL_SCOPE;
52 }
53 this.context = context;
54 this.factory = factory;
55
56 }
57
58
59
60
61
62
63
64 public AuthenticationUtils getAuthenticationUtils() {
65 AuthenticationUtils authenticationUtils = null;
66 if (this instanceof StatefulAuthenticationBindings) {
67 authenticationUtils = (AuthenticationUtils) ((StatefulAuthenticationBindings) this).getSessionAttribute(CoreConstants.AUTHN_UTILS);
68
69 }
70
71
72 if (authenticationUtils == null) {
73 Configuration configuration = (Configuration) this.getApplicationAttribute(CoreConstants.JGUARD_CONFIGURATION);
74 if (CoreConstants.LOCAL_SCOPE.equals(scope) && configuration != null) {
75 authenticationUtils = new AuthenticationUtils(configuration);
76 } else {
77 authenticationUtils = new AuthenticationUtils();
78 }
79 if (this instanceof StatefulAuthenticationBindings) {
80 ((StatefulAuthenticationBindings) this).setSessionAttribute(CoreConstants.AUTHN_UTILS, authenticationUtils);
81 }
82 }
83 return authenticationUtils;
84 }
85
86
87 public AccessContext getContext() {
88 return context;
89 }
90
91 public AuthenticationBindingsFactory getAuthenticationBindingsFactory() {
92 return factory;
93 }
94
95
96
97
98 public String getScope() {
99 return scope;
100 }
101
102 }