mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 15:02:17 +01:00
Add feature to set custom realm description
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -216,7 +216,7 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
|
||||
|
||||
if (Strings.isNullOrEmpty(authentication))
|
||||
{
|
||||
HttpUtil.sendUnauthorized(request, response);
|
||||
HttpUtil.sendUnauthorized(request, response, configuration.getRealmDescription());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -262,7 +262,7 @@ public abstract class PermissionFilter extends HttpFilter
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpUtil.sendUnauthorized(response);
|
||||
HttpUtil.sendUnauthorized(response, configuration.getRealmDescription());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user