v1.2.2 RC

This commit is contained in:
shimingxy
2020-03-30 10:32:39 +08:00
parent c70aa8df95
commit 6ce1481df5
28 changed files with 3112 additions and 1447 deletions

View File

@@ -1,9 +1,7 @@
package org.maxkey;
import java.util.Date;
import javax.servlet.ServletException;
import org.apache.ibatis.io.VFS;
import org.apache.mybatis.jpa.SpringBootVFS;
import org.maxkey.web.InitApplicationContext;
@@ -17,25 +15,30 @@ import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class MaxKeyApplication extends SpringBootServletInitializer {
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyApplication.class);
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyApplication.class);
public static void main(String[] args) {
VFS.addImplClass(SpringBootVFS.class);
ConfigurableApplicationContext applicationContext =SpringApplication.run(MaxKeyApplication.class, args);
InitApplicationContext initWebContext=new InitApplicationContext(applicationContext);
try {
initWebContext.init(null);
} catch (ServletException e) {
e.printStackTrace();
_logger.error("",e);
}
_logger.info("MaxKey at "+new Date(applicationContext.getStartupDate()));
_logger.info("MaxKey Server Port "+applicationContext.getBean(MaxKeyConfig.class).getPort());
_logger.info("MaxKey started.");
}
/**
* @param args args
*/
public static void main(String[] args) {
VFS.addImplClass(SpringBootVFS.class);
ConfigurableApplicationContext applicationContext =
SpringApplication.run(MaxKeyApplication.class, args);
InitApplicationContext initWebContext = new InitApplicationContext(applicationContext);
try {
initWebContext.init(null);
} catch (ServletException e) {
e.printStackTrace();
_logger.error("", e);
}
_logger.info("MaxKey at " + new Date(applicationContext.getStartupDate()));
_logger.info("MaxKey Server Port "
+ applicationContext.getBean(MaxKeyConfig.class).getPort());
_logger.info("MaxKey started.");
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MaxKeyApplication.class);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MaxKeyApplication.class);
}
}

View File

@@ -18,21 +18,21 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
@Configuration
@ImportResource(locations={"classpath:spring/maxkey.xml"})
@ImportResource(locations = { "classpath:spring/maxkey.xml" })
@PropertySource("classpath:/application.properties")
public class MaxKeyConfig {
@Value("${server.port:8080}")
@Value("${server.port:8080}")
private int port;
public int getPort() {
return port;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Bean
public void setPort(int port) {
this.port = port;
}
@Bean
public FilterRegistrationBean<TokenEndpointAuthenticationFilter> TokenEndpointAuthenticationFilter() {
FilterRegistrationBean<TokenEndpointAuthenticationFilter> registration = new FilterRegistrationBean<TokenEndpointAuthenticationFilter>();
registration.setFilter(new TokenEndpointAuthenticationFilter());
@@ -41,52 +41,50 @@ public class MaxKeyConfig {
registration.setOrder(1);
return registration;
}
/**
* 配置默认错误页面仅用于内嵌tomcat启动时
* 使用这种方式在打包为war后不起作用
/**
* 配置默认错误页面仅用于内嵌tomcat启动时 使用这种方式在打包为war后不起作用
*
* @return
*/
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
*/
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
@Override
public void customize(ConfigurableWebServerFactory factory) {
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST,"/exception/error/400");
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND,"/exception/error/404");
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/exception/error/500");
factory.addErrorPages(errorPage400, errorPage404,errorPage500);
ErrorPage errorPage400 = new ErrorPage(HttpStatus.BAD_REQUEST, "/exception/error/400");
ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/exception/error/404");
ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/exception/error/500");
factory.addErrorPages(errorPage400, errorPage404, errorPage500);
}
};
}
@Bean
public Connector connector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(80);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
}
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}
@Bean
public Connector connector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(80);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}
}

View File

