32
32
import opengrok .auth .plugin .ldap .AbstractLdapProvider ;
33
33
import opengrok .auth .plugin .ldap .FakeLdapFacade ;
34
34
import opengrok .auth .plugin .ldap .LdapFacade ;
35
+ import org .opensolaris .opengrok .authorization .AuthorizationFramework ;
35
36
import org .opensolaris .opengrok .authorization .IAuthorizationPlugin ;
36
37
import org .opensolaris .opengrok .configuration .Group ;
37
38
import org .opensolaris .opengrok .configuration .Project ;
42
43
* <ul>
43
44
* <li>controlling the established session</li>
44
45
* <li>controlling if the session belongs to the user</li>
45
- * <li>controlling plug-in version</li>
46
46
* </ul>
47
47
*
48
48
* <p>
@@ -63,9 +63,9 @@ abstract public class AbstractLdapPlugin implements IAuthorizationPlugin {
63
63
protected static final String CONFIGURATION_PARAM = "configuration" ;
64
64
protected static final String FAKE_PARAM = "fake" ;
65
65
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 " ;
66
+ private final static String SESSION_PREFIX = "opengrok-abstract-ldap- plugin-" ;
67
+ protected String SESSION_USERNAME = SESSION_PREFIX + "username " ;
68
+ protected String SESSION_ESTABLISHED = SESSION_PREFIX + " session-established " ;
69
69
70
70
/**
71
71
* Configuration for the LDAP servers.
@@ -86,7 +86,6 @@ abstract public class AbstractLdapPlugin implements IAuthorizationPlugin {
86
86
public AbstractLdapPlugin () {
87
87
SESSION_USERNAME += "-" + nextId ;
88
88
SESSION_ESTABLISHED += "-" + nextId ;
89
- SESSION_VERSION += "-" + nextId ;
90
89
nextId ++;
91
90
}
92
91
@@ -197,11 +196,8 @@ public AbstractLdapProvider getLdapProvider() {
197
196
* @return true if it does; false otherwise
198
197
*/
199
198
protected boolean isSameUser (String sessionUsername , String authUser ) {
200
- if (sessionUsername != null
201
- && sessionUsername .equals (authUser )) {
202
- return true ;
203
- }
204
- return false ;
199
+ return sessionUsername != null
200
+ && sessionUsername .equals (authUser );
205
201
}
206
202
207
203
/**
@@ -214,7 +210,6 @@ protected boolean isSameUser(String sessionUsername, String authUser) {
214
210
protected boolean sessionExists (HttpServletRequest req ) {
215
211
return req != null && req .getSession () != null
216
212
&& req .getSession ().getAttribute (SESSION_ESTABLISHED ) != null
217
- && req .getSession ().getAttribute (SESSION_VERSION ) != null
218
213
&& req .getSession ().getAttribute (SESSION_USERNAME ) != null ;
219
214
}
220
215
@@ -234,39 +229,40 @@ protected boolean sessionExists(HttpServletRequest req) {
234
229
@ SuppressWarnings ("unchecked" )
235
230
private void ensureSessionExists (HttpServletRequest req ) {
236
231
User user ;
232
+
237
233
if (req .getSession () == null ) {
238
234
// old/invalid request (should not happen)
239
235
return ;
240
236
}
241
-
237
+
238
+ // The cast to User should not be problem as this object is stored
239
+ // in the request itself (as opposed to in the session).
242
240
if ((user = (User ) req .getAttribute (UserPlugin .REQUEST_ATTR )) == null ) {
243
- updateSession (req , null , false , getPluginVersion () );
241
+ updateSession (req , null , false );
244
242
return ;
245
243
}
246
244
247
245
if (sessionExists (req )
248
246
// we've already filled the groups and projects
249
247
&& (boolean ) req .getSession ().getAttribute (SESSION_ESTABLISHED )
250
248
// 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 )) {
249
+ && isSameUser ((String ) req .getSession ().getAttribute (SESSION_USERNAME ), user .getUsername ())) {
254
250
/**
255
251
* The session is already filled so no need to
256
252
* {@link #updateSession()}
257
253
*/
258
254
return ;
259
255
}
260
256
261
- updateSession (req , user .getUsername (), false , getPluginVersion () );
257
+ updateSession (req , user .getUsername (), false );
262
258
263
259
if (ldap == null ) {
264
260
return ;
265
261
}
266
262
267
263
fillSession (req , user );
268
264
269
- updateSession (req , user .getUsername (), true , getPluginVersion () );
265
+ updateSession (req , user .getUsername (), true );
270
266
}
271
267
272
268
/**
@@ -275,44 +271,12 @@ && isSameUser((String) req.getSession().getAttribute(SESSION_USERNAME), user.get
275
271
* @param req the request
276
272
* @param username new username
277
273
* @param established new value for established
278
- * @param sessionV new value for session version
279
274
*/
280
275
protected void updateSession (HttpServletRequest req ,
281
276
String username ,
282
- boolean established ,
283
- int sessionV ) {
277
+ boolean established ) {
284
278
setSessionEstablished (req , established );
285
279
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
280
}
317
281
318
282
/**
@@ -335,15 +299,6 @@ protected void setSessionUsername(HttpServletRequest req, String value) {
335
299
req .getSession ().setAttribute (SESSION_USERNAME , value );
336
300
}
337
301
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
302
@ Override
348
303
public boolean isAllowed (HttpServletRequest request , Project project ) {
349
304
ensureSessionExists (request );
0 commit comments