Welcome. Ask away! Unless otherwise specified we assume you're using the latest 5.x version of Spring Security
can someone help me pls with this:
@miha-
Hello, can some one help me understand this:
i need to sign en encrypt soap request
https://docs.spring.io/spring-ws/site/reference/html/security.html
The XwsSecurityInterceptor will fire a SignatureKeyCallback to the registered handlers. Within Spring-WS, there are is one class which handles this particular callback: the KeyStoreCallbackHandler.
The XwsSecurityInterceptor will fire a EncryptionKeyCallback to the registered handlers in order to retrieve the encryption information. Within Spring-WS, there is one class which handled this particular callback: the KeyStoreCallbackHandler.
so for this only in policy has to be added, other things are the same
@Bean
public KeyStoreCallbackHandler callback() throws Exception{
KeyStoreCallbackHandler callbackHandler = new KeyStoreCallbackHandler();
callbackHandler.setPrivateKeyPassword("t_passwordo");
callbackHandler.setDefaultAlias("snet");
callbackHandler.setKeyStore(keyStoreFactoryBean());
callbackHandler.setTrustStore(TrustFactoryBean());
return callbackHandler;
}
signeture works ok
but for encrypt i get
2019-10-16 09:41:01.902 ERROR 21412 --- [nio-8080-exec-2] j.e.resource.xml.webservices.security : WSS0221: Unable to locate matching certificate for Key Encryption using Callback Handler.
2019-10-16 09:41:01.906 ERROR 21412 --- [nio-8080-exec-2] com.sun.xml.wss.logging.impl.filter : WSS1413: Error extracting certificate
tnx
BindAuthenticator
to authenticate users against LDAP. When the user provides the correct password, it gets correctly authenticated; the problem is when the user provides a wrong password: the authentication takes a very long time and then it fails with a timeout exception.
Hi, I have the following code, it's a MDCFilter.
import org.slf4j.MDC;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
public class NettyMDCFilter implements WebFilter {
public static final String USER_AND_APPLICATION_KEY = "user";
public static final String APPLICATION_KEY = "application";
public static final String USERNAME_KEY = "username";
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return exchange.<OAuth2Authentication>getPrincipal()
.doOnNext(this::logWithContext)
.map(auth -> exchange)
.switchIfEmpty(Mono.just(exchange))
.flatMap(chain::filter)
.doFinally(signalType -> removeMDCKeys());
}
private void logWithContext(OAuth2Authentication authentication) {
MDC.put(USER_AND_APPLICATION_KEY, userKey(authentication));
if (authentication.isClientOnly()) {
MDC.put(APPLICATION_KEY, authentication.getName());
} else {
MDC.put(APPLICATION_KEY, authentication.getOAuth2Request().getClientId());
MDC.put(USERNAME_KEY, authentication.getName());
}
}
private void removeMDCKeys() {
MDC.remove(USER_AND_APPLICATION_KEY);
MDC.remove(USERNAME_KEY);
MDC.remove(APPLICATION_KEY);
}
private String userKey(OAuth2Authentication authentication) {
if (authentication.isClientOnly()) {
return authentication.getName();
} else {
return String.format("%s:%s", authentication.getOAuth2Request().getClientId(), authentication.getName());
}
}
}
In the previous implementation was implemented using the class OAuth2Authentication, that belongs to the project the project spring-security-oauth, but this project now is under maintance mode , as you can see here . In my code, I want to check in the filter if the token belongs to a client application or to an user, but I don't have any idea about how could I do this in the new version of spring-security , even reading the documentation it's not clear for me what I should do, because there isn't a migration tutorial to migrate from spring-security-oauth2 project to the spring security project new version with built-in support to oauth2. I googled, but couldn't find a concrete tutorial to help me with this problem.
HI
my error:
WSS1205: Unable to initialize XML Cipher
java.security.NoSuchAlgorithmException: Null or empty transformation
i guess it is something with my policy, if someone can help me what i am missing
<xwss:Sign includeTimestamp="true">
<xwss:X509Token certificateAlias="softnet"></xwss:X509Token>
<xwss:SignatureTarget type="xpath"
value="/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsu:Timestamp">
<xwss:DigestMethod algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<xwss:Transform algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<xwss:AlgorithmParameter name="CanonicalizationMethod"
value="http://www.w3.org/2001/10/xml-exc-c14n#" />
</xwss:Transform>
</xwss:SignatureTarget>
</xwss:Sign>
<xwss:Encrypt>
<xwss:SymmetricKey keyAlias="syn" />
<xwss:DataEncryptionMethod
algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<xwss:EncryptionTarget type="XPATH" value="//env:Body">
<xwss:Transform algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5">
<xwss:AlgorithmParameter name="CanonicalizationMethod" value="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</xwss:Transform>
</xwss:EncryptionTarget>
</xwss:Encrypt>
public class MyFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
OAuth2Authentication authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
String id = Oauth2AuthenticationUtils.getId(httpRequest, authentication;
MyContextHolder.setId(id);
filterChain.doFilter(servletRequest, servletResponse);
MyContextHolder.clearContext();
}
@Override
public void destroy() {}
}
And the example of the implementation using ThreadLocal:public class MyContextHolder {
private static final ThreadLocal<String> MY_THREAD_LOCAL = new InheritableThreadLocal<>();
public static String getId() {
return MY_THREAD_LOCAL.get();
}
protected static void setId(String ID) {
MY_THREAD_LOCAL.set(organizationId);
}
public static void clearContext() {
MY_THREAD_LOCAL.remove();
}
}
http
.addFilterBefore(new AuthZFilter(), SecurityContextHolderAwareRequestFilter.class)
.authorizeRequests()
.antMatchers(<MATCHERS>).access(<RULES>)
.anyRequest().permitAll();
// Ignore sessions.
http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// Set error 403/401 response payloads to Custom ?? Not working with addFilterBefore ???
http
.csrf().disable().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).accessDeniedHandler(accessDeniedHandler);
AuthorizationEndpoint
.
org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices
protected String[] decodeCookie(String cookieValue) throws InvalidCookieException {
for (int j = 0; j < cookieValue.length() % 4; j++) {
cookieValue = cookieValue + "=";
}
//here
try {
Base64.getDecoder().decode(cookieValue.getBytes());
}
catch (IllegalArgumentException e) {
throw new InvalidCookieException(
"Cookie token was not Base64 encoded; value was '" + cookieValue
+ "'");
}
//here
String cookieAsPlainText = new String(Base64.getDecoder().decode(cookieValue.getBytes()));
AuthorizedClientServiceOAuth2AuthorizedClientManager
is what I'm looking for
Will copy question from spring-boot room here
Hello, after updating spring boot 2.1.4
to 2.2.0
I encountered a problem on starting application Caused by: java.lang.IllegalStateException: Can't configure antMatchers after anyRequest
nothing changed in code except spring boot version and configuration file where that IllegalStateException
pointing on looks like that
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/something/**")
.csrf().disable()
.authorizeRequests().anyRequest().hasRole(ROLE)
.antMatchers(PUT, "/api/**").hasRole(ROLE)
.and().httpBasic();
}
As I understand spring-security was updated to version 5.2
in boot 2.2.0
, maybe I missed something there ?
Also maybe that related to that this project have several security configuration files with @Order
annotation ?
Is it expected that @EnableGlobalMethodSecurity
cannot be used at the same time as @EnableReactiveMethodSecurity
within the same application? They both declare a bean named methodSecurityInterceptor
, so spring boot startup fails with:
The bean 'methodSecurityInterceptor', defined in class path resource [org/springframework/security/config/annotation/method/configuration/ReactiveMethodSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class] and overriding is disabled.
I know that the former pulls the SecurityContext
from SecurityContextHolder
and the latter pulls it from ReactiveSecurityContextHolder
. However, if I have code that manages propagation of the SecurityContext
between SecurityContextHolder
and ReactiveSecurityContextHolder
, it seems like I should be able to use both @EnableGlobalMethodSecurity
and @EnableReactiveMethodSecurity
SecurityContext
from ReactiveSecurityContextHolder
to SecurityContextHolder
. Ideally, this would allow @PreAuthorize to continue to work in the old code