@@ -1,7 +1,6 @@
package org.maxkey.web.contorller;
import java.util.List;
import org.maxkey.constants.OPERATEMESSAGE;
import org.maxkey.constants.PROTOCOLS;
import org.maxkey.crypto.ReciprocalUtils;
@@ -27,217 +26,233 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
* AppListController.
*
* @author Administrator
*
*/
@Controller
public class AppListController{
final static Logger _logger = LoggerFactory.getLogger(AppListController.class);
@Autowired
private UserInfoService userInfoService;
@Autowired
protected JdbcTemplate jdbcTemplate;
@Autowired
MyAppsListService myAppsListService;
@Autowired
AccountsService appUsersService;
@Autowired
AppsService appsService;
@RequestMapping(value={"/appList"})
public ModelAndView appList(@RequestParam(value="gridList",required = false) String gridList) {
ModelAndView modelAndView=new ModelAndView("main/appList");
if(gridList!=null&&!gridList.equals("")){
int intGridList=Integer.parseInt(gridList);
jdbcTemplate.update("UPDATE USERINFO SET GRIDLIST = ? WHERE ID = ?",
intGridList,WebContext.getUserInfo().getId());
WebContext.getUserInfo().setGridList(intGridList);
}
modelAndView.addObject("appList", queryAccessableApps());
return modelAndView;
}
@RequestMapping(value={"/appConfigList"})
public ModelAndView appConfigList() {
ModelAndView modelAndView=new ModelAndView("main/appConfigList");
modelAndView.addObject("appList", queryAccessableApps());
return modelAndView;
}
private List<UserApps> queryAccessableApps(){
UserApps userApplications=new UserApps();
userApplications.setUsername(WebContext.getUserInfo().getUsername());
List<UserApps> appList=myAppsListService.queryMyApps(userApplications);
for (UserApps app : appList){
WebContext.setAttribute(app.getId(), app.getIcon());
}
return appList;
}
public class AppListController {
static final Logger _logger = LoggerFactory.getLogger(AppListController.class);
@RequestMapping(value={"/forward/appProtectedConfig/{protocol}/{credential}/{appId}"})
public ModelAndView forwardAppLoginConfig(
@PathVariable("protocol") String protocol,
@PathVariable("credential") int credential,
@PathVariable("appId") String appId){
ModelAndView modelAndView=new ModelAndView("main/appProtectedConfig");
@Autowired
private UserInfoService userInfoService;
UserInfo userInfo=WebContext.getUserInfo();
if(userInfo.getProtectedAppsMap().get(appId)!=null){
modelAndView.addObject("protectedappId",true);
}else{
modelAndView.addObject("protectedappId",false);
}
modelAndView.addObject("uid",userInfo.getId());
modelAndView.addObject("appId",appId);
modelAndView.addObject("protocol",protocol);
modelAndView.addObject("credential",credential);
return modelAndView;
}
@ResponseBody
@RequestMapping(value={"/appProtectedConfig"})
public Message appLoginConfig(
@RequestParam("protocol") String protocol,
@RequestParam("credential") int credential,
@RequestParam("appId") String appId,
@RequestParam("protectedappId") String protectedappId,
@RequestParam("password") String password
){
@Autowired
protected JdbcTemplate jdbcTemplate;
UserInfo userInfo=WebContext.getUserInfo();
String userAppProtectedPassword=ReciprocalUtils.decoder(userInfo.getAppLoginPassword());
if(userAppProtectedPassword.equals(password)){
if(protectedappId.equalsIgnoreCase("YES")){
if(userInfo.getProtectedApps()!=null&&userInfo.getProtectedApps().indexOf(appId)<0){
userInfo.setProtectedApps(userInfo.getProtectedApps()+","+appId);
if(userInfo.getProtectedAppsMap()!=null){
userInfo.getProtectedAppsMap().put(appId, appId);
}
}else{
userInfo.setProtectedApps(","+appId);
}
}else{
if(userInfo.getProtectedApps()!=null&&userInfo.getProtectedApps().indexOf(appId)>-1){
//userInfo.setSecondProtectedApps(userInfo.getSecondProtectedApps()+","+appId);
String []protectedApps=userInfo.getProtectedApps().split(",");
String protectedAppIds="";
if(userInfo.getProtectedAppsMap()!=null){
userInfo.getProtectedAppsMap().remove(appId);
}
for(String protectedAppId:protectedApps){
if(protectedAppId.equalsIgnoreCase(appId)||protectedAppId.trim().equals(""))continue;
protectedAppIds=protectedAppIds+","+protectedAppId;
}
userInfo.setProtectedApps(protectedAppIds);
}
}
userInfoService.updateProtectedApps(userInfo);
}else{
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR),MessageType.error);
}
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),MessageType.success);
}
@RequestMapping(value={"/forward/appUserConfig/{protocol}/{credential}/{appId}"})
public ModelAndView forwardAppUserConfig(
@PathVariable("protocol") String protocol,
@PathVariable("credential") int credential,
@PathVariable("appId") String appId){
ModelAndView modelAndView=new ModelAndView("main/appUserConfig");
//modelAndView.addObject("appList",appList);
Accounts appUsers=new Accounts();
UserInfo userInfo=WebContext.getUserInfo();
if(credential==Apps.CREDENTIALS.USER_DEFINED){
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
if(protocol.equalsIgnoreCase(PROTOCOLS.DESKTOP)||
protocol.equalsIgnoreCase(PROTOCOLS.FORMBASED)||
protocol.equalsIgnoreCase(PROTOCOLS.BASIC)||
protocol.equalsIgnoreCase(PROTOCOLS.EXTEND_API)
){
modelAndView.addObject("username",true);
modelAndView.addObject("password",true);
}else if(protocol.equalsIgnoreCase(PROTOCOLS.SAML20)
){
modelAndView.addObject("username",true);
modelAndView.addObject("password",false);
}else{
modelAndView.addObject("username",false);
modelAndView.addObject("password",false);
}
if(appUsers!=null){
modelAndView.addObject("identity_username",appUsers.getRelatedUsername());
modelAndView.addObject("identity_password",ReciprocalUtils.decoder(appUsers.getRelatedPassword()));
}else{
modelAndView.addObject("identity_username","");
modelAndView.addObject("identity_password","");
}
}else{
modelAndView.addObject("username",false);
modelAndView.addObject("password",false);
}
modelAndView.addObject("uid",userInfo.getId());
modelAndView.addObject("appId",appId);
modelAndView.addObject("protocol",protocol);
modelAndView.addObject("credential",credential);
return modelAndView;
}
@ResponseBody
@RequestMapping(value={"/appUserConfig"})
public Message appUserConfig(
@RequestParam("protocol") String protocol,
@RequestParam("credential") int credential,
@RequestParam("appId") String appId,
@RequestParam("identity_username") String identity_username,
@RequestParam("identity_password") String identity_password
){
Apps app=appsService.get(appId);
UserInfo userInfo=WebContext.getUserInfo();
Accounts appUsers=new Accounts();
appUsers.setAppId(appId);
appUsers.setUid(userInfo.getId());
if(identity_password!=null&&!identity_password.equals("")&&credential==Apps.CREDENTIALS.USER_DEFINED){
appUsers=appUsersService.load(new Accounts(userInfo.getId(),appId));
if(appUsers==null){
appUsers=new Accounts();
appUsers.setId(appUsers.generateId());
appUsers.setAppId(appId);
appUsers.setAppName(app.getName());
appUsers.setUid(userInfo.getId());
appUsers.setUsername(userInfo.getUsername());
appUsers.setDisplayName(userInfo.getDisplayName());
appUsers.setRelatedUsername(identity_username);
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
appUsersService.insert(appUsers);
}else{
appUsers.setRelatedUsername(identity_username);
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
appUsersService.update(appUsers);
}
}
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),MessageType.success);
}
@Autowired
MyAppsListService myAppsListService;
@Autowired
AccountsService appUsersService;
@Autowired
AppsService appsService;
/**
* gridList.
* @param gridList 类型
* @return
*/
@RequestMapping(value = { "/appList" })
public ModelAndView appList(
@RequestParam(value = "gridList", required = false) String gridList) {
ModelAndView modelAndView = new ModelAndView("main/appList");
if (gridList != null && !gridList.equals("")) {
int intGridList = Integer.parseInt(gridList);
jdbcTemplate.update("UPDATE USERINFO SET GRIDLIST = ? WHERE ID = ?", intGridList,
WebContext.getUserInfo().getId());
WebContext.getUserInfo().setGridList(intGridList);
}
modelAndView.addObject("appList", queryAccessableApps());
return modelAndView;
}
@RequestMapping(value = { "/appConfigList" })
public ModelAndView appConfigList() {
ModelAndView modelAndView = new ModelAndView("main/appConfigList");
modelAndView.addObject("appList", queryAccessableApps());
return modelAndView;
}
private List<UserApps> queryAccessableApps() {
UserApps userApplications = new UserApps();
userApplications.setUsername(WebContext.getUserInfo().getUsername());
List<UserApps> appList = myAppsListService.queryMyApps(userApplications);
for (UserApps app : appList) {
WebContext.setAttribute(app.getId(), app.getIcon());
}
return appList;
}
/**
* forwardAppLoginConfig.
* @param protocol protocol
* @param credential credential
* @param appId appId
* @return
*/
@RequestMapping(value = { "/forward/appProtectedConfig/{protocol}/{credential}/{appId}" })
public ModelAndView forwardAppLoginConfig(@PathVariable("protocol") String protocol,
@PathVariable("credential") int credential, @PathVariable("appId") String appId) {
ModelAndView modelAndView = new ModelAndView("main/appProtectedConfig");
UserInfo userInfo = WebContext.getUserInfo();
if (userInfo.getProtectedAppsMap().get(appId) != null) {
modelAndView.addObject("protectedappId", true);
} else {
modelAndView.addObject("protectedappId", false);
}
modelAndView.addObject("uid", userInfo.getId());
modelAndView.addObject("appId", appId);
modelAndView.addObject("protocol", protocol);
modelAndView.addObject("credential", credential);
return modelAndView;
}
/**
* appLoginConfig.
* @param protocol protocol
* @param credential credential
* @param appId appId
* @param protectedappId protectedappId
* @param password password
* @return
*/
@ResponseBody
@RequestMapping(value = { "/appProtectedConfig" })
public Message appLoginConfig(
@RequestParam("protocol") String protocol,
@RequestParam("credential") int credential,
@RequestParam("appId") String appId,
@RequestParam("protectedappId") String protectedappId,
@RequestParam("password") String password) {
UserInfo userInfo = WebContext.getUserInfo();
String userAppProtectedPassword = ReciprocalUtils.decoder(userInfo.getAppLoginPassword());
if (userAppProtectedPassword.equals(password)) {
if (protectedappId.equalsIgnoreCase("YES")) {
if (userInfo.getProtectedApps() != null
&& userInfo.getProtectedApps().indexOf(appId) < 0) {
userInfo.setProtectedApps(userInfo.getProtectedApps() + "," + appId);
if (userInfo.getProtectedAppsMap() != null) {
userInfo.getProtectedAppsMap().put(appId, appId);
}
} else {
userInfo.setProtectedApps("," + appId);
}
} else {
if (userInfo.getProtectedApps() != null
&& userInfo.getProtectedApps().indexOf(appId) > -1) {
// userInfo.setSecondProtectedApps(userInfo.getSecondProtectedApps()+","+appId);
String[] protectedApps = userInfo.getProtectedApps().split(",");
String protectedAppIds = "";
if (userInfo.getProtectedAppsMap() != null) {
userInfo.getProtectedAppsMap().remove(appId);
}
for (String protectedAppId : protectedApps) {
if (protectedAppId.equalsIgnoreCase(appId)
|| protectedAppId.trim().equals("")) {
continue;
}
protectedAppIds = protectedAppIds + "," + protectedAppId;
}
userInfo.setProtectedApps(protectedAppIds);
}
}
userInfoService.updateProtectedApps(userInfo);
} else {
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR), MessageType.error);
}
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS), MessageType.success);
}
@RequestMapping(value = { "/forward/appUserConfig/{protocol}/{credential}/{appId}" })
public ModelAndView forwardAppUserConfig(@PathVariable("protocol") String protocol,
@PathVariable("credential") int credential, @PathVariable("appId") String appId) {
ModelAndView modelAndView = new ModelAndView("main/appUserConfig");
// modelAndView.addObject("appList",appList);
Accounts appUsers = new Accounts();
UserInfo userInfo = WebContext.getUserInfo();
if (credential == Apps.CREDENTIALS.USER_DEFINED) {
appUsers = appUsersService.load(new Accounts(userInfo.getId(), appId));
if (protocol.equalsIgnoreCase(PROTOCOLS.DESKTOP) || protocol.equalsIgnoreCase(PROTOCOLS.FORMBASED)
|| protocol.equalsIgnoreCase(PROTOCOLS.BASIC) || protocol.equalsIgnoreCase(PROTOCOLS.EXTEND_API)) {
modelAndView.addObject("username", true);
modelAndView.addObject("password", true);
} else if (protocol.equalsIgnoreCase(PROTOCOLS.SAML20)) {
modelAndView.addObject("username", true);
modelAndView.addObject("password", false);
} else {
modelAndView.addObject("username", false);
modelAndView.addObject("password", false);
}
if (appUsers != null) {
modelAndView.addObject("identity_username", appUsers.getRelatedUsername());
modelAndView.addObject("identity_password", ReciprocalUtils.decoder(appUsers.getRelatedPassword()));
} else {
modelAndView.addObject("identity_username", "");
modelAndView.addObject("identity_password", "");
}
} else {
modelAndView.addObject("username", false);
modelAndView.addObject("password", false);
}
modelAndView.addObject("uid", userInfo.getId());
modelAndView.addObject("appId", appId);
modelAndView.addObject("protocol", protocol);
modelAndView.addObject("credential", credential);
return modelAndView;
}
@ResponseBody
@RequestMapping(value = { "/appUserConfig" })
public Message appUserConfig(@RequestParam("protocol") String protocol, @RequestParam("credential") int credential,
@RequestParam("appId") String appId, @RequestParam("identity_username") String identity_username,
@RequestParam("identity_password") String identity_password) {
Apps app = appsService.get(appId);
UserInfo userInfo = WebContext.getUserInfo();
Accounts appUsers = new Accounts();
appUsers.setAppId(appId);
appUsers.setUid(userInfo.getId());
if (identity_password != null && !identity_password.equals("") && credential == Apps.CREDENTIALS.USER_DEFINED) {
appUsers = appUsersService.load(new Accounts(userInfo.getId(), appId));
if (appUsers == null) {
appUsers = new Accounts();
appUsers.setId(appUsers.generateId());
appUsers.setAppId(appId);
appUsers.setAppName(app.getName());
appUsers.setUid(userInfo.getId());
appUsers.setUsername(userInfo.getUsername());
appUsers.setDisplayName(userInfo.getDisplayName());
appUsers.setRelatedUsername(identity_username);
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
appUsersService.insert(appUsers);
} else {
appUsers.setRelatedUsername(identity_username);
appUsers.setRelatedPassword(ReciprocalUtils.encode(identity_password));
appUsersService.update(appUsers);
}
}
return new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS), MessageType.success);
}
}

