org.iplass.mtp.tools.batch.cleaner.AuthProviderCleaner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iplass-tools-batch Show documentation
Show all versions of iplass-tools-batch Show documentation
Java-based open source low-code development platform for enterprise
The newest version!
/*
* Copyright 2014 DENTSU SOKEN INC. All Rights Reserved.
*/
package org.iplass.mtp.tools.batch.cleaner;
import java.util.List;
import org.iplass.mtp.impl.auth.AuthService;
import org.iplass.mtp.impl.auth.authenticate.AuthenticationProvider;
import org.iplass.mtp.impl.core.ExecuteContext;
import org.iplass.mtp.impl.core.TenantContextService;
import org.iplass.mtp.impl.tools.tenant.TenantInfo;
import org.iplass.mtp.spi.ServiceRegistry;
import org.iplass.mtp.tools.batch.MtpBatchResourceDisposer;
import org.iplass.mtp.tools.batch.MtpSilentBatch;
import org.iplass.mtp.transaction.Transaction;
import org.iplass.mtp.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 認証モジュールが保持するデータのメンテナンス用バッチ
*/
public class AuthProviderCleaner extends MtpSilentBatch {
private static Logger logger = LoggerFactory.getLogger(AuthProviderCleaner.class);
private static TenantContextService tenantContextService = ServiceRegistry.getRegistry().getService(TenantContextService.class);
private static AuthService authService = ServiceRegistry.getRegistry().getService(AuthService.class);
private int tenantId;
/**
* 引数について
*
* - テナントID:対象テナントID(-1の場合、全テナントが対象になります)
*
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int tenantId = -1;
if (args != null && args.length > 0 && StringUtil.isNotEmpty(args[0])) {
tenantId = Integer.parseInt(args[0]);
}
try {
if (tenantId >= 0) {
(new AuthProviderCleaner(tenantId)).clean();
} else {
//全テナントを対象
List tenants = getValidTenantInfoList();
if (tenants != null) {
for (TenantInfo t: tenants) {
(new AuthProviderCleaner(t.getId())).clean();
}
}
}
} finally {
// リソース破棄
MtpBatchResourceDisposer.disposeResource();
}
}
/**
* 対象のテナントIDを指定します。
*
* @param tenantId 対象のテナントID
*/
public AuthProviderCleaner(int tenantId) {
setTenantId(tenantId);
}
/**
*
* @return boolean 成功:true 失敗:false
* @throws Exception
*/
public boolean clean() throws Exception {
setSuccess(false);
clearLog();
return executeTask(null, (param) -> {
return ExecuteContext.executeAs(tenantContextService.getTenantContext(tenantId), () -> {
logArguments();
AuthenticationProvider[] aps = authService.getAuthenticationProviders();
if (aps != null) {
for (AuthenticationProvider ap: aps) {
final AuthenticationProvider apFinal = ap;
Transaction.required(t -> {
apFinal.cleanupData();
return null;
});
}
}
setSuccess(true);
return isSuccess();
});
});
}
/**
* パラメータ値ログ出力
*
*/
private void logArguments() {
logInfo("■Execute Argument");
logInfo("\ttenant id :" + getTenantId());
logInfo("");
}
/**
* tenantIdを取得します。
* @return tenantId
*/
public int getTenantId() {
return tenantId;
}
/**
* tenantIdを設定します。
* @param tenantId tenantId
*/
public void setTenantId(int tenantId) {
this.tenantId = tenantId;
}
@Override
protected Logger loggingLogger() {
return logger;
}
}