Add some entities about database, and ScriptCapture

This commit is contained in:
coderfengyun 2013-06-27 16:54:26 +08:00
parent e7256882b6
commit 190194e836
16 changed files with 289 additions and 288 deletions

View File

@ -3,7 +3,7 @@ package org.bench4q.master.api;
import javax.servlet.http.HttpServletRequest;
import org.bench4q.master.auth.AuthenticationManager;
import org.bench4q.master.entity.User;
import org.bench4q.master.entity.db.User;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class BaseController {
@ -33,7 +33,7 @@ public abstract class BaseController {
return this.getAuthenticationManager().getPrincipal(this.getRequest());
}
protected boolean checkScope(String scope) {
protected boolean checkScope(byte scope) {
return this.getAuthenticationManager().checkScope(this.getRequest(),
scope);
}

View File

@ -1,6 +1,6 @@
package org.bench4q.master.api;
import org.bench4q.master.entity.User;
import org.bench4q.master.entity.db.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

View File

@ -4,7 +4,7 @@ import org.bench4q.master.api.model.AuthorizeResponseModel;
import org.bench4q.master.api.model.RegisterResponseModel;
import org.bench4q.master.auth.AccessToken;
import org.bench4q.master.auth.AuthenticationManager;
import org.bench4q.master.entity.User;
import org.bench4q.master.entity.db.User;
import org.bench4q.master.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

View File

@ -2,15 +2,15 @@ package org.bench4q.master.auth;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
public class AccessToken implements Serializable {
private static final long serialVersionUID = 4134631390384650898L;
private String userName;
private String password;
private byte scope;
private Date generateTime;
private int expiresIn;
private List<String> scope;
public String getUserName() {
return userName;
@ -44,11 +44,11 @@ public class AccessToken implements Serializable {
this.expiresIn = expiresIn;
}
public List<String> getScope() {
public byte getScope() {
return scope;
}
public void setScope(List<String> scope) {
public void setScope(byte scope) {
this.scope = scope;
}

View File

@ -4,13 +4,12 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.bench4q.master.entity.User;
import org.bench4q.master.entity.db.User;
import org.bench4q.master.helper.StringHelper;
import org.bench4q.master.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@ -58,12 +57,12 @@ public class AuthenticationManager {
return this.extractUser(accessToken);
}
public boolean checkScope(HttpServletRequest request, String scope) {
public boolean checkScope(HttpServletRequest request, byte scope) {
AccessToken accessToken = this.getAccessToken(request);
if (accessToken == null) {
return false;
}
return accessToken.getScope().contains(scope);
return accessToken.getScope() >= scope;
}
public String generateCredential(User user) {
@ -105,8 +104,7 @@ public class AuthenticationManager {
accessToken.setPassword(user.getPassword());
accessToken.setUserName(user.getUserName());
// TODO: scope
accessToken.setScope(new ArrayList<String>());
accessToken.getScope().add("all");
accessToken.setScope(user.getScope());
return accessToken;
}

View File

@ -1,46 +0,0 @@
package org.bench4q.master.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "behavior")
public class behavior {
//id is the identifier only in database, in fact, behaviorstring is the identifier in the dtd
private int id;
private int Script_id;
private String behaviorstring;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "script_id", nullable = false)
public int getScript_id() {
return Script_id;
}
public void setScript_id(int script_id) {
Script_id = script_id;
}
@Column(name = "behaviorstring", nullable = false)
public String getBehaviorString() {
return behaviorstring;
}
public void setBehaviorString(String behaviorstring) {
this.behaviorstring = behaviorstring;
}
}

View File

@ -0,0 +1,47 @@
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "behavior")
public class Behavior {
// id is the identifier only in database, in fact, behaviorstring is the
// identifier in the dtd
private int id;
private int scriptId;
private String behaviorString;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "scriptId", nullable = false)
public int getScriptId() {
return scriptId;
}
public void setScriptId(int scriptId) {
this.scriptId = scriptId;
}
@Column(name = "behaviorString", nullable = false)
public String getBehaviorString() {
return behaviorString;
}
public void setBehaviorString(String behaviorItring) {
this.behaviorString = behaviorItring;
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -9,10 +9,10 @@ import javax.persistence.Table;
@Entity
@Table(name = "group")
public class group {
public class Group {
private int id;
private int behavior_id;
private int loadprofile_id;
private int behaviorId;
private int loadProfileId;
private String forceStop;
@Id
@ -25,12 +25,12 @@ public class group {
this.id = id;
}
@Column(name = "behavior_id", nullable = false)
public int getBehavior_id() {
return behavior_id;
@Column(name = "behaviorId", nullable = false)
public int getBehaviorId() {
return behaviorId;
}
public void setBehavior_id(int behavior_id) {
this.behavior_id = behavior_id;
public void setBehaviorId(int behaviorId) {
this.behaviorId = behaviorId;
}
@Column(name = "forceStop", nullable = false)
@ -43,10 +43,10 @@ public class group {
@Column(name = "loadprofile_id", nullable = false)
public int getLoadprofile_id() {
return loadprofile_id;
return loadProfileId;
}
public void setLoadprofile_id(int loadprofile_id) {
this.loadprofile_id = loadprofile_id;
this.loadProfileId = loadprofile_id;
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -9,9 +9,9 @@ import javax.persistence.Table;
@Entity
@Table(name = "loadprofile")
public class loadprofile {
public class LoadProfile {
private int id;
private int script_id;
private int scriptId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -24,10 +24,10 @@ public class loadprofile {
}
@Column(name = "script_id", nullable = false)
public int getScript_id() {
return script_id;
public int getScriptId() {
return scriptId;
}
public void setScript_id(int script_id) {
this.script_id = script_id;
public void setScriptId(int scriptId) {
this.scriptId = scriptId;
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -9,7 +9,7 @@ import javax.persistence.Table;
@Entity
@Table(name = "plugin")
public class plugin {
public class Plugin {
private int id;
private String use;
private String name;

View File

@ -0,0 +1,179 @@
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "sample")
public class Sample {
private int id;
private String name;
//plugin_id is the only identifier of use just in database, and use is the true id of the use in dtd
private int pluginId;
private int behaviorId;
//for params
private String paramsPassword;
private String paramsParameters;
private String paramsRealm;
private String paramsProxyport;
private String paramsCookies;
private String paramsProxypassword;
private String paramsHostauth;
private String paramsCookiepolicy;
private String paramsUri;
private String paramsUsername;
private String paramsRedirect;
private String paramsLocaladdress;
private String paramsProxylogin;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "name", nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "pluginId", nullable = false)
public int getPluginId() {
return pluginId;
}
public void setPluginId(int pluginId) {
this.pluginId = pluginId;
}
@Column(name = "behaviorId", nullable = false)
public int getBehaviorId() {
return behaviorId;
}
public void setBehaviorId(int behaviorId) {
this.behaviorId = behaviorId;
}
/**
* For Parameters in sample
*/
@Column(name = "paramsPassword", nullable = false)
public String getParamsPassword() {
return paramsPassword;
}
public void setParamsPassword(String password) {
this.paramsPassword = password;
}
@Column(name = "paramsParameters", nullable = false)
public String getParams_Parameters() {
return paramsParameters;
}
public void setParamsParameters(String parameters) {
this.paramsParameters = parameters;
}
@Column(name = "paramsRealm", nullable = false)
public String getParamsRealm() {
return paramsRealm;
}
public void setParamsRealm(String realm) {
this.paramsRealm = realm;
}
@Column(name = "paramsProxyport", nullable = false)
public String getParamsProxyport() {
return paramsProxyport;
}
public void setParamsProxyport(String proxyport) {
this.paramsProxyport = proxyport;
}
@Column(name = "paramsCookies", nullable = false)
public String getParamsCookies() {
return paramsCookies;
}
public void setParamsCookies(String cookies) {
this.paramsCookies = cookies;
}
@Column(name = "paramsProxypassword", nullable = false)
public String getParamsProxypassword() {
return paramsProxypassword;
}
public void setParamsProxypassword(String proxypassword) {
this.paramsProxypassword = proxypassword;
}
@Column(name = "paramsHostauth", nullable = false)
public String getParamsHostauth() {
return paramsHostauth;
}
public void setParamsHostauth(String hostauth) {
this.paramsHostauth = hostauth;
}
@Column(name = "paramsCookiepolicy", nullable = false)
public String getParamsCookiepolicy() {
return paramsCookiepolicy;
}
public void setParamsCookiepolicy(String cookiepolicy) {
this.paramsCookiepolicy = cookiepolicy;
}
@Column(name = "paramsUri", nullable = false)
public String getParamsUri() {
return paramsUri;
}
public void setParamsUri(String uri) {
this.paramsUri = uri;
}
@Column(name = "paramsUsername", nullable = false)
public String getParamsUsername() {
return paramsUsername;
}
public void setParamsUsername(String username) {
this.paramsUsername = username;
}
@Column(name = "paramsRedirect", nullable = false)
public String getParamsRedirect() {
return paramsRedirect;
}
public void setParamsRedirect(String redirect) {
this.paramsRedirect = redirect;
}
@Column(name = "paramsLocaladdress", nullable = false)
public String getParamsLocaladdress() {
return paramsLocaladdress;
}
public void setParamsLocaladdress(String localaddress) {
this.paramsLocaladdress = localaddress;
}
@Column(name = "paramsProxylogin", nullable = false)
public String getParamsProxylogin() {
return paramsProxylogin;
}
public void setParamsProxylogin(String proxylogin) {
this.paramsProxylogin = proxylogin;
}
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -15,8 +15,8 @@ public class Script {
private int id;
private String name;
private DateTimeDV create_datetime;
private int user_id;
private DateTimeDV createDatetime;
private int userId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -36,20 +36,20 @@ public class Script {
this.name = scriptName;
}
@Column(name = "create_datetime", nullable = false)
public DateTimeDV getCreate_datetime() {
return create_datetime;
@Column(name = "createDatetime", nullable = false)
public DateTimeDV getCreateDatetime() {
return createDatetime;
}
public void setCreate_datetime(DateTimeDV create_datetime) {
this.create_datetime = create_datetime;
public void setCreateDatetime(DateTimeDV createDatetime) {
this.createDatetime = createDatetime;
}
@Column(name = "user_id", nullable = false)
public int getUser_id() {
return user_id;
@Column(name = "userId", nullable = false)
public int getUserId() {
return userId;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
public void setUserId(int userId) {
this.userId = userId;
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -9,10 +9,10 @@ import javax.persistence.Table;
@Entity
@Table(name = "timer")
public class timer {
public class Timer {
private int id;
private int plugin_id;
private int behavior_id;
private int pluginId;
private int behaviorId;
private String name;
@Id
@ -25,12 +25,12 @@ public class timer {
this.id = id;
}
@Column(name = "plugin_id", nullable = false)
public int getPlugin_id() {
return plugin_id;
@Column(name = "pluginId", nullable = false)
public int getPluginId() {
return pluginId;
}
public void setPlugin_id(int plugin_id) {
this.plugin_id = plugin_id;
public void setPluginId(int pluginId) {
this.pluginId = pluginId;
}
@Column(name = "name", nullable = false)
@ -41,12 +41,12 @@ public class timer {
this.name = name;
}
@Column(name = "behavior_id", nullable = false)
public int getBehavior_id() {
return behavior_id;
@Column(name = "behaviorId", nullable = false)
public int getBehaviorId() {
return behaviorId;
}
public void setBehavior_id(int behavior_id) {
this.behavior_id = behavior_id;
public void setBehaviorId(int behaviorId) {
this.behaviorId = behaviorId;
}

View File

@ -1,4 +1,4 @@
package org.bench4q.master.entity;
package org.bench4q.master.entity.db;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -1,179 +0,0 @@
package org.bench4q.master.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "sample")
public class sample {
private int id;
private String name;
//plugin_id is the only identifier of use just in database, and use is the true id of the use in dtd
private int plugin_id;
private int behavior_id;
//for params
private String params_password;
private String params_parameters;
private String params_realm;
private String params_proxyport;
private String params_cookies;
private String params_proxypassword;
private String params_hostauth;
private String params_cookiepolicy;
private String params_uri;
private String params_username;
private String params_redirect;
private String params_localaddress;
private String params_proxylogin;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "name", nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "plugin_id", nullable = false)
public int getPlugin_id() {
return plugin_id;
}
public void setPlugin_id(int plugin_id) {
this.plugin_id = plugin_id;
}
@Column(name = "behavior_id", nullable = false)
public int getBehavior_id() {
return behavior_id;
}
public void setBehavior_id(int behavior_id) {
this.behavior_id = behavior_id;
}
/**
* For Parameters in sample
*/
@Column(name = "password", nullable = false)
public String getParams_Password() {
return params_password;
}
public void setParams_Password(String password) {
this.params_password = password;
}
@Column(name = "parameters", nullable = false)
public String getParams_Parameters() {
return params_parameters;
}
public void setParams_Parameters(String parameters) {
this.params_parameters = parameters;
}
@Column(name = "realm", nullable = false)
public String getParams_Realm() {
return params_realm;
}
public void setParams_Realm(String realm) {
this.params_realm = realm;
}
@Column(name = "proxyport", nullable = false)
public String getParams_Proxyport() {
return params_proxyport;
}
public void setParams_Proxyport(String proxyport) {
this.params_proxyport = proxyport;
}
@Column(name = "cookies", nullable = false)
public String getParams_Cookies() {
return params_cookies;
}
public void setParams_Cookies(String cookies) {
this.params_cookies = cookies;
}
@Column(name = "proxypassword", nullable = false)
public String getParams_Proxypassword() {
return params_proxypassword;
}
public void setParams_Proxypassword(String proxypassword) {
this.params_proxypassword = proxypassword;
}
@Column(name = "hostauth", nullable = false)
public String getParams_Hostauth() {
return params_hostauth;
}
public void setParams_Hostauth(String hostauth) {
this.params_hostauth = hostauth;
}
@Column(name = "cookiepolicy", nullable = false)
public String getParams_Cookiepolicy() {
return params_cookiepolicy;
}
public void setParams_Cookiepolicy(String cookiepolicy) {
this.params_cookiepolicy = cookiepolicy;
}
@Column(name = "uri", nullable = false)
public String getParams_Uri() {
return params_uri;
}
public void setParams_Uri(String uri) {
this.params_uri = uri;
}
@Column(name = "username", nullable = false)
public String getParams_Username() {
return params_username;
}
public void setParams_Username(String username) {
this.params_username = username;
}
@Column(name = "redirect", nullable = false)
public String getParams_Redirect() {
return params_redirect;
}
public void setParams_Redirect(String redirect) {
this.params_redirect = redirect;
}
@Column(name = "localaddress", nullable = false)
public String getParams_Localaddress() {
return params_localaddress;
}
public void setParams_Localaddress(String localaddress) {
this.params_localaddress = localaddress;
}
@Column(name = "proxylogin", nullable = false)
public String getParams_Proxylogin() {
return params_proxylogin;
}
public void setParams_Proxylogin(String proxylogin) {
this.params_proxylogin = proxylogin;
}
}

View File

@ -1,6 +1,7 @@
package org.bench4q.master.service;
import org.bench4q.master.entity.User;
import org.bench4q.master.entity.Constant;
import org.bench4q.master.entity.db.User;
import org.bench4q.master.helper.HashHelper;
import org.bench4q.master.helper.SessionHelper;
import org.hibernate.Session;
@ -44,6 +45,7 @@ public class UserService {
user = new User();
user.setUserName(userName);
user.setPassword(this.hashPassword(password));
user.setScope(Constant.NORAML_AUTHENTICATION);
session.merge(user);
transaction.commit();
return true;