View File

@@ -19,120 +19,119 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value={"/forgotpassword"})
@RequestMapping(value = { "/forgotpassword" })
public class ForgotPasswordContorller {
private static Logger _logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
@Autowired
ForgotPasswordService forgotPasswordService;
@Autowired
private UserInfoService userInfoService;
@Autowired
protected ApplicationConfig applicationConfig;
@Autowired
private PasswordEncoder passwordEncoder;
@RequestMapping(value={"/forward"})
public ModelAndView forwardreg() {
_logger.debug("Registration /forgotpassword/forward.");
return new ModelAndView("forgotpassword/forward");
}
@RequestMapping(value={"/email"})
public ModelAndView email(@RequestParam String email) {
_logger.debug("Registration /forgotpassword/email.");
_logger.debug("email : "+email);
UserInfo userInfo=forgotPasswordService.queryUserInfoByEmail(email);
ModelAndView modelAndView=new ModelAndView("forgotpassword/email");
modelAndView.addObject("emailsend", 0);
modelAndView.addObject("email", email);
if(userInfo!=null){
ForgotPassword forgotPassword =new ForgotPassword();
forgotPassword.setId(forgotPassword.generateId());
forgotPassword.setEmail(email);
forgotPassword.setUid(userInfo.getId());
forgotPassword.setUsername(userInfo.getUsername());
forgotPasswordService.insert(forgotPassword);
HtmlEmail hemail = new HtmlEmail();
try {
hemail.setHostName(applicationConfig.getEmailConfig().getSmtpHost());
hemail.setSmtpPort(applicationConfig.getEmailConfig().getPort());
hemail.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(), applicationConfig.getEmailConfig().getPassword()));
hemail.addTo(userInfo.getEmail(), userInfo.getNickName());
hemail.setFrom(applicationConfig.getEmailConfig().getSenderMail(), "ConnSec");
hemail.setSubject("ConnSec Cloud Identity & Access ReSet Password .");
// set the html message
String forgotPasswordUrl=WebContext.getHttpContextPath()+"/forgotpassword/resetpwd/"+forgotPassword.getId();
// set the html message
String emailText="<html>";
emailText+="<a href='"+forgotPasswordUrl+"'>Reset Password</a><br>";
emailText+=" or copy "+forgotPasswordUrl+" to brower.";
emailText+="</html>";
hemail.setHtmlMsg(emailText);
// set the alternative message
hemail.setTextMsg("Your email client does not support HTML messages");
// send the email
hemail.send();
modelAndView.addObject("emailsend", 1);
} catch (EmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return modelAndView ;
}
@RequestMapping(value={"/resetpwd/{id}"})
public ModelAndView resetpwd(@PathVariable("id") String id) {
_logger.debug("Registration /forgotpassword/resetpwd.");
ForgotPassword forgotPassword=forgotPasswordService.get(id);
ModelAndView mav=new ModelAndView("forgotpassword/resetpwd");
if(forgotPassword!=null){
mav.addObject("model", forgotPassword);
}
return mav;
}
@RequestMapping(value={"/setpassword/{id}"})
public ModelAndView setPassWord(@PathVariable("id") String id,@RequestParam String password,@RequestParam String confirmpassword) {
_logger.debug("forgotPassword /forgotPassword/pwdreseted.");
ModelAndView modelAndView=new ModelAndView("forgotpassword/pwdreseted");
if(password.equals(confirmpassword)){
ForgotPassword forgotPassword=forgotPasswordService.get(id);
if(forgotPassword!=null){
UserInfo userInfo=new UserInfo();
userInfo.setId(forgotPassword.getUid());
userInfo.setPassword(password);
userInfo.setDecipherable(password);
userInfo.setUsername(forgotPassword.getUsername());
userInfoService.changePassword(userInfo);
forgotPasswordService.remove(id);
modelAndView.addObject("pwdreseted", 1);
}else{
modelAndView.addObject("pwdreseted", 2);
}
}else{
modelAndView.addObject("pwdreseted", 0);
}
return modelAndView;
}
private static Logger _logger = LoggerFactory.getLogger(ForgotPasswordContorller.class);
@Autowired
ForgotPasswordService forgotPasswordService;
@Autowired
private UserInfoService userInfoService;
@Autowired
protected ApplicationConfig applicationConfig;
@Autowired
private PasswordEncoder passwordEncoder;
@RequestMapping(value = { "/forward" })
public ModelAndView forwardreg() {
_logger.debug("Registration /forgotpassword/forward.");
return new ModelAndView("forgotpassword/forward");
}
@RequestMapping(value = { "/email" })
public ModelAndView email(@RequestParam String email) {
_logger.debug("Registration /forgotpassword/email.");
_logger.debug("email : " + email);
UserInfo userInfo = forgotPasswordService.queryUserInfoByEmail(email);
ModelAndView modelAndView = new ModelAndView("forgotpassword/email");
modelAndView.addObject("emailsend", 0);
modelAndView.addObject("email", email);
if (userInfo != null) {
ForgotPassword forgotPassword = new ForgotPassword();
forgotPassword.setId(forgotPassword.generateId());
forgotPassword.setEmail(email);
forgotPassword.setUid(userInfo.getId());
forgotPassword.setUsername(userInfo.getUsername());
forgotPasswordService.insert(forgotPassword);
HtmlEmail hemail = new HtmlEmail();
try {
hemail.setHostName(applicationConfig.getEmailConfig().getSmtpHost());
hemail.setSmtpPort(applicationConfig.getEmailConfig().getPort());
hemail.setAuthenticator(new DefaultAuthenticator(applicationConfig.getEmailConfig().getUsername(),
applicationConfig.getEmailConfig().getPassword()));
hemail.addTo(userInfo.getEmail(), userInfo.getNickName());
hemail.setFrom(applicationConfig.getEmailConfig().getSenderMail(), "ConnSec");
hemail.setSubject("ConnSec Cloud Identity & Access ReSet Password .");
// set the html message
String forgotPasswordUrl = WebContext.getHttpContextPath() + "/forgotpassword/resetpwd/"
+ forgotPassword.getId();
// set the html message
String emailText = "<html>";
emailText += "<a href='" + forgotPasswordUrl + "'>Reset Password</a><br>";
emailText += " or copy " + forgotPasswordUrl + " to brower.";
emailText += "</html>";
hemail.setHtmlMsg(emailText);
// set the alternative message
hemail.setTextMsg("Your email client does not support HTML messages");
// send the email
hemail.send();
modelAndView.addObject("emailsend", 1);
} catch (EmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return modelAndView;
}
@RequestMapping(value = { "/resetpwd/{id}" })
public ModelAndView resetpwd(@PathVariable("id") String id) {
_logger.debug("Registration /forgotpassword/resetpwd.");
ForgotPassword forgotPassword = forgotPasswordService.get(id);
ModelAndView mav = new ModelAndView("forgotpassword/resetpwd");
if (forgotPassword != null) {
mav.addObject("model", forgotPassword);
}
return mav;
}
@RequestMapping(value = { "/setpassword/{id}" })
public ModelAndView setPassWord(@PathVariable("id") String id, @RequestParam String password,
@RequestParam String confirmpassword) {
_logger.debug("forgotPassword /forgotPassword/pwdreseted.");
ModelAndView modelAndView = new ModelAndView("forgotpassword/pwdreseted");
if (password.equals(confirmpassword)) {
ForgotPassword forgotPassword = forgotPasswordService.get(id);
if (forgotPassword != null) {
UserInfo userInfo = new UserInfo();
userInfo.setId(forgotPassword.getUid());
userInfo.setPassword(password);
userInfo.setDecipherable(password);
userInfo.setUsername(forgotPassword.getUsername());
userInfoService.changePassword(userInfo);
forgotPasswordService.remove(id);
modelAndView.addObject("pwdreseted", 1);
} else {
modelAndView.addObject("pwdreseted", 2);
}
} else {
modelAndView.addObject("pwdreseted", 0);
}
return modelAndView;
}
}

View File

@@ -2,13 +2,12 @@ package org.maxkey.web.contorller;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.dao.service.HistoryLoginAppsService;
import org.maxkey.dao.service.HistoryLoginService;
import org.maxkey.dao.service.HistoryLogsService;
import org.maxkey.domain.HistoryLoginApps;
import org.maxkey.domain.HistoryLogin;
import org.maxkey.domain.HistoryLoginApps;
import org.maxkey.domain.HistoryLogs;
import org.maxkey.util.DateUtils;
import org.maxkey.web.WebContext;
@@ -24,89 +23,89 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 登录日志和操作日志查询
* 登录日志和操作日志查询.
*
* @author Crystal.sea
*
*/
@Controller
@RequestMapping(value={"/historys"})
@RequestMapping(value = { "/historys" })
public class HistorysController {
final static Logger _logger = LoggerFactory.getLogger(HistorysController.class);
@Autowired
HistoryLoginService historyLoginService;
@Autowired
protected HistoryLoginAppsService historyLoginAppsService;
@Autowired
HistoryLogsService historyLogsService;
@RequestMapping(value={"/logs"})
public String List(){
return "historys/logsList";
}
/**
* 查询操作日志
* @param logs
* @return
*/
@RequestMapping(value={"/logs/grid"})
@ResponseBody
public JpaPageResults<HistoryLogs> logsDataGrid(@ModelAttribute("historyLogs") HistoryLogs historyLogs){
_logger.debug("history/logs/grid/ logsGrid() "+historyLogs);
return historyLogsService.queryPageResults(historyLogs);
}
static final Logger _logger = LoggerFactory.getLogger(HistorysController.class);
@RequestMapping(value={"/login"})
public String authList(){
return "historys/loginList";
}
/**
* 查询登录日志
* @param logsAuth
* @return
*/
@RequestMapping(value={"/login/grid"})
@ResponseBody
public JpaPageResults<HistoryLogin> logAuthsGrid(@ModelAttribute("historyLogin") HistoryLogin historyLogin){
_logger.debug("history/login/grid/ logsGrid() "+historyLogin);
historyLogin.setUid(WebContext.getUserInfo().getId());
return historyLoginService.queryPageResults(historyLogin);
}
@Autowired
HistoryLoginService historyLoginService;
@RequestMapping(value={"/loginApps"})
public String loginAppHistoryList(){
return "historys/loginAppsList";
}
/**
* 查询单点登录日志
* @param logsSso
* @return
*/
@RequestMapping(value={"/loginApps/grid"})
@ResponseBody
public JpaPageResults<HistoryLoginApps> logsSsoGrid(@ModelAttribute("historyLoginApps") HistoryLoginApps historyLoginApps){
_logger.debug("history/loginApps/grid/ logsGrid() "+historyLoginApps);
historyLoginApps.setId(null);
return historyLoginAppsService.queryPageResults(historyLoginApps);
@Autowired
protected HistoryLoginAppsService historyLoginAppsService;
}
@Autowired
HistoryLogsService historyLogsService;
@RequestMapping(value = { "/logs" })
public String List() {
return "historys/logsList";
}
@InitBinder
/**
* 查询操作日志.
*
* @param logs
* @return
*/
@RequestMapping(value = { "/logs/grid" })
@ResponseBody
public JpaPageResults<HistoryLogs> logsDataGrid(@ModelAttribute("historyLogs") HistoryLogs historyLogs) {
_logger.debug("history/logs/grid/ logsGrid() " + historyLogs);
return historyLogsService.queryPageResults(historyLogs);
}
@RequestMapping(value = { "/login" })
public String authList() {
return "historys/loginList";
}
/**
* 查询登录日志.
*
* @param logsAuth
* @return
*/
@RequestMapping(value = { "/login/grid" })
@ResponseBody
public JpaPageResults<HistoryLogin> logAuthsGrid(@ModelAttribute("historyLogin") HistoryLogin historyLogin) {
_logger.debug("history/login/grid/ logsGrid() " + historyLogin);
historyLogin.setUid(WebContext.getUserInfo().getId());
return historyLoginService.queryPageResults(historyLogin);
}
@RequestMapping(value = { "/loginApps" })
public String loginAppHistoryList() {
return "historys/loginAppsList";
}
/**
* 查询单点登录日志.
*
* @param logsSso
* @return
*/
@RequestMapping(value = { "/loginApps/grid" })
@ResponseBody
public JpaPageResults<HistoryLoginApps> logsSsoGrid(
@ModelAttribute("historyLoginApps") HistoryLoginApps historyLoginApps) {
_logger.debug("history/loginApps/grid/ logsGrid() " + historyLoginApps);
historyLoginApps.setId(null);
return historyLoginAppsService.queryPageResults(historyLoginApps);
}
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtils.FORMAT_DATE_HH_MM_SS);
dateFormat.setLenient(false);
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}

View File

@@ -2,7 +2,6 @@ package org.maxkey.web.contorller;
import java.awt.image.BufferedImage;
import java.util.UUID;
import org.apache.commons.codec.binary.Hex;
import org.maxkey.crypto.Base32Utils;
import org.maxkey.crypto.password.PasswordReciprocal;
@@ -11,8 +10,8 @@ import org.maxkey.crypto.password.opt.algorithm.OTPSecret;
import org.maxkey.dao.service.UserInfoService;
import org.maxkey.domain.UserInfo;
import org.maxkey.util.RQCodeUtils;
import org.maxkey.web.WebContext;
import org.maxkey.web.ImageEndpoint;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,127 +22,128 @@ import org.springframework.web.servlet.ModelAndView;
/**
* .
* @author Crystal.Sea
*
*/
@Controller
@RequestMapping(value = { "/safe/otp" })
@RequestMapping(value = { "/safe/otp" })
public class OneTimePasswordController {
final static Logger _logger = LoggerFactory.getLogger(OneTimePasswordController.class);
static final Logger _logger = LoggerFactory.getLogger(OneTimePasswordController.class);
@Autowired
@Qualifier("userInfoService")
private UserInfoService userInfoService;
@Autowired
@Qualifier("keyUriFormat")
KeyUriFormat keyUriFormat;
@Autowired
@Qualifier("userInfoService")
private UserInfoService userInfoService;
@Autowired
@Qualifier("passwordReciprocal")
PasswordReciprocal passwordReciprocal;
@RequestMapping(value={"/timebased"})
public ModelAndView timebased(){
ModelAndView modelAndView=new ModelAndView("safe/timeBased");
UserInfo userInfo=WebContext.getUserInfo();
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
String otpauth=keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRQCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value={"gen/timebased"})
public ModelAndView gentimebased(){
UserInfo userInfo=WebContext.getUserInfo();
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret=Base32Utils.encode(byteSharedSecret);
sharedSecret=passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/timebased");
}
@Autowired
@Qualifier("keyUriFormat")
KeyUriFormat keyUriFormat;
@RequestMapping(value={"/counterbased"})
public ModelAndView counterbased(){
ModelAndView modelAndView=new ModelAndView("safe/counterBased");
UserInfo userInfo=WebContext.getUserInfo();
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth=keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRQCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value={"gen/counterbased"})
public ModelAndView gencounterbased(){
UserInfo userInfo=WebContext.getUserInfo();
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret=Base32Utils.encode(byteSharedSecret);
sharedSecret=passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfo.setSharedCounter("0");
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/counterbased");
}
@Autowired
@Qualifier("passwordReciprocal")
PasswordReciprocal passwordReciprocal;
@RequestMapping(value={"/hotp"})
public ModelAndView hotp(){
ModelAndView modelAndView=new ModelAndView("safe/hotp");
UserInfo userInfo=WebContext.getUserInfo();
String sharedSecret=passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth=keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret=Base32Utils.decode(sharedSecret);
String hexSharedSecret=Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRQCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value={"gen/hotp"})
public ModelAndView genhotp(){
UserInfo userInfo=WebContext.getUserInfo();
byte[] byteSharedSecret=OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret=Base32Utils.encode(byteSharedSecret);
sharedSecret=passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfo.setSharedCounter("0");
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/hotp");
}
public String genRQCode(String otpauth){
BufferedImage bufferedImage = RQCodeUtils.write2BufferedImage(otpauth, "gif", 300, 300);
byte[] imageByte=ImageEndpoint.bufferedImage2Byte(bufferedImage);
String uuid=UUID.randomUUID().toString().toLowerCase();
WebContext.getSession().setAttribute(uuid, imageByte);
return uuid;
}
@RequestMapping(value = {"/timebased"})
public ModelAndView timebased() {
ModelAndView modelAndView = new ModelAndView("safe/timeBased");
UserInfo userInfo = WebContext.getUserInfo();
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
String otpauth = keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRqCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value = {"gen/timebased"})
public ModelAndView gentimebased() {
UserInfo userInfo = WebContext.getUserInfo();
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret = Base32Utils.encode(byteSharedSecret);
sharedSecret = passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/timebased");
}
@RequestMapping(value = {"/counterbased"})
public ModelAndView counterbased() {
ModelAndView modelAndView = new ModelAndView("safe/counterBased");
UserInfo userInfo = WebContext.getUserInfo();
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth = keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRqCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value = {"gen/counterbased"})
public ModelAndView gencounterbased() {
UserInfo userInfo = WebContext.getUserInfo();
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret = Base32Utils.encode(byteSharedSecret);
sharedSecret = passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfo.setSharedCounter("0");
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/counterbased");
}
@RequestMapping(value = {"/hotp"})
public ModelAndView hotp() {
ModelAndView modelAndView = new ModelAndView("safe/hotp");
UserInfo userInfo = WebContext.getUserInfo();
String sharedSecret = passwordReciprocal.decoder(userInfo.getSharedSecret());
keyUriFormat.setSecret(sharedSecret);
keyUriFormat.setCounter(Long.parseLong(userInfo.getSharedCounter()));
String otpauth = keyUriFormat.format(userInfo.getUsername());
byte[] byteSharedSecret = Base32Utils.decode(sharedSecret);
String hexSharedSecret = Hex.encodeHexString(byteSharedSecret);
modelAndView.addObject("id", genRqCode(otpauth));
modelAndView.addObject("userInfo", userInfo);
modelAndView.addObject("format", keyUriFormat);
modelAndView.addObject("sharedSecret", sharedSecret);
modelAndView.addObject("hexSharedSecret", hexSharedSecret);
return modelAndView;
}
@RequestMapping(value = {"gen/hotp"})
public ModelAndView genhotp() {
UserInfo userInfo = WebContext.getUserInfo();
byte[] byteSharedSecret = OTPSecret.generate(keyUriFormat.getCrypto());
String sharedSecret = Base32Utils.encode(byteSharedSecret);
sharedSecret = passwordReciprocal.encode(sharedSecret);
userInfo.setSharedSecret(sharedSecret);
userInfo.setSharedCounter("0");
userInfoService.changeSharedSecret(userInfo);
WebContext.setUserInfo(userInfo);
return WebContext.redirect("/safe/otp/hotp");
}
public String genRqCode(String otpauth) {
BufferedImage bufferedImage = RQCodeUtils.write2BufferedImage(otpauth, "gif", 300, 300);
byte[] imageByte = ImageEndpoint.bufferedImage2Byte(bufferedImage);
String uuid = UUID.randomUUID().toString().toLowerCase();
WebContext.getSession().setAttribute(uuid, imageByte);
return uuid;
}
}

View File

@@ -1,7 +1,6 @@
package org.maxkey.web.contorller;
import javax.validation.Valid;
import org.maxkey.constants.OPERATEMESSAGE;
import org.maxkey.dao.service.MyProfileService;
import org.maxkey.dao.service.UserInfoService;
@@ -20,45 +19,45 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value={"/profile"})
@RequestMapping(value = { "/profile" })
public class ProfileController {
final static Logger _logger = LoggerFactory.getLogger(ProfileController.class);
@Autowired
private UserInfoService userInfoService;
@Autowired
private MyProfileService myProfileService;
@RequestMapping(value={"/myProfile"})
public ModelAndView forwardBasic(){
ModelAndView modelAndView=new ModelAndView("profile/myProfile");
UserInfo userInfo=userInfoService.loadByUsername(WebContext.getUserInfo().getUsername());
WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
// HashMap<String,Object>extraAttributeMap=new HashMap<String,Object>();
// extraAttributeMap=(HashMap<String,Object>)JsonUtils.json2Object(userInfo.getExtraAttribute(),extraAttributeMap);
// modelAndView.addObject("extraAttributeMap", extraAttributeMap);
// _logger.info("extraAttributeMap : "+extraAttributeMap);
modelAndView.addObject("model", userInfo);
return modelAndView;
}
/**
* 修改用户
* @param userInfo
* @param result
* @return
*/
@RequestMapping(value="/update/myProfile")
public ModelAndView updatebasic(@Valid @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) {
_logger.debug(userInfo.toString());
static final Logger _logger = LoggerFactory.getLogger(ProfileController.class);
@Autowired
private UserInfoService userInfoService;
@Autowired
private MyProfileService myProfileService;
@RequestMapping(value = { "/myProfile" })
public ModelAndView forwardBasic() {
ModelAndView modelAndView = new ModelAndView("profile/myProfile");
UserInfo userInfo = userInfoService.loadByUsername(WebContext.getUserInfo().getUsername());
WebContext.getSession().setAttribute(userInfo.getId(), userInfo.getPicture());
// HashMap<String,Object>extraAttributeMap=new HashMap<String,Object>();
// extraAttributeMap=(HashMap<String,Object>)JsonUtils.json2Object(userInfo.getExtraAttribute(),extraAttributeMap);
// modelAndView.addObject("extraAttributeMap", extraAttributeMap);
// _logger.info("extraAttributeMap : "+extraAttributeMap);
//
modelAndView.addObject("model", userInfo);
return modelAndView;
}
/**
* 修改用户.
*
* @param userInfo
* @param result
* @return
*/
@RequestMapping(value = "/update/myProfile")
public ModelAndView updatebasic(
@Valid @ModelAttribute("userInfo") UserInfo userInfo,
BindingResult result) {
_logger.debug(userInfo.toString());
// if(userInfo.getExtraAttributeValue()!=null){
// String []extraAttributeLabel=userInfo.getExtraAttributeName().split(",");
// String []extraAttributeValue=userInfo.getExtraAttributeValue().split(",");
@@ -69,16 +68,19 @@ public class ProfileController {
// String extraAttribute=JsonUtils.object2Json(extraAttributeMap);
// userInfo.setExtraAttribute(extraAttribute);
// }
if(myProfileService.updateProfile(userInfo)>0) {
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB);
}else{
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR),MessageType.error);
}
return WebContext.forward("forwardMyProfile");
}
if (myProfileService.updateProfile(userInfo) > 0) {
new Message(
WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_SUCCESS),
userInfo, MessageType.success,
OperateType.add, MessageScope.DB);
} else {
new Message(WebContext.getI18nValue(OPERATEMESSAGE.UPDATE_ERROR), MessageType.error);
}
return WebContext.forward("forwardMyProfile");
}
}

View File

@@ -1,7 +1,6 @@
package org.maxkey.web.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -12,7 +11,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.maxkey.config.ApplicationConfig;
import org.maxkey.domain.IpAddrFilter;
import org.maxkey.web.WebContext;
@@ -24,58 +22,59 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class IpAddressFilter implements Filter {
private static final Logger _logger = LoggerFactory.getLogger(IpAddressFilter.class);
@Autowired
@Qualifier("applicationConfig")
private ApplicationConfig applicationConfig;
boolean whiteList=false;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
private static final Logger _logger = LoggerFactory.getLogger(IpAddressFilter.class);
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if(applicationConfig==null){
_logger.info("applicationConfig init .");
applicationConfig=WebApplicationContextUtils.getWebApplicationContext(request.getServletContext()).getBean("applicationConfig", ApplicationConfig.class);
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession();
String ipAddress=WebContext.getRequestIpAddress(httpServletRequest);
_logger.trace("IpAddress "+ipAddress);
//黑名单地址
if(IpAddressCache.ipAddressBlackListMap.containsKey(ipAddress)){
IpAddrFilter ipAddrFilter=IpAddressCache.ipAddressBlackListMap.get(ipAddress);
_logger.info("You IpAddress in Black List "+ipAddrFilter);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return ;
@Autowired
@Qualifier("applicationConfig")
private ApplicationConfig applicationConfig;
}
//白名单地址
if(whiteList&&!IpAddressCache.ipAddressWhiteListMap.containsKey(ipAddress)){
_logger.info("You IpAddress not in White List "+ipAddress);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return ;
}
chain.doFilter(request, response);
}
boolean whiteList = false;
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (applicationConfig == null) {
_logger.info("applicationConfig init .");
applicationConfig = WebApplicationContextUtils.getWebApplicationContext(
request.getServletContext())
.getBean("applicationConfig", ApplicationConfig.class);
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession();
String ipAddress = WebContext.getRequestIpAddress(httpServletRequest);
_logger.trace("IpAddress " + ipAddress);
// 黑名单地址
if (IpAddressCache.ipAddressBlackListMap.containsKey(ipAddress)) {
IpAddrFilter ipAddrFilter = IpAddressCache.ipAddressBlackListMap.get(ipAddress);
_logger.info("You IpAddress in Black List " + ipAddrFilter);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return;
}
// 白名单地址
if (whiteList && !IpAddressCache.ipAddressWhiteListMap.containsKey(ipAddress)) {
_logger.info("You IpAddress not in White List " + ipAddress);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return;
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}

View File

@@ -10,40 +10,45 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.maxkey.util.StringUtils;
import org.maxkey.web.WebConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* SingleSignOnFilter.
* @author Crystal.Sea
*/
public class SingleSignOnFilter implements Filter {
private static final Logger _logger = LoggerFactory.getLogger(SingleSignOnFilter.class);
public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
private static final Logger _logger = LoggerFactory.getLogger(SingleSignOnFilter.class);
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession();
//浠巗ession涓幏鍙栧瓨鏀剧殑appid
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
//鑾峰彇鏈<E5BD87>鍚庝竴涓<E7ABB4>"/"鐨勬暟鎹綔涓篴ppid锛屼繚瀛樺湪session涓<6E>
if(StringUtils.isNullOrBlank(appId)) {
String uir = httpServletRequest.getRequestURI();
session.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, uir.substring(uir.lastIndexOf("/")+1));
session.setAttribute("protocol", "formbase");
}
chain.doFilter(request, response);
}
public void destroy() {
_logger.debug(" destroy.");
}
/**
*doFilter.
*/
public void doFilter(ServletRequest request,
ServletResponse response, FilterChain chain)throws IOException, ServletException {
public void init(FilterConfig config) throws ServletException {
_logger.debug(" init.");
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession();
// 浠巗ession涓幏鍙栧瓨鏀剧殑appid
String appId = (String) session.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
// 鑾峰彇鏈<E5BD87>鍚庝竴涓<E7ABB4>"/"鐨勬暟鎹綔涓篴ppid锛屼繚瀛樺湪session涓<6E>
if (StringUtils.isNullOrBlank(appId)) {
String uir = httpServletRequest.getRequestURI();
session.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID,
uir.substring(uir.lastIndexOf("/") + 1));
session.setAttribute("protocol", "formbase");
}
chain.doFilter(request, response);
}
public void destroy() {
_logger.debug(" destroy.");
}
public void init(FilterConfig config) throws ServletException {
_logger.debug(" init.");
}
}

View File

@@ -1,9 +1,7 @@
package org.maxkey.web.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
import org.maxkey.dao.service.AppsService;
import org.maxkey.dao.service.HistoryLoginAppsService;
@@ -20,42 +18,47 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class HistoryLoginAppAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(HistoryLoginAppAdapter.class);
private static final Logger _logger = LoggerFactory.getLogger(HistoryLoginAppAdapter.class);
@Autowired
HistoryLoginAppsService historyLoginAppsService;
@Autowired
@Qualifier("appsService")
protected AppsService appsService;
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
_logger.debug("postHandle");
String appId=null;
if(WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID)!=null){
appId=WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID).toString();
}
if(appId==null){
PreLoginAppAdapter.getAppIdFromRequestURI(request);
}
//Applications app=applicationsService.get(appId);
Apps app=(Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
String sessionId=(String)WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
UserInfo userInfo =WebContext.getUserInfo();
_logger.debug("sessionId : "+sessionId+" ,appId : "+appId);
HistoryLoginApps historyLoginApps=new HistoryLoginApps();
historyLoginApps.setId(historyLoginApps.generateId());
historyLoginApps.setAppId(appId);
historyLoginApps.setSessionId(sessionId);
historyLoginApps.setAppName(app.getName());
historyLoginApps.setUid(userInfo.getId());
historyLoginApps.setUsername(userInfo.getUsername());
historyLoginApps.setDisplayName(userInfo.getDisplayName());
historyLoginAppsService.insert(historyLoginApps);
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
}
@Autowired
HistoryLoginAppsService historyLoginAppsService;
@Autowired
@Qualifier("appsService")
protected AppsService appsService;
/**
* postHandle .
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,ModelAndView modelAndView) throws Exception {
_logger.debug("postHandle");
String appId = null;
if (WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID) != null) {
appId = WebContext.getAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID).toString();
}
if (appId == null) {
PreLoginAppAdapter.getAppIdFromRequestUrl(request);
}
//Applications app=applicationsService.get(appId);
final Apps app = (Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
String sessionId = (String)WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID);
final UserInfo userInfo = WebContext.getUserInfo();
_logger.debug("sessionId : " + sessionId + " ,appId : " + appId);
HistoryLoginApps historyLoginApps = new HistoryLoginApps();
historyLoginApps.setId(historyLoginApps.generateId());
historyLoginApps.setAppId(appId);
historyLoginApps.setSessionId(sessionId);
historyLoginApps.setAppName(app.getName());
historyLoginApps.setUid(userInfo.getId());
historyLoginApps.setUsername(userInfo.getUsername());
historyLoginApps.setDisplayName(userInfo.getDisplayName());
historyLoginAppsService.insert(historyLoginApps);
WebContext.removeAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
WebContext.removeAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID);
}
}

View File

@@ -2,7 +2,6 @@ package org.maxkey.web.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.dao.service.HistoryLogsService;
import org.maxkey.domain.HistoryLogs;
import org.maxkey.domain.UserInfo;
@@ -19,47 +18,53 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
* Contorller调用完成后进行日志操作
*
* 日志处理需在parasec-servlet.xml中配置
* mvc:interceptors log
* @author Crystal.Sea
*
*/
public class HistoryLogsAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);
@Autowired
@Qualifier("historyLogsService")
private HistoryLogsService historyLogsService;
// after the handler is executed
public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {
_logger.debug("postHandle");
Message message = WebContext.getMessage();//读取session中message
if(message != null){
if(message.getMessageScope() == MessageScope.DB || message.getMessageScope() == MessageScope.DB_CLIENT) {//判断message类型
UserInfo userInfo =WebContext.getUserInfo();//取得当前用户信息
//创建日志记录
HistoryLogs historyLogs = new HistoryLogs(
message.getServiceName(),
message.getCode(),
message.getMessage(),
JsonUtils.object2Json(message.getMessageObject()),
message.getMessageType().toString(),
message.getOperateType().toString(),
userInfo==null?null:userInfo.getId(),
userInfo==null?null:userInfo.getUsername(),
""
);
_logger.debug("insert db historyLogs content : "+historyLogs);
historyLogsService.insert(historyLogs);//日志插入数据库
if(message.getMessageScope() == MessageScope.DB) {//message类型仅插入数据库
WebContext.clearMessage();//清除message
}
}
}
}
private static final Logger _logger = LoggerFactory.getLogger(HistoryLogsAdapter.class);
@Autowired
@Qualifier("historyLogsService")
private HistoryLogsService historyLogsService;
/**
* after the handler is executed.
*/
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,ModelAndView modelAndView) throws Exception {
_logger.debug("postHandle");
Message message = WebContext.getMessage();//读取session中message
if (message != null) {
//判断message类型
if (message.getMessageScope() == MessageScope.DB
|| message.getMessageScope() == MessageScope.DB_CLIENT) {
UserInfo userInfo = WebContext.getUserInfo();//取得当前用户信息
//创建日志记录
HistoryLogs historyLogs = new HistoryLogs(
message.getServiceName(),
message.getCode(),
message.getMessage(),
JsonUtils.object2Json(message.getMessageObject()),
message.getMessageType().toString(),
message.getOperateType().toString(),
userInfo == null ? null : userInfo.getId(),
userInfo == null ? null : userInfo.getUsername(),
""
);
_logger.debug("insert db historyLogs content : " + historyLogs);
historyLogsService.insert(historyLogs);//日志插入数据库
//message类型仅插入数据库
if (message.getMessageScope() == MessageScope.DB) {
WebContext.clearMessage();//清除message
}
}
}
}
}

