forked from p81075629/datagear
主页数据库列表和查看时不传输数据库密码
This commit is contained in:
parent
3f3ff8a9b2
commit
47de0893ab
|
@ -15,7 +15,7 @@ import org.datagear.model.support.AbstractStringIdEntity;
|
|||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class Schema extends AbstractStringIdEntity implements CreateUserEntity<String>
|
||||
public class Schema extends AbstractStringIdEntity implements CreateUserEntity<String>, Cloneable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class Schema extends AbstractStringIdEntity implements CreateUserEntity<S
|
|||
|
||||
public Schema(String id, String title, String url, String user, String password)
|
||||
{
|
||||
super();
|
||||
super(id);
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
this.user = user;
|
||||
|
@ -159,11 +159,35 @@ public class Schema extends AbstractStringIdEntity implements CreateUserEntity<S
|
|||
this.driverEntity = driverEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除密码属性值。
|
||||
* <p>
|
||||
* 密码是敏感信息,某些情况下需要清除。
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public void clearPassword()
|
||||
{
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema clone() throws CloneNotSupportedException
|
||||
{
|
||||
Schema schema = new Schema(getId(), title, url, user, password);
|
||||
schema.setCreateUser(createUser);
|
||||
schema.setCreateTime(createTime);
|
||||
schema.setShared(shared);
|
||||
schema.setDriverEntity(driverEntity);
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + " [title=" + title + ", url=" + url + ", user=" + user + ", password="
|
||||
+ password + ", createUser=" + createUser + ", createTime=" + createTime + ", shared=" + shared
|
||||
+ ", driverEntity=" + driverEntity + "]";
|
||||
return getClass().getSimpleName() + " [title=" + title + ", url=" + url + ", user=" + user + ", createUser="
|
||||
+ createUser + ", createTime=" + createTime + ", shared=" + shared + ", driverEntity=" + driverEntity
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.datagear.management.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -116,7 +117,7 @@ public class SchemaServiceImpl extends AbstractMybatisEntityService<String, Sche
|
|||
this.schemaCache.putSchema(schema);
|
||||
}
|
||||
|
||||
return schema;
|
||||
return cloneIf(schema);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -137,7 +138,37 @@ public class SchemaServiceImpl extends AbstractMybatisEntityService<String, Sche
|
|||
this.schemaCache.putSchema(schema);
|
||||
}
|
||||
|
||||
return schema;
|
||||
return cloneIf(schema);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Schema> query(Query query)
|
||||
{
|
||||
return cloneIf(super.query(query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Schema> query(User user, Query query)
|
||||
{
|
||||
return cloneIf(super.query(user, query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingData<Schema> pagingQuery(PagingQuery pagingQuery)
|
||||
{
|
||||
PagingData<Schema> pagingData = super.pagingQuery(pagingQuery);
|
||||
pagingData.setItems(cloneIf(pagingData.getItems()));
|
||||
|
||||
return pagingData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingData<Schema> pagingQuery(User user, PagingQuery pagingQuery)
|
||||
{
|
||||
PagingData<Schema> pagingData = super.pagingQuery(user, pagingQuery);
|
||||
pagingData.setItems(cloneIf(pagingData.getItems()));
|
||||
|
||||
return pagingData;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -247,6 +278,54 @@ public class SchemaServiceImpl extends AbstractMybatisEntityService<String, Sche
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果设置了缓存则拷贝{@linkplain Schema}。
|
||||
* <p>
|
||||
* {@code get...()}方法返回对象修改属性值后不能影响缓存值,所以要进行拷贝。
|
||||
* </p>
|
||||
*
|
||||
* @param schema
|
||||
* @return
|
||||
*/
|
||||
protected Schema cloneIf(Schema schema)
|
||||
{
|
||||
if (schema == null || this.schemaCache == null)
|
||||
return schema;
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return schema.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Schema> cloneIf(List<Schema> schemas)
|
||||
{
|
||||
if (schemas == null || this.schemaCache == null)
|
||||
return schemas;
|
||||
else
|
||||
{
|
||||
List<Schema> clones = new ArrayList<Schema>(schemas.size());
|
||||
|
||||
try
|
||||
{
|
||||
for (Schema schema : schemas)
|
||||
clones.add(schema.clone());
|
||||
|
||||
return clones;
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSqlNamespace()
|
||||
{
|
||||
|
|
|
@ -172,6 +172,8 @@ public class SchemaController extends AbstractSchemaModelController
|
|||
if (schema == null)
|
||||
throw new RecordNotFoundException();
|
||||
|
||||
schema.clearPassword();
|
||||
|
||||
model.addAttribute("schema", schema);
|
||||
model.addAttribute(KEY_TITLE_MESSAGE_KEY, "schema.viewSchema");
|
||||
model.addAttribute(KEY_READONLY, "true");
|
||||
|
@ -226,6 +228,12 @@ public class SchemaController extends AbstractSchemaModelController
|
|||
|
||||
List<Schema> schemas = getSchemaService().query(user, query);
|
||||
|
||||
if (schemas != null)
|
||||
{
|
||||
for (Schema schema : schemas)
|
||||
schema.clearPassword();
|
||||
}
|
||||
|
||||
return schemas;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue