reduce security informations returned by this public service

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1428920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-01-04 15:16:22 +00:00
parent f42e8368e7
commit 4a9e3f90a7
6 changed files with 61 additions and 18 deletions

View File

@ -18,10 +18,14 @@ package org.apache.archiva.web.api;
* under the License.
*/
import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.RedbackRuntimeConfigurationService;
import org.apache.archiva.web.model.CookieInformation;
import org.apache.archiva.web.runtime.ArchivaRuntimeInfo;
import org.apache.archiva.web.model.ApplicationRuntimeInfo;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,8 +75,24 @@ public class DefaultRuntimeInfoService
new Locale( StringUtils.isEmpty( locale ) ? "en" : locale ) );
applicationRuntimeInfo.setTimestampStr( sfd.format( new Date( archivaRuntimeInfo.getTimestamp() ) ) );
applicationRuntimeInfo.setRedbackRuntimeConfiguration(
redbackRuntimeConfigurationService.getRedbackRuntimeConfiguration() );
CookieInformation cookieInformation = new CookieInformation();
RedbackRuntimeConfiguration redbackRuntimeConfiguration =
redbackRuntimeConfigurationService.getRedbackRuntimeConfiguration();
cookieInformation.setDomain(
redbackRuntimeConfiguration.getConfigurationProperties().get( UserConfigurationKeys.REMEMBER_ME_DOMAIN ) );
cookieInformation.setPath(
redbackRuntimeConfiguration.getConfigurationProperties().get( UserConfigurationKeys.REMEMBER_ME_PATH ) );
cookieInformation.setSecure(
redbackRuntimeConfiguration.getConfigurationProperties().get( UserConfigurationKeys.REMEMBER_ME_SECURE ) );
cookieInformation.setTimeout(
redbackRuntimeConfiguration.getConfigurationProperties().get( UserConfigurationKeys.REMEMBER_ME_TIMEOUT ) );
cookieInformation.setRememberMeEnabled( BooleanUtils.toBoolean(
redbackRuntimeConfiguration.getConfigurationProperties().get(
UserConfigurationKeys.REMEMBER_ME_ENABLED ) ) );
applicationRuntimeInfo.setCookieInformation( cookieInformation );
return applicationRuntimeInfo;
}

View File

@ -21,6 +21,7 @@ package org.apache.archiva.web.model;
import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Calendar;
/**
@ -29,6 +30,7 @@ import java.util.Calendar;
*/
@XmlRootElement(name = "applicationRuntimeInfo")
public class ApplicationRuntimeInfo
implements Serializable
{
private boolean devMode = false;
@ -48,7 +50,7 @@ public class ApplicationRuntimeInfo
private String timestampStr;
private RedbackRuntimeConfiguration redbackRuntimeConfiguration;
private CookieInformation cookieInformation;
public ApplicationRuntimeInfo()
{
@ -151,14 +153,14 @@ public class ApplicationRuntimeInfo
this.timestampStr = timestampStr;
}
public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
public CookieInformation getCookieInformation()
{
return redbackRuntimeConfiguration;
return cookieInformation;
}
public void setRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration )
public void setCookieInformation( CookieInformation cookieInformation )
{
this.redbackRuntimeConfiguration = redbackRuntimeConfiguration;
this.cookieInformation = cookieInformation;
}
@Override
@ -175,7 +177,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( ", cookieInformation=" ).append( cookieInformation );
sb.append( '}' );
return sb.toString();
}

View File

@ -110,9 +110,7 @@ $.ajax({
window.archivaJavascriptLog=data.javascriptLog;
window.archivaRuntimeInfo=data;
window.redbackRuntimeConfiguration=mapRedbackRuntimeConfiguration(data.redbackRuntimeConfiguration);
$.log("security.rememberme.enabled key value:"+ window.redbackRuntimeConfiguration.findPropertyValue('security.rememberme.enabled'));
window.cookieInformation=mapCookieInformation(data.cookieInformation);
require(['sammy','jquery','i18n','jquery.tmpl','archiva.main','utils','domReady!'],function () {
startArchivaApplication();

View File

@ -1612,7 +1612,6 @@ 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);
@ -1653,4 +1652,28 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
return new CacheConfiguration(data.timeToIdleSeconds,data.timeToLiveSeconds,data.maxElementsInMemory,data.maxElementsOnDisk);
}
CookieInformation=function(path,domain,secure,timeout,rememberMeEnabled){
//private String path;
this.path=path;
//private String domain;
this.domain=domain;
//private String secure;
this.secure=secure;
//private String timeout;
this.timeout=timeout;
//private boolean rememberMeEnabled;
this.rememberMeEnabled=rememberMeEnabled;
}
mapCookieInformation=function(data){
if(!data){
return new CookieInformation();
}
return new CookieInformation(data.path,data.domain,data.secure,data.timeout,data.rememberMeEnabled);
}
});

View File

@ -29,13 +29,13 @@ function(jquery,ui,sammy,tmpl,i18n,jqueryCookie,bootstrap,archivaSearch,jqueryVa
*/
reccordLoginCookie=function(user) {
var path = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.path");
var path = window.cookieInformation.path;
path = path ? path : "/";
var domain = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.domain");
var secure = window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.secure");
var domain = window.cookieInformation.domain;
var secure = window.cookieInformation.secure;
var expires= Number(window.redbackRuntimeConfiguration.findPropertyValue("security.rememberme.timeout"));
var expires= Number(window.cookieInformation.timeout);
var userJson=ko.toJSON(user);

View File

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