View File

@@ -1,11 +1,9 @@
package org.maxkey.web.interceptor;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.config.ApplicationConfig;
import org.maxkey.web.WebContext;
import org.slf4j.Logger;
@@ -13,56 +11,58 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
* 权限Interceptor处理
* 权限处理需在servlet.xml中配置
* mvc:interceptors permission
* 权限Interceptor处理 权限处理需在servlet.xml中配置 mvc:interceptors permission
*
* @author Crystal.Sea
*
*/
public class PermissionAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(PermissionAdapter.class);
//无需Interceptor url
@Autowired
@Qualifier("applicationConfig")
private ApplicationConfig applicationConfig;
static ConcurrentHashMap<String ,String >navigationsMap=null;
/*
* 请求前处理
* (non-Javadoc)
* @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
_logger.trace("PermissionAdapter preHandle");
//判断用户是否登录
if(WebContext.getAuthentication()==null||WebContext.getAuthentication().getAuthorities()==null){//判断用户和角色,判断用户是否登录用户
_logger.trace("No Authentication ... forward to /login");
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
dispatcher.forward(request, response);
return false;
}
boolean hasAccess=true;
/*
boolean preHandler = super.preHandle(request, response, handler);
if(preHandler) {
preHandler = false;
if(!preHandler){//无权限转向
log.debug("You do not have permission to access "+accessUrl);
RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
dispatcher.forward(request, response);
return false;
}
}*/
return hasAccess;
}
private static final Logger _logger = LoggerFactory.getLogger(PermissionAdapter.class);
// 无需Interceptor url
@Autowired
@Qualifier("applicationConfig")
private ApplicationConfig applicationConfig;
static ConcurrentHashMap<String, String> navigationsMap = null;
/*
* 请求前处理 (non-Javadoc)
*
* @see
* org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse, java.lang.Object)
*/
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {
_logger.trace("PermissionAdapter preHandle");
// 判断用户是否登录, 判断用户和角色,判断用户是否登录用户
if (WebContext.getAuthentication() == null
|| WebContext.getAuthentication().getAuthorities() == null) {
_logger.trace("No Authentication ... forward to /login");
RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
dispatcher.forward(request, response);
return false;
}
boolean hasAccess = true;
/*
* boolean preHandler = super.preHandle(request, response, handler);
*
* if(preHandler) { preHandler = false;
*
*
* if(!preHandler){//无权限转向
* log.debug("You do not have permission to access "+accessUrl);
* RequestDispatcher dispatcher = request.getRequestDispatcher("/accessdeny");
* dispatcher.forward(request, response); return false; } }
*/
return hasAccess;
}
}

