Search in sources :

Example 1 with UserInfo

use of com.ctrip.xpipe.api.sso.UserInfo in project x-pipe by ctripcorp.

the class CtripUserInfoHolder method getUser.

@Override
public UserInfo getUser() {
    try {
        Assertion assertion = AssertionHolder.getAssertion();
        if (assertion != null) {
            AttributePrincipal principal = assertion.getPrincipal();
            String userId = principal.getName();
            UserInfo userInfo = new CtripUserInfo();
            userInfo.setUserId(userId);
            return userInfo;
        }
    } catch (Exception e) {
        throw new RuntimeException("get user info from assertion holder error", e);
    }
    return CtripUserInfo.noBody();
}
Also used : Assertion(com.ctrip.infosec.sso.client.principal.Assertion) UserInfo(com.ctrip.xpipe.api.sso.UserInfo) AttributePrincipal(com.ctrip.infosec.sso.client.principal.AttributePrincipal)

Example 2 with UserInfo

use of com.ctrip.xpipe.api.sso.UserInfo in project x-pipe by ctripcorp.

the class ConfigController method changeConfig.

private RetMessage changeConfig(final String key, final String val, final String uri) {
    UserInfo user = UserInfoHolder.DEFAULT.getUser();
    String userId = user.getUserId();
    ConfigModel configModel = new ConfigModel();
    configModel.setUpdateUser(userId);
    configModel.setUpdateIP(uri);
    logger.info("[changeConfig] Config changed by user: {} and ip: {}", userId, uri);
    try {
        boolean target = Boolean.parseBoolean(val);
        if (DefaultConsoleDbConfig.KEY_ALERT_SYSTEM_ON.equalsIgnoreCase(key)) {
            if (target) {
                configService.startAlertSystem(configModel);
            } else {
                configService.stopAlertSystem(configModel, consoleConfig.getConfigDefaultRestoreHours());
            }
        } else if (DefaultConsoleDbConfig.KEY_SENTINEL_AUTO_PROCESS.equalsIgnoreCase(key)) {
            if (target) {
                configService.startSentinelAutoProcess(configModel);
            } else {
                configService.stopSentinelAutoProcess(configModel, consoleConfig.getConfigDefaultRestoreHours());
            }
        } else {
            return RetMessage.createFailMessage("Unknown config key: " + key);
        }
        return RetMessage.createSuccessMessage();
    } catch (Exception e) {
        logger.error("[getExecuteFunction] Exception: {}", e);
        return RetMessage.createFailMessage(e.getMessage());
    }
}
Also used : ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) UserInfo(com.ctrip.xpipe.api.sso.UserInfo)

Aggregations

UserInfo (com.ctrip.xpipe.api.sso.UserInfo)2 Assertion (com.ctrip.infosec.sso.client.principal.Assertion)1 AttributePrincipal (com.ctrip.infosec.sso.client.principal.AttributePrincipal)1 ConfigModel (com.ctrip.xpipe.redis.console.model.ConfigModel)1