Cache 30 MINUTES
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package org.maxkey.authz.endpoint;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.crypto.ReciprocalUtils;
|
||||
import org.maxkey.entity.Accounts;
|
||||
@@ -42,9 +43,6 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
public class AuthorizeBaseEndpoint {
|
||||
final static Logger _logger = LoggerFactory.getLogger(AuthorizeBaseEndpoint.class);
|
||||
|
||||
//maxkey-mgt
|
||||
public final static String MGT_APP_ID = "622076759805923328";
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
@@ -60,9 +58,8 @@ public class AuthorizeBaseEndpoint {
|
||||
protected Apps getApp(String id){
|
||||
Apps app=(Apps)WebContext.getAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP);
|
||||
//session中为空或者id不一致重新加载
|
||||
if(app==null||!app.getId().equalsIgnoreCase(id)) {
|
||||
id = id.equalsIgnoreCase("maxkey_mgt") ? MGT_APP_ID : id;
|
||||
app=appsService.get(id);
|
||||
if(StringUtils.isBlank(id) || !app.getId().equalsIgnoreCase(id)) {
|
||||
app=appsService.loadById(id);
|
||||
WebContext.setAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP, app);
|
||||
}
|
||||
if(app == null){
|
||||
@@ -75,36 +72,35 @@ public class AuthorizeBaseEndpoint {
|
||||
protected Accounts getAccounts(Apps app){
|
||||
Accounts account=new Accounts();
|
||||
UserInfo userInfo=WebContext.getUserInfo();
|
||||
Apps application= getApp(app.getId());
|
||||
if(application.getCredential()==Apps.CREDENTIALS.USER_DEFINED){
|
||||
Apps loadApp = getApp(app.getId());
|
||||
if(loadApp.getCredential()==Apps.CREDENTIALS.USER_DEFINED){
|
||||
|
||||
account=accountsService.load(new Accounts(userInfo.getId(),application.getId()));
|
||||
account=accountsService.load(new Accounts(userInfo.getId(),loadApp.getId()));
|
||||
if(account!=null){
|
||||
account.setRelatedPassword(ReciprocalUtils.decoder(account.getRelatedPassword()));
|
||||
}
|
||||
}else if(application.getCredential()==Apps.CREDENTIALS.SHARED){
|
||||
}else if(loadApp.getCredential()==Apps.CREDENTIALS.SHARED){
|
||||
|
||||
account.setRelatedUsername(application.getSharedUsername());
|
||||
account.setRelatedPassword(ReciprocalUtils.decoder(application.getSharedPassword()));
|
||||
account.setRelatedUsername(loadApp.getSharedUsername());
|
||||
account.setRelatedPassword(ReciprocalUtils.decoder(loadApp.getSharedPassword()));
|
||||
|
||||
}else if(application.getCredential()==Apps.CREDENTIALS.SYSTEM){
|
||||
}else if(loadApp.getCredential()==Apps.CREDENTIALS.SYSTEM){
|
||||
|
||||
if(application.getSystemUserAttr().equalsIgnoreCase("userId")){
|
||||
if(loadApp.getSystemUserAttr().equalsIgnoreCase("userId")){
|
||||
account.setUsername(userInfo.getId());
|
||||
}else if(application.getSystemUserAttr().equalsIgnoreCase("username")){
|
||||
}else if(loadApp.getSystemUserAttr().equalsIgnoreCase("username")){
|
||||
account.setUsername(userInfo.getUsername());
|
||||
}else if(application.getSystemUserAttr().equalsIgnoreCase("employeeNumber")){
|
||||
}else if(loadApp.getSystemUserAttr().equalsIgnoreCase("employeeNumber")){
|
||||
account.setUsername(userInfo.getEmployeeNumber());
|
||||
}else if(application.getSystemUserAttr().equalsIgnoreCase("email")){
|
||||
}else if(loadApp.getSystemUserAttr().equalsIgnoreCase("email")){
|
||||
account.setUsername(userInfo.getEmail());
|
||||
}else if(application.getSystemUserAttr().equalsIgnoreCase("windowsAccount")){
|
||||
}else if(loadApp.getSystemUserAttr().equalsIgnoreCase("windowsAccount")){
|
||||
account.setUsername(userInfo.getWindowsAccount());
|
||||
}
|
||||
//decoder database stored encode password
|
||||
account.setRelatedPassword(ReciprocalUtils.decoder(WebContext.getUserInfo().getDecipherable()));
|
||||
|
||||
|
||||
}else if(application.getCredential()==Apps.CREDENTIALS.NONE){
|
||||
}else if(loadApp.getCredential()==Apps.CREDENTIALS.NONE){
|
||||
|
||||
account.setUsername(userInfo.getUsername());
|
||||
account.setRelatedPassword(userInfo.getUsername());
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.maxkey.entity.apps.Apps;
|
||||
import org.maxkey.persistence.service.AppsCasDetailsService;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -44,6 +46,8 @@ import io.swagger.annotations.ApiOperation;
|
||||
@Api(tags = "1-2认证总地址文档模块")
|
||||
@Controller
|
||||
public class AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
final static Logger _logger = LoggerFactory.getLogger(AuthorizeEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
AppsCasDetailsService casDetailsService;
|
||||
|
||||
@@ -54,30 +58,29 @@ public class AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
HttpServletRequest request,
|
||||
@PathVariable("id") String id){
|
||||
ModelAndView modelAndView=null;
|
||||
Apps application=getApp(id);
|
||||
id = application.getId();
|
||||
WebContext.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, application.getId());
|
||||
Apps app=getApp(id);
|
||||
WebContext.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, app.getId());
|
||||
|
||||
if(application.getProtocol().equalsIgnoreCase(ConstantsProtocols.EXTEND_API)){
|
||||
modelAndView=WebContext.forward("/authz/api/"+id);
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.FORMBASED)){
|
||||
modelAndView=WebContext.forward("/authz/formbased/"+id);
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.OAUTH20)){
|
||||
modelAndView=WebContext.forward("/authz/oauth/v20/"+application.getId());
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.OAUTH21)){
|
||||
modelAndView=WebContext.redirect(application.getLoginUrl());
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.OPEN_ID_CONNECT10)){
|
||||
modelAndView=WebContext.forward("/authz/oauth/v20/"+application.getId());
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.SAML20)){
|
||||
modelAndView=WebContext.forward("/authz/saml20/idpinit/"+application.getId());
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.TOKENBASED)){
|
||||
modelAndView=WebContext.forward("/authz/tokenbased/"+id);
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.CAS)){
|
||||
modelAndView=WebContext.forward("/authz/cas/"+id);
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.JWT)){
|
||||
modelAndView=WebContext.forward("/authz/jwt/"+id);
|
||||
}else if (application.getProtocol().equalsIgnoreCase(ConstantsProtocols.BASIC)){
|
||||
modelAndView=WebContext.redirect(application.getLoginUrl());
|
||||
if(app.getProtocol().equalsIgnoreCase(ConstantsProtocols.EXTEND_API)){
|
||||
modelAndView=WebContext.forward("/authz/api/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.FORMBASED)){
|
||||
modelAndView=WebContext.forward("/authz/formbased/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.OAUTH20)){
|
||||
modelAndView=WebContext.forward("/authz/oauth/v20/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.OAUTH21)){
|
||||
modelAndView=WebContext.redirect(app.getLoginUrl());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.OPEN_ID_CONNECT10)){
|
||||
modelAndView=WebContext.forward("/authz/oauth/v20/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.SAML20)){
|
||||
modelAndView=WebContext.forward("/authz/saml20/idpinit/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.TOKENBASED)){
|
||||
modelAndView=WebContext.forward("/authz/tokenbased/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.CAS)){
|
||||
modelAndView=WebContext.forward("/authz/cas/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.JWT)){
|
||||
modelAndView=WebContext.forward("/authz/jwt/"+app.getId());
|
||||
}else if (app.getProtocol().equalsIgnoreCase(ConstantsProtocols.BASIC)){
|
||||
modelAndView=WebContext.redirect(app.getLoginUrl());
|
||||
}
|
||||
|
||||
_logger.debug(modelAndView.getViewName());
|
||||
|
||||
Reference in New Issue
Block a user