001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.auth; 020 021import org.apache.logging.log4j.LogManager; 022import org.apache.logging.log4j.Logger; 023import org.apache.wiki.api.core.Engine; 024import org.apache.wiki.api.core.Session; 025import org.apache.wiki.api.exceptions.WikiException; 026import org.apache.wiki.api.spi.Wiki; 027import org.apache.wiki.auth.authorize.WebAuthorizer; 028import org.apache.wiki.auth.authorize.WebContainerAuthorizer; 029import org.apache.wiki.auth.login.AnonymousLoginModule; 030import org.apache.wiki.auth.login.CookieAssertionLoginModule; 031import org.apache.wiki.auth.login.CookieAuthenticationLoginModule; 032import org.apache.wiki.auth.login.UserDatabaseLoginModule; 033import org.apache.wiki.auth.login.WebContainerCallbackHandler; 034import org.apache.wiki.auth.login.WebContainerLoginModule; 035import org.apache.wiki.auth.login.WikiCallbackHandler; 036import org.apache.wiki.event.WikiEventListener; 037import org.apache.wiki.event.WikiEventManager; 038import org.apache.wiki.event.WikiSecurityEvent; 039import org.apache.wiki.i18n.InternationalizationManager; 040import org.apache.wiki.util.ClassUtil; 041import org.apache.wiki.util.Synchronizer; 042import org.apache.wiki.util.TextUtil; 043import org.apache.wiki.util.TimedCounterList; 044 045import javax.security.auth.Subject; 046import javax.security.auth.callback.CallbackHandler; 047import javax.security.auth.login.LoginException; 048import javax.security.auth.spi.LoginModule; 049import jakarta.servlet.http.HttpServletRequest; 050import jakarta.servlet.http.HttpSession; 051import java.security.Principal; 052import java.util.Collections; 053import java.util.Date; 054import java.util.HashMap; 055import java.util.HashSet; 056import java.util.List; 057import java.util.Map; 058import java.util.Properties; 059import java.util.ResourceBundle; 060import java.util.Set; 061import org.apache.wiki.WikiContext; 062import org.apache.wiki.WikiSession; 063import org.apache.wiki.auth.user.UserDatabase; 064import org.apache.wiki.auth.user.UserProfile; 065import java.util.concurrent.locks.ReentrantLock; 066 067 068/** 069 * Default implementation for {@link AuthenticationManager} 070 * 071 * {@inheritDoc} 072 * 073 * @since 2.3 074 */ 075public class DefaultAuthenticationManager implements AuthenticationManager { 076 077 /** How many milliseconds the logins are stored before they're cleaned away. */ 078 private static final long LASTLOGINS_CLEANUP_TIME = 10 * 60 * 1_000L; // Ten minutes 079 080 private static final long MAX_LOGIN_DELAY = 20 * 1_000L; // 20 seconds 081 082 private static final Logger LOG = LogManager.getLogger( DefaultAuthenticationManager.class ); 083 084 /** Empty Map passed to JAAS {@link #doJAASLogin(Class, CallbackHandler, Map)} method. */ 085 protected static final Map< String, String > EMPTY_MAP = Collections.unmodifiableMap( new HashMap<>() ); 086 087 /** Class (of type LoginModule) to use for custom authentication. */ 088 protected Class< ? extends LoginModule > m_loginModuleClass = UserDatabaseLoginModule.class; 089 090 /** Options passed to {@link LoginModule#initialize(Subject, CallbackHandler, Map, Map)}; 091 * initialized by {@link #initialize(Engine, Properties)}. */ 092 protected final Map< String, String > m_loginModuleOptions = new HashMap<>(); 093 094 /** The default {@link LoginModule} class name to use for custom authentication. */ 095 private static final String DEFAULT_LOGIN_MODULE = "org.apache.wiki.auth.login.UserDatabaseLoginModule"; 096 097 /** Empty principal set. */ 098 private static final Set<Principal> NO_PRINCIPALS = new HashSet<>(); 099 100 /** Static Boolean for lazily-initializing the "allows assertions" flag */ 101 private boolean m_allowsCookieAssertions = true; 102 103 private boolean m_throttleLogins = true; 104 105 private PasswordExpiry m_passwordExpiry = new PasswordExpiry( new Properties() ); 106 107 /** Static Boolean for lazily-initializing the "allows cookie authentication" flag */ 108 private boolean m_allowsCookieAuthentication; 109 110 private Engine m_engine; 111 112 /** If true, logs the IP address of the editor */ 113 private boolean m_storeIPAddress = true; 114 115 /** Keeps a list of the usernames who have attempted a login recently. */ 116 private final TimedCounterList< String > m_lastLoginAttempts = new TimedCounterList<>(); 117 118 /** 119 * A lock used to ensure thread safety when accessing shared resources. 120 * This lock provides more flexibility and capabilities than the intrinsic locking mechanism, 121 * such as the ability to attempt to acquire a lock with a timeout, or to interrupt a thread 122 * waiting to acquire a lock. 123 * 124 * @see java.util.concurrent.locks.ReentrantLock 125 */ 126 private final ReentrantLock lock = new ReentrantLock(); 127 128 /** 129 * {@inheritDoc} 130 */ 131 @Override 132 public void initialize( final Engine engine, final Properties props ) throws WikiException { 133 m_engine = engine; 134 m_storeIPAddress = TextUtil.getBooleanProperty( props, PROP_STOREIPADDRESS, m_storeIPAddress ); 135 136 // Should we allow cookies for assertions? (default: yes) 137 m_allowsCookieAssertions = TextUtil.getBooleanProperty( props, PROP_ALLOW_COOKIE_ASSERTIONS,true ); 138 139 // Should we allow cookies for authentication? (default: no) 140 m_allowsCookieAuthentication = TextUtil.getBooleanProperty( props, PROP_ALLOW_COOKIE_AUTH, false ); 141 142 // Should we throttle logins? (default: yes) 143 m_throttleLogins = TextUtil.getBooleanProperty( props, PROP_LOGIN_THROTTLING, true ); 144 145 // Should passwords expire? (default: no) 146 m_passwordExpiry = new PasswordExpiry( props ); 147 148 // Look up the LoginModule class 149 final String loginModuleClassName = TextUtil.getStringProperty( props, PROP_LOGIN_MODULE, DEFAULT_LOGIN_MODULE ); 150 try { 151 m_loginModuleClass = ClassUtil.findClass( "", loginModuleClassName ); 152 } catch( final ClassNotFoundException e ) { 153 LOG.error( e.getMessage(), e ); 154 throw new WikiException( "Could not instantiate LoginModule class.", e ); 155 } 156 157 // Initialize the LoginModule options 158 initLoginModuleOptions( props ); 159 } 160 161 /** 162 * {@inheritDoc} 163 */ 164 @Override 165 public boolean isContainerAuthenticated() { 166 try { 167 final Authorizer authorizer = m_engine.getManager( AuthorizationManager.class ).getAuthorizer(); 168 if ( authorizer instanceof WebContainerAuthorizer ) { 169 return ( ( WebContainerAuthorizer )authorizer ).isContainerAuthorized(); 170 } 171 } catch ( final WikiException e ) { 172 LOG.debug(e.getMessage(), e); 173 // It's probably ok to fail silently... 174 } 175 return false; 176 } 177 178 /** 179 * {@inheritDoc} 180 */ 181 @Override 182 public boolean login( final HttpServletRequest request ) throws WikiSecurityException { 183 final HttpSession httpSession = request.getSession(); 184 final Session session = SessionMonitor.getInstance( m_engine ).find( httpSession ); 185 final AuthenticationManager authenticationMgr = m_engine.getManager( AuthenticationManager.class ); 186 final AuthorizationManager authorizationMgr = m_engine.getManager( AuthorizationManager.class ); 187 CallbackHandler handler = null; 188 final Map< String, String > options = EMPTY_MAP; 189 190 // If user not authenticated, check if container logged them in, or if there's an authentication cookie 191 if ( !session.isAuthenticated() ) { 192 // Create a callback handler 193 handler = new WebContainerCallbackHandler( m_engine, request ); 194 195 // Execute the container login module, then (if that fails) the cookie auth module 196 Set< Principal > principals = authenticationMgr.doJAASLogin( WebContainerLoginModule.class, handler, options ); 197 if (principals.isEmpty() && authenticationMgr.allowsCookieAuthentication() ) { 198 principals = authenticationMgr.doJAASLogin( CookieAuthenticationLoginModule.class, handler, options ); 199 } 200 201 // If the container logged the user in successfully, tell the Session (and add all the Principals) 202 if (!principals.isEmpty()) { 203 rotateSessionAfterAuthentication( request, session ); 204 fireEvent( WikiSecurityEvent.LOGIN_AUTHENTICATED, getLoginPrincipal( principals ), session, request ); 205 for( final Principal principal : principals ) { 206 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, principal, session, request ); 207 } 208 209 // Add all appropriate Authorizer roles 210 injectAuthorizerRoles( session, authorizationMgr.getAuthorizer(), request ); 211 } 212 } 213 214 // If user still not authenticated, check if assertion cookie was supplied 215 if ( !session.isAuthenticated() && authenticationMgr.allowsCookieAssertions() ) { 216 // Execute the cookie assertion login module 217 final Set< Principal > principals = authenticationMgr.doJAASLogin( CookieAssertionLoginModule.class, handler, options ); 218 if (!principals.isEmpty()) { 219 fireEvent( WikiSecurityEvent.LOGIN_ASSERTED, getLoginPrincipal( principals ), session, request); 220 } 221 } 222 223 if (!session.isAnonymous()) { 224 final SessionMonitor monitor = SessionMonitor.getInstance(m_engine); 225 List<Session> sessions = monitor.findOtherSessionsByUsername(session.getLoginPrincipal().getName()); 226 StringBuilder sb = new StringBuilder(); 227 for (Session s : sessions) { 228 if (s.getRemoteAddress() != null && !s.getRemoteAddress().equals(request.getRemoteAddr())) { 229 sb.append(request.getRemoteAddr()).append(","); 230 } 231 } 232 if (sb.length() > 0) { 233 sb.append(request.getRemoteAddr()); 234 LOG.warn("AUDIT - New login for login '" + session.getLoginPrincipal().getName() + "' from " + request.getRemoteAddr() 235 + " however there are already concurrent logins from the following addresses " + sb.toString()); 236 fireEvent(WikiSecurityEvent.LOGIN_ALERT, session.getLoginPrincipal(), session, request); 237 } 238 } 239 240 // If user still anonymous, use the remote address 241 if( session.isAnonymous() ) { 242 final Set< Principal > principals = authenticationMgr.doJAASLogin( AnonymousLoginModule.class, handler, options ); 243 if(!principals.isEmpty()) { 244 fireEvent( WikiSecurityEvent.LOGIN_ANONYMOUS, getLoginPrincipal( principals ), session, request ); 245 return true; 246 } 247 } else { 248 //attempt to get the user profile 249 250 try { 251 UserManager mgr = m_engine.getManager(UserManager.class); 252 UserProfile profile = mgr.getUserDatabase().findByLoginName(session.getLoginPrincipal().getName()); 253 if (request.getSession().getAttribute("LOGINTIMESTAMPSET") == null) { 254 request.getSession().setAttribute("LOGINTIMESTAMPSET", true); 255 Long lastLoginAt = (Long) profile.getAttributes().get(UserProfile.ATTR_CURRENT_LOGIN_TIMESTAMP); 256 String oldIp = (String) profile.getAttributes().get(UserProfile.ATTR_CURRENT_LOGIN_IP); 257 if (lastLoginAt != null) { 258 profile.getAttributes().put(UserProfile.ATTR_PREVIOUS_LOGIN_TIMESTAMP, lastLoginAt); 259 } 260 if (oldIp != null) { 261 profile.getAttributes().put(UserProfile.ATTR_PREVIOUS_LOGIN_IP, oldIp); 262 } 263 profile.getAttributes().put(UserProfile.ATTR_CURRENT_LOGIN_IP, request.getRemoteAddr()); 264 profile.getAttributes().put(UserProfile.ATTR_CURRENT_LOGIN_TIMESTAMP, System.currentTimeMillis()); 265 mgr.setUserProfile(Wiki.context().create(m_engine, request, ""), profile); 266 } 267 } catch (Exception ex) { 268 LOG.debug(ex.getMessage(), ex); 269 } 270 } 271 // If by some unusual turn of events the Anonymous login module doesn't work, login failed! 272 return false; 273 } 274 275 /** 276 * {@inheritDoc} 277 */ 278 @Override 279 public boolean login( final Session session, final HttpServletRequest request, final String username, final String password ) throws WikiSecurityException { 280 if ( session == null ) { 281 LOG.error( "No wiki session provided, cannot log in." ); 282 return false; 283 } 284 285 // Protect against brute-force password guessing if configured to do so 286 if ( m_throttleLogins ) { 287 delayLogin( username ); 288 } 289 290 final CallbackHandler handler = new WikiCallbackHandler( m_engine, null, username, password ); 291 292 // Execute the user's specified login module 293 final Set< Principal > principals = doJAASLogin( m_loginModuleClass, handler, m_loginModuleOptions ); 294 if(!principals.isEmpty()) { 295 if( passwordExpired( session, principals ) ) { 296 return false; 297 } 298 rotateSessionAfterAuthentication( request, session ); 299 fireEvent(WikiSecurityEvent.LOGIN_AUTHENTICATED, getLoginPrincipal( principals ), session, request ); 300 for ( final Principal principal : principals ) { 301 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, principal, session, request ); 302 } 303 304 // Add all appropriate Authorizer roles 305 injectAuthorizerRoles( session, m_engine.getManager( AuthorizationManager.class ).getAuthorizer(), null ); 306 307 return true; 308 } 309 return false; 310 } 311 312 /** 313 * Tells if the password of a user who has just authenticated with the wiki's user database has expired, and tells the user so. The 314 * password of a profile that does not have the date it was changed yet is given it now, so that it expires once it is as old as 315 * the limit. Nothing is checked if passwords do not expire, or if the users are not authenticated with the user database. 316 * 317 * @param session the wiki session of the user 318 * @param principals the principals the user authenticated as 319 * @return {@code true} if the password has expired 320 */ 321 private boolean passwordExpired( final Session session, final Set< Principal > principals ) { 322 if( !m_passwordExpiry.isEnabled() || !UserDatabaseLoginModule.class.isAssignableFrom( m_loginModuleClass ) ) { 323 return false; 324 } 325 326 final String loginName = getLoginPrincipal( principals ).getName(); 327 final UserDatabase db = m_engine.getManager( UserManager.class ).getUserDatabase(); 328 try { 329 final UserProfile profile = db.findByLoginName( loginName ); 330 final Date now = new Date(); 331 if( profile.getPasswordChanged() == null ) { 332 profile.setPasswordChanged( now ); 333 db.save( profile ); 334 } else if( m_passwordExpiry.isExpired( profile, now ) ) { 335 LOG.info( "Login denied for {}: the password has expired", loginName ); 336 final ResourceBundle rb = m_engine.getManager( InternationalizationManager.class ) 337 .getBundle( InternationalizationManager.CORE_BUNDLE, session.getLocale() ); 338 session.addMessage( "login", rb.getString( "login.error.passwordExpired" ) ); 339 return true; 340 } 341 } catch( final NoSuchPrincipalException e ) { 342 LOG.debug( "No profile for {} in the user database, so its password cannot expire", loginName, e ); 343 } catch( final WikiSecurityException e ) { 344 LOG.error( "Could not record the date of the password of {}: {}", loginName, e.getMessage(), e ); 345 } 346 return false; 347 } 348 349 /** 350 * Session-fixation defense: the pre-authentication HTTP session id and anti-CSRF token must not survive the 351 * upgrade to an authenticated session. Rotates the servlet session id, re-keys the {@link SessionMonitor} entry 352 * so the wiki session attaches to the new id, and regenerates the wiki session's anti-CSRF token so a token 353 * observed before login cannot be replayed against the authenticated session. 354 * 355 * @param request the servlet request, may be <code>null</code> (e.g. embedded use); nothing to rotate then 356 * @param session the wiki session being upgraded 357 */ 358 private void rotateSessionAfterAuthentication( final HttpServletRequest request, final Session session ) { 359 if( request != null ) { 360 final HttpSession httpSession = request.getSession( false ); 361 if( httpSession != null ) { 362 final SessionMonitor monitor = SessionMonitor.getInstance( m_engine ); 363 monitor.remove( httpSession ); 364 try { 365 request.changeSessionId(); 366 } catch( final IllegalStateException e ) { 367 LOG.debug( "Unable to rotate the http session id: {}", e.getMessage() ); 368 } 369 monitor.register( httpSession, session ); 370 } 371 } 372 session.regenerateAntiCsrfToken(); 373 374 } 375 376 /** 377 * This method builds a database of login names that are being attempted, and will try to delay if there are too many requests coming 378 * in for the same username. 379 * <p> 380 * The current algorithm uses 2^loginattempts as the delay in milliseconds, i.e. at 10 login attempts it'll add 1.024 seconds to the login. 381 * 382 * @param username The username that is being logged in 383 */ 384 private void delayLogin( final String username ) { 385 try { 386 m_lastLoginAttempts.cleanup( LASTLOGINS_CLEANUP_TIME ); 387 final int count = m_lastLoginAttempts.count( username ); 388 389 final long delay = Math.min( 1L << count, MAX_LOGIN_DELAY ); 390 LOG.debug( "Sleeping for " + delay + " ms to allow login." ); 391 Thread.sleep( delay ); 392 393 m_lastLoginAttempts.add( username ); 394 } catch( final InterruptedException e ) { 395 // FALLTHROUGH is fine 396 LOG.debug(e.getMessage(), e); 397 } 398 } 399 400 /** 401 * {@inheritDoc} 402 */ 403 @Override 404 public void logout( final HttpServletRequest request ) { 405 if( request == null ) { 406 LOG.error( "No HTTP reqest provided; cannot log out." ); 407 return; 408 } 409 410 final HttpSession session = request.getSession(); 411 final String sid = ( session == null ) ? "(null)" : session.getId(); 412 LOG.debug( "Invalidating Session for session ID= {}", sid ); 413 // Retrieve the associated Session and clear the Principal set 414 final Session wikiSession = Wiki.session().find( m_engine, request ); 415 final Principal originalPrincipal = wikiSession.getLoginPrincipal(); 416 wikiSession.invalidate(); 417 418 // Remove the wikiSession from the WikiSession cache 419 Wiki.session().remove( m_engine, request ); 420 421 // We need to flush the HTTP session too 422 if( session != null ) { 423 session.invalidate(); 424 } 425 426 // Log the event 427 fireEvent( WikiSecurityEvent.LOGOUT, originalPrincipal, null, request ); 428 } 429 430 /** 431 * {@inheritDoc} 432 */ 433 @Override 434 public boolean allowsCookieAssertions() { 435 return m_allowsCookieAssertions; 436 } 437 438 /** 439 * {@inheritDoc} 440 */ 441 @Override 442 public boolean allowsCookieAuthentication() { 443 return m_allowsCookieAuthentication; 444 } 445 446 /** 447 * {@inheritDoc} 448 */ 449 @Override 450 public Set< Principal > doJAASLogin( final Class< ? extends LoginModule > clazz, 451 final CallbackHandler handler, 452 final Map< String, String > options ) throws WikiSecurityException { 453 // Instantiate the login module 454 final LoginModule loginModule; 455 try { 456 loginModule = ClassUtil.buildInstance( clazz ); 457 } catch( final ReflectiveOperationException e ) { 458 throw new WikiSecurityException( e.getMessage(), e ); 459 } 460 461 // Initialize the LoginModule 462 final Subject subject = new Subject(); 463 loginModule.initialize( subject, handler, EMPTY_MAP, options ); 464 465 // Try to log in: 466 boolean loginSucceeded = false; 467 boolean commitSucceeded = false; 468 try { 469 loginSucceeded = loginModule.login(); 470 if( loginSucceeded ) { 471 commitSucceeded = loginModule.commit(); 472 } 473 } catch( final LoginException e ) { 474 LOG.debug(e.getMessage(), e); 475 // Login or commit failed! No principal for you! 476 } 477 478 // If we successfully logged in & committed, return all the principals 479 if( loginSucceeded && commitSucceeded ) { 480 return subject.getPrincipals(); 481 } 482 return NO_PRINCIPALS; 483 } 484 485 // events processing ....................................................... 486 487 /** 488 * {@inheritDoc} 489 */ 490 @Override 491 public void addWikiEventListener( final WikiEventListener listener ) { 492 Synchronizer.synchronize(lock, () -> { 493 WikiEventManager.addWikiEventListener( this, listener ); 494 }); 495 } 496 497 /** 498 * {@inheritDoc} 499 */ 500 @Override 501 public void removeWikiEventListener( final WikiEventListener listener ) { 502 Synchronizer.synchronize(lock, () -> { 503 WikiEventManager.removeWikiEventListener( this, listener ); 504 }); 505 } 506 507 /** 508 * Initializes the options Map supplied to the configured LoginModule every time it is invoked. The properties and values extracted from 509 * <code>jspwiki.properties</code> are of the form <code>jspwiki.loginModule.options.<var>param</var> = <var>value</var>, where 510 * <var>param</var> is the key name, and <var>value</var> is the value. 511 * 512 * @param props the properties used to initialize JSPWiki 513 * @throws IllegalArgumentException if any of the keys are duplicated 514 */ 515 private void initLoginModuleOptions( final Properties props ) { 516 for( final Object key : props.keySet() ) { 517 final String propName = key.toString(); 518 if( propName.startsWith( PREFIX_LOGIN_MODULE_OPTIONS ) ) { 519 // Extract the option name and value 520 final String optionKey = propName.substring( PREFIX_LOGIN_MODULE_OPTIONS.length() ).trim(); 521 if( !optionKey.isEmpty() ) { 522 final String optionValue = props.getProperty( propName ); 523 524 // Make sure the key is unique before stashing the key/value pair 525 if ( m_loginModuleOptions.containsKey( optionKey ) ) { 526 throw new IllegalArgumentException( "JAAS LoginModule key " + propName + " cannot be specified twice!" ); 527 } 528 m_loginModuleOptions.put( optionKey, optionValue ); 529 } 530 } 531 } 532 } 533 534 /** 535 * After successful login, this method is called to inject authorized role Principals into the Session. To determine which roles 536 * should be injected, the configured Authorizer is queried for the roles it knows about by calling {@link Authorizer#getRoles()}. 537 * Then, each role returned by the authorizer is tested by calling {@link Authorizer#isUserInRole(Session, Principal)}. If this 538 * check fails, and the Authorizer is of type WebAuthorizer, the role is checked again by calling 539 * {@link WebAuthorizer#isUserInRole(HttpServletRequest, Principal)}). Any roles that pass the test are injected into the Subject by 540 * firing appropriate authentication events. 541 * 542 * @param session the user's current Session 543 * @param authorizer the Engine's configured Authorizer 544 * @param request the user's HTTP session, which may be <code>null</code> 545 */ 546 private void injectAuthorizerRoles( final Session session, final Authorizer authorizer, final HttpServletRequest request ) { 547 // Test each role the authorizer knows about 548 for( final Principal role : authorizer.getRoles() ) { 549 // Test the Authorizer 550 if( authorizer.isUserInRole( session, role ) ) { 551 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, role, session, request ); 552 LOG.debug( "Added authorizer role {}.", role.getName() ); 553 // If web authorizer, test the request.isInRole() method also 554 } else if ( request != null && authorizer instanceof WebAuthorizer ) { 555 final WebAuthorizer wa = ( WebAuthorizer )authorizer; 556 addRoles( request, "jspwiki.role.admin", "Admin",session); 557 addRoles( request, "jspwiki.role.authenticated", "Authenticated",session); 558 addRoles( request, "jspwiki.role.extraRoles", null,session); 559 if ( wa.isUserInRole( request, role ) ) { 560 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, role, session, request ); 561 LOG.debug( "Added container role {}.",role.getName() ); 562 } 563 } 564 } 565 } 566 567 private void addRoles(HttpServletRequest request, String configProp, String jspWikiRole, Session session) { 568 if (m_engine.getWikiProperties().containsKey(configProp)) { 569 String roles = m_engine.getWikiProperties().getProperty(configProp); 570 if (roles != null) { 571 String[] parts = roles.split("\\,"); 572 for (String s : parts) { 573 if (request.isUserInRole(s)) { 574 WikiPrincipal wikiPrincipal = new WikiPrincipal(s); 575 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, wikiPrincipal, session ); 576 if (jspWikiRole != null) { 577 WikiPrincipal wikiPrincipal1 = new WikiPrincipal(jspWikiRole); 578 fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, wikiPrincipal1, session ); 579 } 580 } 581 } 582 } 583 584 } 585 } 586 587}