-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from OpsMx/bugfix/OP-17106-4-0
OP-17106: Added SamlSsoEventPublishConfig to update ApplicationEventPublisher
- Loading branch information
Showing
3 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...-saml/src/main/java/com/opsmx/spinnaker/gate/security/saml/SamlSsoEventPublishConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.opsmx.spinnaker.gate.security.saml; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.servlet.Filter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.saml.SAMLProcessingFilter; | ||
import org.springframework.security.web.FilterChainProxy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@ConditionalOnExpression("${saml.enabled:false}") | ||
@Configuration | ||
@Slf4j | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public class SamlSsoEventPublishConfig { | ||
|
||
private ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@Autowired | ||
@Qualifier("springSecurityFilterChain") | ||
private Filter springSecurityFilterChain; | ||
|
||
@Autowired | ||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { | ||
this.applicationEventPublisher = applicationEventPublisher; | ||
} | ||
|
||
@Bean | ||
public FilterChainProxy getFilters() { | ||
FilterChainProxy filterChainProxy = (FilterChainProxy) springSecurityFilterChain; | ||
List<SecurityFilterChain> list = filterChainProxy.getFilterChains(); | ||
|
||
list.stream() | ||
.flatMap(chain -> chain.getFilters().stream()) | ||
.filter(filter -> filter.getClass() == FilterChainProxy.class) | ||
.findAny() | ||
.map(FilterChainProxy.class::cast) | ||
.map(FilterChainProxy::getFilterChains) | ||
.orElse(new ArrayList<>()) | ||
.stream() | ||
.flatMap(chin -> chin.getFilters().stream()) | ||
.filter(filter -> filter.getClass() == SAMLProcessingFilter.class) | ||
.findAny() | ||
.map(SAMLProcessingFilter.class::cast) | ||
.ifPresent(filter -> filter.setApplicationEventPublisher(applicationEventPublisher)); | ||
return filterChainProxy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
gate-web/src/main/java/com/opsmx/spinnaker/gate/model/AuditData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 OpsMx | ||
* | ||
* Licensed 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 com.opsmx.spinnaker.gate.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class AuditData { | ||
private Source source; | ||
|
||
public AuditData(String name) { | ||
this.source = new Source(name); | ||
} | ||
|
||
@Data | ||
public class Source { | ||
private String name; | ||
|
||
public Source(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |