App credential to string type

This commit is contained in:
MaxKey 2022-11-04 21:13:31 +08:00
parent 9bf04827e0
commit 6bd2231a1c
7 changed files with 76 additions and 74 deletions

View File

@ -42,10 +42,10 @@ public class Apps extends JpaBaseEntity implements Serializable {
private static final long serialVersionUID = -6264641546959620712L; private static final long serialVersionUID = -6264641546959620712L;
public static final class CREDENTIALS { public static final class CREDENTIALS {
public static final int USER_DEFINED = 3; public static final String USER_DEFINED = "user_defined";
public static final int SHARED = 2; public static final String SHARED = "shared";
public static final int SYSTEM = 1; public static final String SYSTEM = "system";
public static final int NONE = 0; public static final String NONE = "none";
} }
public static final class VISIBLE { public static final class VISIBLE {
@ -100,7 +100,7 @@ public class Apps extends JpaBaseEntity implements Serializable {
* CREDENTIAL VALUES USER-DEFINED SYSTEM SHARED NONE * CREDENTIAL VALUES USER-DEFINED SYSTEM SHARED NONE
*/ */
@Column @Column
private int credential; private String credential;
@Column @Column
private String sharedUsername; private String sharedUsername;
@Column @Column
@ -116,6 +116,7 @@ public class Apps extends JpaBaseEntity implements Serializable {
@Column @Column
private String logoutUrl; private String logoutUrl;
@Column @Column
@JsonFormat(shape = JsonFormat.Shape.STRING)
private int logoutType; private int logoutType;
/* /*
* extendAttr * extendAttr
@ -173,7 +174,6 @@ public class Apps extends JpaBaseEntity implements Serializable {
public Apps() { public Apps() {
super(); super();
isSignature = ConstsBoolean.FALSE; isSignature = ConstsBoolean.FALSE;
credential = CREDENTIALS.NONE;
} }
@ -354,14 +354,14 @@ public class Apps extends JpaBaseEntity implements Serializable {
/** /**
* @return the credential * @return the credential
*/ */
public int getCredential() { public String getCredential() {
return credential; return credential;
} }
/** /**
* @param credential the credential to set * @param credential the credential to set
*/ */
public void setCredential(int credential) { public void setCredential(String credential) {
this.credential = credential; this.credential = credential;
} }

View File

@ -94,6 +94,7 @@ public class AppsOAuth20Details extends Apps {
this.setAppName(application.getAppName()); this.setAppName(application.getAppName());
this.setLoginUrl(application.getLoginUrl()); this.setLoginUrl(application.getLoginUrl());
this.setLogoutUrl(application.getLogoutUrl()); this.setLogoutUrl(application.getLogoutUrl());
this.setLogoutType(application.getLogoutType());
this.setCategory(application.getCategory()); this.setCategory(application.getCategory());
this.setProtocol(application.getProtocol()); this.setProtocol(application.getProtocol());
this.setIcon(application.getIcon()); this.setIcon(application.getIcon());
@ -103,6 +104,8 @@ public class AppsOAuth20Details extends Apps {
this.setVendor(application.getVendor()); this.setVendor(application.getVendor());
this.setVendorUrl(application.getVendorUrl()); this.setVendorUrl(application.getVendorUrl());
this.setVisible(application.getVisible()); this.setVisible(application.getVisible());
this.setIsAdapter(application.getIsAdapter());
this.setAdapter(application.getAdapter()); this.setAdapter(application.getAdapter());
this.setAdapterId(application.getAdapterId()); this.setAdapterId(application.getAdapterId());
this.setAdapterName(application.getAdapterName()); this.setAdapterName(application.getAdapterName());

View File

@ -76,24 +76,24 @@ public class AuthorizeBaseEndpoint {
account.setUsername(userInfo.getUsername()); account.setUsername(userInfo.getUsername());
account.setAppName(app.getAppName()); account.setAppName(app.getAppName());
if(loadApp.getCredential() == Apps.CREDENTIALS.USER_DEFINED){ if(loadApp.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.USER_DEFINED)){
account = accountsService.load(new Accounts(userInfo.getId(),loadApp.getId())); account = accountsService.load(new Accounts(userInfo.getId(),loadApp.getId()));
if(account != null){ if(account != null){
account.setRelatedPassword( account.setRelatedPassword(
PasswordReciprocal.getInstance().decoder(account.getRelatedPassword())); PasswordReciprocal.getInstance().decoder(account.getRelatedPassword()));
} }
}else if(loadApp.getCredential() == Apps.CREDENTIALS.SHARED){ }else if(loadApp.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.SHARED)){
account.setRelatedUsername(loadApp.getSharedUsername()); account.setRelatedUsername(loadApp.getSharedUsername());
account.setRelatedPassword(PasswordReciprocal.getInstance().decoder(loadApp.getSharedPassword())); account.setRelatedPassword(PasswordReciprocal.getInstance().decoder(loadApp.getSharedPassword()));
}else if(loadApp.getCredential() == Apps.CREDENTIALS.SYSTEM){ }else if(loadApp.getCredential().equalsIgnoreCase( Apps.CREDENTIALS.SYSTEM)){
account.setUsername( account.setUsername(
AbstractAuthorizeAdapter.getValueByUserAttr(userInfo, loadApp.getSystemUserAttr()) AbstractAuthorizeAdapter.getValueByUserAttr(userInfo, loadApp.getSystemUserAttr())
); );
//decoder database stored encode password //decoder database stored encode password
account.setRelatedPassword( account.setRelatedPassword(
PasswordReciprocal.getInstance().decoder(userInfo.getDecipherable())); PasswordReciprocal.getInstance().decoder(userInfo.getDecipherable()));
}else if(loadApp.getCredential()==Apps.CREDENTIALS.NONE){ }else if(loadApp.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.NONE)){
account.setUsername(userInfo.getUsername()); account.setUsername(userInfo.getUsername());
account.setRelatedPassword(userInfo.getUsername()); account.setRelatedPassword(userInfo.getUsername());

View File

@ -67,7 +67,7 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
_logger.debug("Adapter {}",apps.getAdapter()); _logger.debug("Adapter {}",apps.getAdapter());
AbstractAuthorizeAdapter adapter = (AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter()); AbstractAuthorizeAdapter adapter = (AbstractAuthorizeAdapter)Instance.newInstance(apps.getAdapter());
Accounts account = getAccounts(apps,currentUser); Accounts account = getAccounts(apps,currentUser);
if(apps.getCredential()==Apps.CREDENTIALS.USER_DEFINED && account == null) { if(apps.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.USER_DEFINED) && account == null) {
return initCredentialView(id,"/authorize/api/"+id); return initCredentialView(id,"/authorize/api/"+id);
} }

View File

@ -19,65 +19,64 @@ import format from 'date-fns/format';
import { BaseEntity } from './BaseEntity'; import { BaseEntity } from './BaseEntity';
export class Apps extends BaseEntity { export class Apps extends BaseEntity {
appName!: String; appName!: String;
loginUrl!: String; loginUrl!: String;
category!: String; category!: String;
protocol!: String; protocol!: String;
secret!: String; secret!: String;
iconBase64!: String; iconBase64!: String;
visible!: String; visible!: String;
inducer!: String; inducer!: String;
vendor!: String; vendor!: String;
vendorUrl!: String; vendorUrl!: String;
credential!: String; credential!: String;
sharedUsername!: String; sharedUsername!: String;
sharedPassword!: String; sharedPassword!: String;
systemUserAttr!: String; systemUserAttr!: String;
principal!: String; principal!: String;
credentials!: String; credentials!: String;
logoutUrl!: String; logoutUrl!: String;
logoutType!: String; logoutType!: String;
isExtendAttr!: String; isExtendAttr!: String;
extendAttr!: String; extendAttr!: String;
userPropertys!: String; resourceMgt!: String;
isSignature!: String; userPropertys!: String;
isAdapter!: String; isSignature!: String;
adapterId!: String; isAdapter!: String;
adapterName!: String; adapterId!: String;
adapter!: String; adapterName!: String;
iconId!: String; adapter!: String;
frequently!: String; iconId!: String;
frequently!: String;
select_userPropertys!: String[]; select_userPropertys!: String[];
constructor() { constructor() {
super(); super();
this.category = 'none'; this.category = 'none';
this.visible = '0'; this.frequently = 'no';
this.isAdapter = '0'; this.resourceMgt = 'false';
this.logoutType = '0'; this.visible = '0';
this.frequently = 'no'; this.isAdapter = '0';
this.logoutType = '0';
this.isExtendAttr = '0';
}
override init(data: any): void {
Object.assign(this, data);
if (this.status == 1) {
this.switch_status = true;
} else {
this.switch_status = false;
} }
}
override init(data: any): void { override trans(): void {
Object.assign(this, data); if (this.switch_status) {
if (this.status == 1) { this.status = 1;
this.switch_status = true; } else {
} else { this.status = 0;
this.switch_status = false;
}
this.isAdapter = `${data.isAdapter}`;
this.isExtendAttr = `${data.isExtendAttr}`;
this.logoutType = `${data.logoutType}`;
this.visible = `${data.visible}`;
}
override trans(): void {
if (this.switch_status) {
this.status = 1;
} else {
this.status = 0;
}
} }
}
} }

View File

@ -86,12 +86,12 @@ public class AppListController {
@RequestMapping(value = { "/account/get" }) @RequestMapping(value = { "/account/get" })
@ResponseBody @ResponseBody
public ResponseEntity<?> getAccount( public ResponseEntity<?> getAccount(
@RequestParam("credential") int credential, @RequestParam("credential") String credential,
@RequestParam("appId") String appId, @RequestParam("appId") String appId,
@CurrentUser UserInfo currentUser) { @CurrentUser UserInfo currentUser) {
Accounts account = null ; Accounts account = null ;
if (credential == Apps.CREDENTIALS.USER_DEFINED) { if (credential.equalsIgnoreCase(Apps.CREDENTIALS.USER_DEFINED)) {
account = accountsService.load(new Accounts(currentUser.getId(), appId)); account = accountsService.load(new Accounts(currentUser.getId(), appId));
account.setRelatedPassword( account.setRelatedPassword(
PasswordReciprocal.getInstance().decoder( PasswordReciprocal.getInstance().decoder(
@ -110,11 +110,11 @@ public class AppListController {
@RequestMapping(value = { "/account/update" }) @RequestMapping(value = { "/account/update" })
@ResponseBody @ResponseBody
public ResponseEntity<?> updateAccount( public ResponseEntity<?> updateAccount(
@RequestParam("credential") int credential, @RequestParam("credential") String credential,
@ModelAttribute Accounts account, @ModelAttribute Accounts account,
@CurrentUser UserInfo currentUser) { @CurrentUser UserInfo currentUser) {
Accounts appUsers = new Accounts(); Accounts appUsers = new Accounts();
if (credential == Apps.CREDENTIALS.USER_DEFINED) { if (credential.equalsIgnoreCase(Apps.CREDENTIALS.USER_DEFINED)) {
appUsers = accountsService.load(new Accounts(currentUser.getId(), account.getAppId())); appUsers = accountsService.load(new Accounts(currentUser.getId(), account.getAppId()));
if (appUsers == null) { if (appUsers == null) {
appUsers = new Accounts(); appUsers = new Accounts();

View File

@ -72,7 +72,7 @@ public class BaseAppContorller {
} }
protected void encodeSharedPassword(Apps application){ protected void encodeSharedPassword(Apps application){
if(application.getCredential()!=Apps.CREDENTIALS.SHARED){ if(!application.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.SHARED)){
if(application.getProtocol().equals(ConstsProtocols.FORMBASED)){ if(application.getProtocol().equals(ConstsProtocols.FORMBASED)){
if(StringUtils.isNotBlank(application.getSharedPassword())){ if(StringUtils.isNotBlank(application.getSharedPassword())){
application.setSharedPassword( application.setSharedPassword(
@ -83,7 +83,7 @@ public class BaseAppContorller {
} }
protected void decoderSharedPassword(Apps application){ protected void decoderSharedPassword(Apps application){
if(application.getCredential()!=Apps.CREDENTIALS.SHARED){ if(application.getCredential().equalsIgnoreCase(Apps.CREDENTIALS.SHARED)){
if(application.getProtocol().equals(ConstsProtocols.FORMBASED)){ if(application.getProtocol().equals(ConstsProtocols.FORMBASED)){
if(StringUtils.isNotBlank(application.getSharedPassword())){ if(StringUtils.isNotBlank(application.getSharedPassword())){
application.setSharedPassword( application.setSharedPassword(