35
35
import org .opensolaris .opengrok .authorization .IAuthorizationPlugin ;
36
36
import org .opensolaris .opengrok .configuration .Group ;
37
37
import org .opensolaris .opengrok .configuration .Project ;
38
- import org .opensolaris .opengrok .configuration .RuntimeEnvironment ;
39
38
40
39
/**
41
40
* Abstract class for all plug-ins working with LDAP. Takes care of
42
41
* <ul>
43
42
* <li>controlling the established session</li>
44
43
* <li>controlling if the session belongs to the user</li>
45
- * <li>controlling plug-in version</li>
46
44
* </ul>
47
45
*
48
46
* <p>
@@ -63,9 +61,9 @@ abstract public class AbstractLdapPlugin implements IAuthorizationPlugin {
63
61
protected static final String CONFIGURATION_PARAM = "configuration" ;
64
62
protected static final String FAKE_PARAM = "fake" ;
65
63
66
- protected String SESSION_USERNAME = "opengrok-group- plugin-username " ;
67
- protected String SESSION_ESTABLISHED = "opengrok-group-plugin-session-established " ;
68
- protected String SESSION_VERSION = "opengrok-group-plugin- session-version " ;
64
+ private final static String SESSION_PREFIX = "opengrok-abstract-ldap- plugin-" ;
65
+ protected String SESSION_USERNAME = SESSION_PREFIX + "username " ;
66
+ protected String SESSION_ESTABLISHED = SESSION_PREFIX + " session-established " ;
69
67
70
68
/**
71
69
* Configuration for the LDAP servers.
@@ -86,7 +84,6 @@ abstract public class AbstractLdapPlugin implements IAuthorizationPlugin {
86
84
public AbstractLdapPlugin () {
87
85
SESSION_USERNAME += "-" + nextId ;
88
86
SESSION_ESTABLISHED += "-" + nextId ;
89
- SESSION_VERSION += "-" + nextId ;
90
87
nextId ++;
91
88
}
92
89
@@ -197,11 +194,8 @@ public AbstractLdapProvider getLdapProvider() {
197
194
* @return true if it does; false otherwise
198
195
*/
199
196
protected boolean isSameUser (String sessionUsername , String authUser ) {
200
- if (sessionUsername != null
201
- && sessionUsername .equals (authUser )) {
202
- return true ;
203
- }
204
- return false ;
197
+ return sessionUsername != null
198
+ && sessionUsername .equals (authUser );
205
199
}
206
200
207
201
/**
@@ -214,7 +208,6 @@ protected boolean isSameUser(String sessionUsername, String authUser) {
214
208
protected boolean sessionExists (HttpServletRequest req ) {
215
209
return req != null && req .getSession () != null
216
210
&& req .getSession ().getAttribute (SESSION_ESTABLISHED ) != null
217
- && req .getSession ().getAttribute (SESSION_VERSION ) != null
218
211
&& req .getSession ().getAttribute (SESSION_USERNAME ) != null ;
219
212
}
220
213
@@ -234,39 +227,40 @@ protected boolean sessionExists(HttpServletRequest req) {
234
227
@ SuppressWarnings ("unchecked" )
235
228
private void ensureSessionExists (HttpServletRequest req ) {
236
229
User user ;
230
+
237
231
if (req .getSession () == null ) {
238
232
// old/invalid request (should not happen)
239
233
return ;
240
234
}
241
-
235
+
236
+ // The cast to User should not be problem as this object is stored
237
+ // in the request itself (as opposed to in the session).
242
238
if ((user = (User ) req .getAttribute (UserPlugin .REQUEST_ATTR )) == null ) {
243
- updateSession (req , null , false , getPluginVersion () );
239
+ updateSession (req , null , false );
244
240
return ;
245
241
}
246
242
247
243
if (sessionExists (req )
248
244
// we've already filled the groups and projects
249
245
&& (boolean ) req .getSession ().getAttribute (SESSION_ESTABLISHED )
250
246
// the session belongs to the user from the request
251
- && isSameUser ((String ) req .getSession ().getAttribute (SESSION_USERNAME ), user .getUsername ())
252
- // and this is not a case when we want to renew all sessions
253
- && !isSessionInvalidated (req )) {
247
+ && isSameUser ((String ) req .getSession ().getAttribute (SESSION_USERNAME ), user .getUsername ())) {
254
248
/**
255
249
* The session is already filled so no need to
256
250
* {@link #updateSession()}
257
251
*/
258
252
return ;
259
253
}
260
254
261
- updateSession (req , user .getUsername (), false , getPluginVersion () );
255
+ updateSession (req , user .getUsername (), false );
262
256
263
257
if (ldap == null ) {
264
258
return ;
265
259
}
266
260
267
261
fillSession (req , user );
268
262
269
- updateSession (req , user .getUsername (), true , getPluginVersion () );
263
+ updateSession (req , user .getUsername (), true );
270
264
}
271
265
272
266
/**
@@ -275,44 +269,12 @@ && isSameUser((String) req.getSession().getAttribute(SESSION_USERNAME), user.get
275
269
* @param req the request
276
270
* @param username new username
277
271
* @param established new value for established
278
- * @param sessionV new value for session version
279
272
*/
280
273
protected void updateSession (HttpServletRequest req ,
281
274
String username ,
282
- boolean established ,
283
- int sessionV ) {
275
+ boolean established ) {
284
276
setSessionEstablished (req , established );
285
277
setSessionUsername (req , username );
286
- setSessionVersion (req , sessionV );
287
- }
288
-
289
- /**
290
- * Is this session marked as invalid?
291
- *
292
- * @param req the request
293
- * @return true if it is; false otherwise
294
- */
295
- protected boolean isSessionInvalidated (HttpServletRequest req ) {
296
- Integer version ;
297
- if ((version = (Integer ) req .getAttribute (SESSION_VERSION )) != null ) {
298
- return version != getPluginVersion ();
299
- }
300
- if ((version = (Integer ) req .getSession ().getAttribute (SESSION_VERSION )) != null ) {
301
- req .setAttribute (SESSION_VERSION , version );
302
- return version != getPluginVersion ();
303
- }
304
- return true ;
305
- }
306
-
307
- /**
308
- * Set session version into the session.
309
- *
310
- * @param req request containing the session
311
- * @param value the value
312
- */
313
- protected void setSessionVersion (HttpServletRequest req , Integer value ) {
314
- req .getSession ().setAttribute (SESSION_VERSION , value );
315
- req .setAttribute (SESSION_VERSION , value );
316
278
}
317
279
318
280
/**
@@ -335,15 +297,6 @@ protected void setSessionUsername(HttpServletRequest req, String value) {
335
297
req .getSession ().setAttribute (SESSION_USERNAME , value );
336
298
}
337
299
338
- /**
339
- * Return the current plug-in version tracked by the authorization framework.
340
- *
341
- * @return the version
342
- */
343
- protected static int getPluginVersion () {
344
- return RuntimeEnvironment .getInstance ().getPluginVersion ();
345
- }
346
-
347
300
@ Override
348
301
public boolean isAllowed (HttpServletRequest request , Project project ) {
349
302
ensureSessionExists (request );
0 commit comments