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

cn.wic4j.security.resource.handler.ResourceServerAuthenticationEntryPoint Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package cn.wic4j.security.resource.handler;

import cn.wi4j.security.core.utils.ResponseUtils;
import cn.wic4j.common.code.CommonCode;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import java.io.IOException;

/**
 * 未登录处理
* * @author Max * @version 2023.0.0.0 * @since 2023/7/11 21:03 */ @Slf4j @ConditionalOnMissingBean(name = "resourceServerAuthenticationEntryPoint") public class ResourceServerAuthenticationEntryPoint implements AuthenticationEntryPoint { /** * Commences an authentication scheme. *

* ExceptionTranslationFilter will populate the HttpSession * attribute named * AbstractAuthenticationProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY * with the requested target URL before calling this method. *

* Implementations should modify the headers on the ServletResponse as * necessary to commence the authentication process. * * @param request that resulted in an AuthenticationException * @param response so that the user agent can begin authentication * @param authException that caused the invocation */ @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { log.error("未登录请求接口:{}", request.getRequestURI()); ResponseUtils.responseUtf8(response, CommonCode.UNAUTHORIZED); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy