권한 부여에 사용되는 보안 인증 정보를 가져오는 프로세스는 이 구성 요소에서 지정하지 않습니다. 필요에 따라 교환에서 인증 정보를 가져오는 자체 프로세서 또는 구성 요소를 작성할 수 있습니다. 예를 들어 HTTP 요청 헤더에서 인증 정보를 가져오는 프로세서를 만들 수 있습니다. 자격 증명을 수집하는 방법에 관계없이 In 메시지 또는 SecurityContextHolder 에 배치하여 Camel Spring Security 구성 요소가 액세스할 수 있도록 해야 합니다.
import javax.security.auth.Subject;
import org.apache.camel.*;
import org.apache.commons.codec.binary.Base64;
import org.springframework.security.authentication.*;
public class MyAuthService implements Processor {
public void process(Exchange exchange) throws Exception {
// get the username and password from the HTTP header
// http://en.wikipedia.org/wiki/Basic_access_authentication
String userpass = new String(Base64.decodeBase64(exchange.getIn().getHeader("Authorization", String.class)));
String[] tokens = userpass.split(":");
// create an Authentication object
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0], tokens[1]);
// wrap it in a Subject
Subject subject = new Subject();
subject.getPrincipals().add(authToken);
// place the Subject in the In message
exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject);
// you could also do this if useThreadSecurityContext is set to true
// SecurityContextHolder.getContext().setAuthentication(authToken);
}
}
import javax.security.auth.Subject;
import org.apache.camel.*;
import org.apache.commons.codec.binary.Base64;
import org.springframework.security.authentication.*;
public class MyAuthService implements Processor {
public void process(Exchange exchange) throws Exception {
// get the username and password from the HTTP header
// http://en.wikipedia.org/wiki/Basic_access_authentication
String userpass = new String(Base64.decodeBase64(exchange.getIn().getHeader("Authorization", String.class)));
String[] tokens = userpass.split(":");
// create an Authentication object
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(tokens[0], tokens[1]);
// wrap it in a Subject
Subject subject = new Subject();
subject.getPrincipals().add(authToken);
// place the Subject in the In message
exchange.getIn().setHeader(Exchange.AUTHENTICATION, subject);
// you could also do this if useThreadSecurityContext is set to true
// SecurityContextHolder.getContext().setAuthentication(authToken);
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
SpringSecurityAuthorizationPolicy 는 필요한 경우 Authentication 오브젝트를 자동으로 인증합니다.
Exchange.AUTHENTICATION 헤더 대신 SecurityContextHolder 를 사용할 때 알아야 할 두 가지 문제가 있습니다. 먼저 컨텍스트 소유자는 스레드 로컬 변수를 사용하여 Authentication 개체를 유지합니다. seda 또는 jms 와 같이 스레드 경계를 통과하는 모든 경로는 Authentication 개체를 손실됩니다. 두 번째, Spring Security 시스템은 컨텍스트의 Authentication 개체가 이미 인증되고 역할이 있을 것으로 예상되는 것으로 보입니다(자세한 내용은 기술 개요 섹션 5.3.1 참조).
camel-spring-security 의 기본 동작은 Exchange.AUTHENTICATION 헤더에서 주체 를 찾는 것입니다. 이 주체에는 org.springframework.security.core.Authentication 의 하위 클래스여야 하는 주체 가 하나 이상 포함되어야 합니다. org.apache.camel.component.spring.security. Authentication Adapter 의 구현을 < authorizationPolicy >에 제공하여 Authentication 오브젝트에 대한 주체 매핑을 사용자 지정할 수 있습니다. 이 기능은 Spring Security를 사용하지 않지만 주체 를 제공하는 구성 요소로 작업하는 경우에 유용할 수 있습니다. 현재 CXF 구성 요소만 Exchange.AUTHENTICATION 헤더를 채웁니다.