[MRM-1722] Use cookie settings from redback for rememberme feature

fix issues on not saved redbackRuntimeConfiguration.properties

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1424183 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-19 22:37:53 +00:00
parent d54308934c
commit 0ae2aff01e
10 changed files with 209 additions and 124 deletions

View File

@ -18,6 +18,8 @@ package org.apache.archiva.web.api;
* under the License.
*/
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
import org.apache.archiva.web.runtime.ArchivaRuntimeInfo;
import org.apache.archiva.web.model.ApplicationRuntimeInfo;
import org.apache.commons.lang.StringUtils;
@ -35,7 +37,7 @@ import java.util.Locale;
/**
* @author Olivier Lamy
*/
@Service( "runtimeInfoService#rest" )
@Service("runtimeInfoService#rest")
public class DefaultRuntimeInfoService
implements RuntimeInfoService
{
@ -44,6 +46,9 @@ public class DefaultRuntimeInfoService
private ArchivaRuntimeInfo archivaRuntimeInfo;
@Inject
private ArchivaRuntimeConfigurationService archivaRuntimeConfigurationService;
@Context
protected HttpServletRequest httpServletRequest;
@ -54,6 +59,7 @@ public class DefaultRuntimeInfoService
}
public ApplicationRuntimeInfo getApplicationRuntimeInfo( String locale )
throws ArchivaRestServiceException
{
ApplicationRuntimeInfo applicationRuntimeInfo = new ApplicationRuntimeInfo();
applicationRuntimeInfo.setBuildNumber( this.archivaRuntimeInfo.getBuildNumber() );
@ -65,6 +71,9 @@ public class DefaultRuntimeInfoService
new Locale( StringUtils.isEmpty( locale ) ? "en" : locale ) );
applicationRuntimeInfo.setTimestampStr( sfd.format( new Date( archivaRuntimeInfo.getTimestamp() ) ) );
applicationRuntimeInfo.setRedbackRuntimeConfiguration(
archivaRuntimeConfigurationService.getRedbackRuntimeConfigurationAdmin() );
return applicationRuntimeInfo;
}

View File

@ -18,6 +18,7 @@ package org.apache.archiva.web.api;
* under the License.
*/
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.web.model.ApplicationRuntimeInfo;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
@ -32,19 +33,20 @@ import javax.ws.rs.core.MediaType;
* @author Olivier Lamy
* @since 1.4-M3
*/
@Path( "/runtimeInfoService/" )
@Path("/runtimeInfoService/")
public interface RuntimeInfoService
{
@Path( "archivaRuntimeInfo/{locale}" )
@Path("archivaRuntimeInfo/{locale}")
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true )
ApplicationRuntimeInfo getApplicationRuntimeInfo( @PathParam( "locale" ) String locale );
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@RedbackAuthorization(noRestriction = true)
ApplicationRuntimeInfo getApplicationRuntimeInfo( @PathParam("locale") String locale )
throws ArchivaRestServiceException;
@Path( "logMissingI18n" )
@Path("logMissingI18n")
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true )
Boolean logMissingI18n( @QueryParam( "key" ) String key );
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@RedbackAuthorization(noRestriction = true)
Boolean logMissingI18n( @QueryParam("key") String key );
}

View File

@ -18,6 +18,8 @@ package org.apache.archiva.web.model;
* under the License.
*/
import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Calendar;
@ -25,7 +27,7 @@ import java.util.Calendar;
* @author Olivier Lamy
* @since 1.4-M3
*/
@XmlRootElement( name = "applicationRuntimeInfo" )
@XmlRootElement(name = "applicationRuntimeInfo")
public class ApplicationRuntimeInfo
{
private boolean devMode = false;
@ -46,6 +48,8 @@ public class ApplicationRuntimeInfo
private String timestampStr;
private RedbackRuntimeConfiguration redbackRuntimeConfiguration;
public ApplicationRuntimeInfo()
{
this.devMode = Boolean.getBoolean( "archiva.devMode" );
@ -147,6 +151,16 @@ public class ApplicationRuntimeInfo
this.timestampStr = timestampStr;
}
public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
{
return redbackRuntimeConfiguration;
}
public void setRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration )
{
this.redbackRuntimeConfiguration = redbackRuntimeConfiguration;
}
@Override
public String toString()
{
@ -161,6 +175,7 @@ public class ApplicationRuntimeInfo
sb.append( ", logMissingI18n=" ).append( logMissingI18n );
sb.append( ", baseUrl='" ).append( baseUrl ).append( '\'' );
sb.append( ", timestampStr='" ).append( timestampStr ).append( '\'' );
sb.append( ", redbackRuntimeConfiguration=" ).append( redbackRuntimeConfiguration );
sb.append( '}' );
return sb.toString();
}

View File

