All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flyfish.oauth.entry.auditing.RestClientAuditingEntryPoint Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.flyfish.oauth.entry.auditing;

import com.fasterxml.jackson.core.type.TypeReference;
import com.flyfish.oauth.client.RestClient;
import com.flyfish.oauth.configuration.OAuth2SsoProperties;
import com.flyfish.oauth.domain.OAuthSSOToken;
import com.flyfish.oauth.domain.auditing.AuditingRecord;
import com.flyfish.oauth.domain.auditing.AuditingStrategy;
import com.flyfish.oauth.entry.AbstractAuthenticationEntryPoint;
import com.flyfish.oauth.entry.AuditingEntryPoint;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.IOException;
import java.util.List;

/**
 * 基于rest client的审计接入点
 *
 * @author wangyu
 */
@Getter
@AllArgsConstructor
public class RestClientAuditingEntryPoint implements AuditingEntryPoint {

    private final OAuth2SsoProperties properties;

    /**
     * 获取本系统配置的审计策略,初始化拉取一次,后续获得通知会更新
     *
     * @return 结果
     */
    @Override
    public List getStrategies() {
        return RestClient.create()
                .get()
                .url(properties.getAuditingFetchUri())
                .addParam("client", properties.getClientId())
                .withCredentials()
                .build()
                .execute(new TypeReference>() {
                });
    }

    /**
     * 提交审计记录
     *
     * @param record 审计记录
     */
    @Override
    public void apply(AuditingRecord record) throws IOException {
        RestClient.create()
                .post()
                .url(properties.getAuditingUri())
                .addHeader(AbstractAuthenticationEntryPoint.AUTH_HEADER,
                        OAuthSSOToken.BEARER_TYPE + " " + record.getAccessToken())
                .addHeader("Type", "OPERATION")
                .body(record)
                .build()
                .execute();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy