Add feature to set custom realm description

This commit is contained in:
Sergey Averkiev
2014-01-29 16:26:57 +04:00
parent da8d673438
commit 387f39bfe1
5 changed files with 78 additions and 6 deletions

View File

@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.ConfigChangedListener;
import sonia.scm.ListenerSupport;
import sonia.scm.event.ScmEventBus;
import sonia.scm.util.HttpUtil;
import sonia.scm.xml.XmlSetStringAdapter;
//~--- JDK imports ------------------------------------------------------------
@@ -157,6 +158,7 @@ public class ScmConfiguration
*/
public void load(ScmConfiguration other)
{
this.realmDescription = other.realmDescription;
this.dateFormat = other.dateFormat;
this.pluginUrl = other.pluginUrl;
this.anonymousAccessEnabled = other.anonymousAccessEnabled;
@@ -231,6 +233,17 @@ public class ScmConfiguration
return baseUrl;
}
/**
* Returns the realm description.
*
*
* @return realm description
*/
public String getRealmDescription()
{
return realmDescription;
}
/**
* Returns the date format for the user interface. This format is a
* JavaScript date format, from the library moment.js.
@@ -516,6 +529,17 @@ public class ScmConfiguration
this.baseUrl = baseUrl;
}
/**
* Sets the realm description.
*
*
* @param realmDescription
*/
public void setRealmDescription(String realmDescription)
{
this.realmDescription = realmDescription;
}
/**
* Sets the date format for the ui.
*
@@ -824,6 +848,13 @@ public class ScmConfiguration
/** Field description */
private boolean disableGroupingGrid = false;
/**
*
* Authentication realm for basic authentication.
*
*/
private String realmDescription = HttpUtil.AUTHENTICATION_REALM;
/**
* JavaScript date format from moment.js
* @see <a href="http://momentjs.com/docs/#/parsing/" target="_blank">http://momentjs.com/docs/#/parsing/</a>

View File

@@ -416,7 +416,7 @@ public final class HttpUtil
throws IOException
{
sendUnauthorized(null, response);
sendUnauthorized(null, response, AUTHENTICATION_REALM);
}
/**
@@ -427,17 +427,50 @@ public final class HttpUtil
* @param response http response
*
* @throws IOException
*
* @since 1.19
*/
public static void sendUnauthorized(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
sendUnauthorized(request, response, AUTHENTICATION_REALM);
}
/**
* Send an unauthorized header back to the client
*
*
* @param response - the http response
* @param realmDescription - realm description
*
* @throws IOException
*/
public static void sendUnauthorized(HttpServletResponse response, String realmDescription)
throws IOException
{
sendUnauthorized(null, response, realmDescription);
}
/**
* Send an unauthorized header back to the client
*
*
* @param request http request
* @param response http response
* @param realmDescription realm description
*
* @throws IOException
*
* @since 1.19
*/
public static void sendUnauthorized(HttpServletRequest request,
HttpServletResponse response,
String realmDescription)
throws IOException
{
if ((request == null) ||!isWUIRequest(request))
{
response.setHeader(HEADER_WWW_AUTHENTICATE,
"Basic realm=\"".concat(AUTHENTICATION_REALM).concat("\""));
"Basic realm=\"".concat(realmDescription).concat("\""));
}
else if (logger.isTraceEnabled())

View File

@@ -216,7 +216,7 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
if (Strings.isNullOrEmpty(authentication))
{
HttpUtil.sendUnauthorized(request, response);
HttpUtil.sendUnauthorized(request, response, configuration.getRealmDescription());
}
else
{

View File

@@ -262,7 +262,7 @@ public abstract class PermissionFilter extends HttpFilter
}
else
{
HttpUtil.sendUnauthorized(response);
HttpUtil.sendUnauthorized(response, configuration.getRealmDescription());
}
}

View File

@@ -34,6 +34,7 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
titleText: 'General Settings',
servnameText: 'Servername',
realmDescriptionText: 'Realm description',
dateFormatText: 'Date format',
enableForwardingText: 'Enable forwarding (mod_proxy)',
forwardPortText: 'Forward Port',
@@ -67,6 +68,7 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
// help
servernameHelpText: 'The name of this server. This name will be part of the repository url.',
realmDescriptionHelpText: 'Enter authentication realm description',
// TODO i18n
dateFormatHelpText: 'Moments date format. Please have a look at \n\
<a href="http://momentjs.com/docs/#/displaying/format/" target="_blank">http://momentjs.com/docs/#/displaying/format/</a>.<br />\n\
@@ -129,6 +131,12 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{
name: 'enableRepositoryArchive',
inputValue: 'true',
helpText: this.enableRepositoryArchiveHelpText
},{
xtype: 'textfield',
fieldLabel: this.realmDescriptionText,
name: 'realmDescription',
allowBlank: false,
helpText: this.realmDescriptionHelpText
},{
xtype: 'textfield',
fieldLabel: this.dateFormatText,