@ -96,25 +96,30 @@ $.ajax({
"archiva.search": "archiva/search",
"archiva.proxy-connectors-rules": "archiva/proxy-connectors-rules",
"archiva.docs": "archiva/docs",
"archiva.main": "archiva/main"
"archiva.main": "archiva/main",
"archiva.knockout.properties": "archiva/knockout-properties"
}
});
requirejs(['jquery','jquery.tmpl','jquery.ui','i18n','sammy','startup','utils','domReady!','archiva.main'], function () {
requirejs(['jquery','jquery.tmpl','jquery.ui','i18n','sammy','startup','utils','domReady!','archiva.main','archiva.general-admin'], function () {
loadi18n(function () {
$.ajax({
url: "restServices/archivaUiServices/runtimeInfoService/archivaRuntimeInfo/"+usedLang(),
dataType: 'json',
success:function(data){
window.archivaDevMode=data.devMode;
window.archivaJavascriptLog=data.javascriptLog;
window.archivaRuntimeInfo=data;
window.archivaDevMode=data.devMode;
window.archivaJavascriptLog=data.javascriptLog;
window.archivaRuntimeInfo=data;
require(['sammy','jquery','i18n','jquery.tmpl','archiva.main','utils','domReady!'],function () {
startArchivaApplication();
$("#loadingDiv").hide();
drawQuickSearchAutocomplete();
})
window.redbackRuntimeConfiguration=mapRedbackRuntimeConfiguration(data.redbackRuntimeConfiguration);
$.log("security.rememberme.enabled key value:"+ window.redbackRuntimeConfiguration.findPropertyValue('security.rememberme.enabled'));
require(['sammy','jquery','i18n','jquery.tmpl','archiva.main','utils','domReady!'],function () {
startArchivaApplication();
$("#loadingDiv").hide();
drawQuickSearchAutocomplete();
})
}
})
});

View File

@ -17,7 +17,7 @@
* under the License.
*/
define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout","knockout.simpleGrid",
"knockout.sortable","jquery.validate","bootstrap"]
"knockout.sortable","jquery.validate","bootstrap","archiva.knockout.properties"]
, function(jquery,i18n,utils,jqueryTmpl,ko) {
//-------------------------
@ -1169,6 +1169,16 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
self.modified(true);
$.log("configurationPropertiesEntries modified")
});
this.findPropertyValue=function(key){
for(var i=0;i<self.configurationPropertiesEntries().length;i++){
if(self.configurationPropertiesEntries()[i].key==key){
var val = self.configurationPropertiesEntries()[i].value;
$.log("findPropertyValue " + key + "->" + val);
return val;
}
}
}
}
mapRedbackRuntimeConfiguration=function(data){
@ -1252,6 +1262,24 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
this.usedUserManagerImpls=ko.observableArray([]);
self.gridViewModel = new ko.simpleGrid.viewModel({
data: self.redbackRuntimeConfiguration().configurationPropertiesEntries,
columns: [
{
headerText: $.i18n.prop('redback.runtime.properties.key.label'),
rowText: "key"
},
{
headerText: $.i18n.prop('redback.runtime.properties.value.label'),
rowText: "value"
}
],
pageSize: 10,//self.redbackRuntimeConfiguration().configurationPropertiesEntries.length,
gridUpdateCallBack: function(){
}
});
findUserManagerImplementationInformation=function(id){
for(var i= 0;i<self.userManagerImplementationInformations().length;i++){
$.log(id+""+self.userManagerImplementationInformations()[i].beanId);
@ -1358,14 +1386,13 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
var userMessages=$("#user-messages");
userMessages.html(mediumSpinnerImg());
self.redbackRuntimeConfiguration().userManagerImpls=ko.observableArray([]);
$.log("length:"+self.usedUserManagerImpls().length);
for(var i=0;i<self.usedUserManagerImpls().length;i++){
var beanId=self.usedUserManagerImpls()[i].beanId;
$.log("beanId:"+beanId);
self.redbackRuntimeConfiguration().userManagerImpls.push(beanId);
}
$.log("length:"+self.redbackRuntimeConfiguration().userManagerImpls().length);
$.log("json:"+ko.toJSON(self.redbackRuntimeConfiguration));
$.log("rememberme enabled:"+self.redbackRuntimeConfiguration().findPropertyValue("security.rememberme.enabled"));
$.ajax("restServices/archivaServices/archivaRuntimeConfigurationService/redbackRuntimeConfiguration",
{
type: "PUT",
@ -1426,11 +1453,12 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
type: "GET",
dataType: 'json',
success: function(data) {
// TODO use window.redbackRuntimeConfiguration ?
var redbackRuntimeConfiguration = mapRedbackRuntimeConfiguration(data);
var redbackRuntimeConfigurationViewModel =
new RedbackRuntimeConfigurationViewModel(redbackRuntimeConfiguration,userManagerImplementationInformations);
mainContent.html( $( "#runtime-configuration-main" ).tmpl() );
ko.applyBindings(redbackRuntimeConfigurationViewModel,$("#runtime-configuration-content" ).get(0));
mainContent.html( $("#redback-runtime-configuration-main" ).tmpl() );
ko.applyBindings(redbackRuntimeConfigurationViewModel,$("#redback-runtime-configuration-content" ).get(0));
activatePopoverDoc();
}
});

View File

@ -359,14 +359,28 @@ require(["jquery","jquery.tmpl","i18n","knockout"], function(jquery,jqueryTmpl,i
*/
Entry=function(key,value,subscribeFn){
var self=this;
this.modified=ko.observable(false);
this.modified.subscribe(function(newValue){
$.log("Entry modified");
});
this.key=ko.observable(key);
if(subscribeFn){
this.key.subscribe(function(newValue){subscribeFn(newValue)});
}
this.key.subscribe(function(newValue){
self.modified(true);
if(subscribeFn){
subscribeFn(newValue)
}
});
this.value=ko.observable(value);
if(subscribeFn){
this.value.subscribe(function(newValue){$.log("value modified");subscribeFn(newValue);});
}
this.value.subscribe(function(newValue){
self.modified(true);
if(subscribeFn){
subscribeFn(newValue)
}
});
}
/**

View File

@ -11,76 +11,76 @@
(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD anonymous module
define("knockout.simpleGrid",["jquery","knockout","utils","i18n"], factory);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(window.ko, jQuery);
}
})(function ($,ko,utils,i18n) {
(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD anonymous module
define("knockout.simpleGrid",["jquery","knockout","utils","i18n"], factory);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(window.ko, jQuery);
}
})(function ($,ko,utils,i18n) {
ko.simpleGrid = {
// Defines a view model class you can use to populate a grid
viewModel: function (configuration) {
this.data = configuration.data;
this.currentPageIndex = ko.observable(0);
this.pageSize = configuration.pageSize || 5;
this.columns = configuration.columns;
ko.simpleGrid = {
// Defines a view model class you can use to populate a grid
viewModel: function (configuration) {
this.data = configuration.data;
this.currentPageIndex = ko.observable(0);
this.pageSize = configuration.pageSize || 5;
this.columns = configuration.columns;
this.itemsOnCurrentPage = ko.computed(function () {
var startIndex = this.pageSize * this.currentPageIndex();
return this.data.slice(startIndex, startIndex + this.pageSize);
}, this);
this.itemsOnCurrentPage = ko.computed(function () {
var startIndex = this.pageSize * this.currentPageIndex();
return this.data.slice(startIndex, startIndex + this.pageSize);
}, this);
this.maxPageIndex = ko.computed(function () {
return Math.ceil(ko.utils.unwrapObservable(this.data).length / this.pageSize);
}, this);
this.i18n=function(key){
return $.i18n.prop(key);
};
this.gridUpdateCallBack = configuration.gridUpdateCallBack;
this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack;
this.maxPageIndex = ko.computed(function () {
return Math.ceil(ko.utils.unwrapObservable(this.data).length / this.pageSize);
}, this);
this.i18n=function(key){
return $.i18n.prop(key);
};
this.gridUpdateCallBack = configuration.gridUpdateCallBack;
this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack;
}
};
// Templates used to render the grid
var templateEngine = new ko.jqueryTmplTemplateEngine();
// The "simpleGrid" binding
ko.bindingHandlers.simpleGrid = {
// This method is called to initialize the node, and will also be called again if you change what the grid is bound to
update: function (element, viewModelAccessor, allBindingsAccessor) {
var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor();
// Empty the element
while(element.firstChild) {
ko.removeNode(element.firstChild);
}
};
// Templates used to render the grid
var templateEngine = new ko.jqueryTmplTemplateEngine();
// Allow the default templates to be overridden
var gridTemplateName = allBindings.simpleGridTemplate || "ko_usersGrid_grid",
pageLinksTemplateName = allBindings.simpleGridPagerTemplate || "ko_simpleGrid_pageLinks";
// Render the main grid
var gridContainer = element.appendChild(document.createElement("DIV"));
ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode")
.subscribe(viewModel.gridUpdateCallBack?viewModel.gridUpdateCallBack:function(){});
// The "simpleGrid" binding
ko.bindingHandlers.simpleGrid = {
// This method is called to initialize the node, and will also be called again if you change what the grid is bound to
update: function (element, viewModelAccessor, allBindingsAccessor) {
var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor();
if (viewModel.gridUpdateCallBack) viewModel.gridUpdateCallBack();
// Empty the element
while(element.firstChild) {
ko.removeNode(element.firstChild);
}
// Allow the default templates to be overridden
var gridTemplateName = allBindings.simpleGridTemplate || "ko_usersGrid_grid",
pageLinksTemplateName = allBindings.simpleGridPagerTemplate || "ko_simpleGrid_pageLinks";
// Render the main grid
var gridContainer = element.appendChild(document.createElement("DIV"));
ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode")
.subscribe(viewModel.gridUpdateCallBack?viewModel.gridUpdateCallBack:function(){});
if (viewModel.gridUpdateCallBack) viewModel.gridUpdateCallBack();
// Render the page links
var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0);
var renderedTemplate = ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode");
if (renderedTemplate.subscribe){
renderedTemplate.subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
}
if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack();
}
};
// Render the page links
var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0);
var renderedTemplate = ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode");
if (renderedTemplate.subscribe){
renderedTemplate.subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
}
if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack();
}
};
})

View File

@ -366,6 +366,16 @@ function(jquery,utils,i18n,jqueryValidate,ko,koSimpleGrid,purl) {
$.log("user not in cookie");
}
var rememberMe=window.redbackRuntimeConfiguration.findPropertyValue('security.rememberme.enabled');
$.log("rememberMe:"+rememberMe);
if (rememberMe!='true'){
$("#user-login-form-rememberme-label" ).hide();
$("#user-login-form-rememberme" ).attr("disabled","true");
if($("#user-login-form-rememberme" ).get(0 ).checked){
$("#user-login-form-rememberme" ).get(0 ).checked=false;
}
}
var userLoginForm = $("#user-login-form");
userLoginForm.validate({

View File

@ -886,11 +886,11 @@
</tbody>
</script>
<script type="text/html" id="runtime-configuration-main">
<script type="text/html" id="redback-runtime-configuration-main">
<div class="page-header">
<h2>${$.i18n.prop('redback-runtime-configuration.title')}</h2>
</div>
<div id="runtime-configuration-content" data-bind='template: {name:"redback-runtime-configuration-content-tmpl"}'>
<div id="redback-runtime-configuration-content" data-bind='template: {name:"redback-runtime-configuration-content-tmpl"}'>
</div>
</script>
@ -1013,44 +1013,46 @@
</div>
<div class="tab-pane" id="redback-runtime-properties-content">
<div class="well">
<table>
<thead>
<tr>
<th></th>
<th>${$.i18n.prop('redback.runtime.properties.key.label')}</th>
<th>${$.i18n.prop('redback.runtime.properties.value.label')}</th>
</tr>
</thead>
<tbody>
{{each(i, property) redbackRuntimeConfiguration().configurationPropertiesEntries}}
<tr>
<td>
{{var key = property.key}}
<a class="popover-doc"
data-original-title="${$.i18n.prop('redback.runtime.properties.help.title')}"
data-content="${$.i18n.prop(key+'.help.content')}">
<span class="btn btn-info"><i class="icon-question-sign icon-white"></i></span>
</a>
</td>
<td><input type="text" class="input-xxlarge" value="${property.key}"></td>
<td><input type="text" class="input-xlarge" value="${property.value}"></td>
</tr>
{{/each}}
</tbody>
<div class="well">
<table id="proxyConnectorsTable"
data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'properties-grid',pageLinksId:'properties-grid-pagination'">
</table>
<div id="properties-grid-pagination"></div>
</div>
</div>
<div>
<button data-bind="click: saveRedbackRuntimeConfiguration,css:{ 'btn-warning': redbackRuntimeConfiguration().modified() | redbackRuntimeConfiguration().ldapConfiguration().modified() }"
id="redback-archiva-runtime-configuration-save"class="btn">${$.i18n.prop('save')}</button>
id="redback-runtime-configuration-save"class="btn">${$.i18n.prop('save')}</button>
</div>
</script>
<script id="configurationPropertiesEntries-tmpl" type="text/html">
<script id='properties-grid' type='text/html'>
<thead>
<tr>
<th></th>
<th>${$.i18n.prop('redback.runtime.properties.key.label')}</th>
<th>${$.i18n.prop('redback.runtime.properties.value.label')}</th>
</tr>
</thead>
<tbody>
{{each(i, row) itemsOnCurrentPage()}}
<tr>
<td>
{{var key = row.key}}
<a class="popover-doc"
data-original-title="${$.i18n.prop('redback.runtime.properties.help.title')}"
data-content="${$.i18n.prop(key+'.help.content')}">
<span class="btn btn-info"><i class="icon-question-sign icon-white"></i></span>
</a>
</td>
<td>${row.key}</td>
<td><input type="text" class="input-xxlarge" data-bind="value: row.value"></td>
</tr>
{{/each}}
</tbody>
</script>

View File

@ -47,7 +47,7 @@
</div>
<div class="modal-footer" id="modal-login-footer">
<div class="pull-left">
<label class="checkbox">
<label class="checkbox" id="user-login-form-rememberme-label">
<input type="checkbox" id="user-login-form-rememberme">${$.i18n.prop('rememberme')}
</label>
</div>