@ -52,9 +52,15 @@ public class index {
}
// access control
final boolean authorizedAccess = sb . verifyAuthentication ( header ) ;
if ( ( post ! = null ) & & ( post . containsKey ( "publicPage" ) ) ) {
if ( ! authorizedAccess ) {
String authenticatedUserName = null ;
final boolean adminAuthenticated = sb . verifyAuthentication ( header ) ;
if ( adminAuthenticated ) {
authenticatedUserName = sb . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , "admin" ) ;
}
if ( ( post ! = null ) & & ( post . containsKey ( "auth" ) | | post . containsKey ( "publicPage" ) ) ) {
if ( ! adminAuthenticated ) {
prop . authenticationRequired ( ) ;
return prop ;
}
@ -136,9 +142,47 @@ public class index {
prop . put ( "searchdomswitches_searchapp_check" , ( contentdom = = ContentDomain . APP ) ? "1" : "0" ) ;
prop . put ( "search.navigation" , sb . getConfig ( "search.navigation" , "all" ) ) ;
prop . put ( "search.verify" , sb . getConfig ( "search.verify" , "iffresh" ) ) ;
handleTopNavBarLoginSection ( header , sb , prop , authenticatedUserName ) ;
// online caution timing
sb . localSearchLastAccess = System . currentTimeMillis ( ) ;
return prop ;
}
/ * *
* Add any eventually relevant information to generate the proper login link or status in the top navigation bar
* @param header the current request headers
* @param sb the server environment
* @param prop the servlet answer object
* @param authenticatedUserName the name of the currently authenticated user or null
* /
private static void handleTopNavBarLoginSection ( final RequestHeader header , final Switchboard sb ,
final serverObjects prop , String authenticatedUserName ) {
final boolean showLogin = sb . getConfigBool ( SwitchboardConstants . SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN ,
SwitchboardConstants . SEARCH_PUBLIC_TOP_NAV_BAR_LOGIN_DEFAULT ) ;
if ( showLogin ) {
if ( authenticatedUserName ! = null ) {
/* Show the name of the authenticated user */
prop . put ( "showLogin" , 1 ) ;
prop . put ( "showLogin_userName" , authenticatedUserName ) ;
} else {
/* Show a login link */
prop . put ( "showLogin" , 2 ) ;
/* The login link targets the same URL as the current location, just adding the 'auth' parameter to indicates that access to extended search features is desired */
StringBuilder loginURL = new StringBuilder ( "index.html?auth" ) ;
final String query = header . getQueryString ( ) ;
if ( query ! = null ) {
loginURL . append ( "&" ) . append ( query ) ;
}
prop . put ( "showLogin_loginURL" , loginURL . toString ( ) ) ;
}
} else {
prop . put ( "showLogin" , 0 ) ;
}
}
}