View File

@@ -1,9 +1,7 @@
package org.maxkey.web.interceptor;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.domain.UserInfo;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
@@ -11,38 +9,43 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class PreLoginAppAdapter extends HandlerInterceptorAdapter {
private static final Logger _logger = LoggerFactory.getLogger(PreLoginAppAdapter.class);
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
_logger.debug("preHandle");
UserInfo userInfo=WebContext.getUserInfo();
String redirect_uri=request.getRequestURL().toString();
String appId=getAppIdFromRequestURI(request);
_logger.debug("preHandle app Id "+appId);
Object singlesignon_uri=WebContext.getAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
if(singlesignon_uri!=null&&singlesignon_uri.equals(redirect_uri)){
return true;
}
/*if(userInfo.getProtectedAppsMap().get(appId)!=null){
request.setAttribute("redirect_uri",redirect_uri);
_logger.debug(""+redirect_uri);
RequestDispatcher dispatcher = request.getRequestDispatcher("/authorize/protected/forward");
dispatcher.forward(request, response);
return false;
}*/
return true;
}
public static String getAppIdFromRequestURI(HttpServletRequest request){
String[] uri=request.getRequestURI().split("/");
String appId=uri[uri.length-1];
return appId;
}
private static final Logger _logger = LoggerFactory.getLogger(PreLoginAppAdapter.class);
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {
_logger.debug("preHandle");
UserInfo userInfo = WebContext.getUserInfo();
String redirect_uri = request.getRequestURL().toString();
String appId = getAppIdFromRequestUrl(request);
_logger.debug("preHandle app Id " + appId);
Object singlesignon_uri = WebContext.getAttribute(WebConstants.CURRENT_SINGLESIGNON_URI);
if (singlesignon_uri != null && singlesignon_uri.equals(redirect_uri)) {
return true;
}
/*
* if(userInfo.getProtectedAppsMap().get(appId)!=null){
*
* request.setAttribute("redirect_uri",redirect_uri);
* _logger.debug(""+redirect_uri); RequestDispatcher dispatcher =
* request.getRequestDispatcher("/authorize/protected/forward");
* dispatcher.forward(request, response); return false; }
*/
return true;
}
/**
* Request URL .
* @param request http
* @return .
*/
public static String getAppIdFromRequestUrl(HttpServletRequest request) {
String[] uri = request.getRequestURI().split("/");
String appId = uri[uri.length - 1];
return appId;
}
}