Skip to content

Commit

Permalink
Align with upstream CAS
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Oct 11, 2023
1 parent d947df5 commit d55ef48
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

public class OIDCC4UIContext implements WebContext {

@Override
public Optional<String> getQueryString() {
return Optional.empty();
}

@Override
public String getRequestMethod() {
return HttpMethod.GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public SAML2SP4UIContext(final String bindingType, final SAML2Response saml2Resp
this.saml2Response = saml2Response;
}

@Override
public Optional<String> getQueryString() {
return Optional.empty();
}

@Override
public String getRequestMethod() {
return SAML2BindingType.POST.getUri().equals(bindingType)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ under the License.
<commons-jexl.version>3.3</commons-jexl.version>
<commons-text.version>1.10.0</commons-text.version>

<pac4j.version>6.0.0-RC9</pac4j.version>
<pac4j.version>6.0.0-RC10-SNAPSHOT</pac4j.version>

<cas.version>7.0.0-SNAPSHOT</cas.version>
<cas-client.version>4.0.3</cas-client.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ public ServerWebExchangeContext setForm(final MultiValueMap<String, String> form
return this;
}

@Override
public Optional<String> getQueryString() {
return Optional.ofNullable(exchange.getRequest().getURI().getQuery());
}

@Override
public Map<String, String[]> getRequestParameters() {
Map<String, String[]> params = new HashMap<>();

this.exchange.getRequest().getQueryParams().
exchange.getRequest().getQueryParams().
forEach((key, value) -> params.put(key, new String[] { value.toString() }));

if (this.form != null) {
if (form != null) {
form.forEach((key, values) -> params.put(key, values.toArray(String[]::new)));
}

Expand All @@ -100,12 +105,12 @@ public Optional<String> getRequestHeader(final String name) {

@Override
public String getRequestMethod() {
return this.exchange.getRequest().getMethod().name();
return exchange.getRequest().getMethod().name();
}

@Override
public String getRemoteAddr() {
return this.exchange.getRequest().getRemoteAddress().getHostString();
return exchange.getRequest().getRemoteAddress().getHostString();
}

/**
Expand All @@ -114,7 +119,7 @@ public String getRemoteAddr() {
* @return the native exchange
*/
public ServerWebExchange getNative() {
return this.exchange;
return exchange;
}

@Override
Expand All @@ -124,12 +129,12 @@ public void setResponseHeader(final String name, final String value) {

@Override
public Optional<String> getResponseHeader(final String s) {
return Optional.ofNullable(this.exchange.getResponse().getHeaders().getFirst(s));
return Optional.ofNullable(exchange.getResponse().getHeaders().getFirst(s));
}

@Override
public void setResponseContentType(final String content) {
this.exchange.getResponse().getHeaders().set(HttpHeaders.CONTENT_TYPE, content);
exchange.getResponse().getHeaders().set(HttpHeaders.CONTENT_TYPE, content);
}

@Override
Expand All @@ -139,40 +144,36 @@ public String getProtocol() {

@Override
public String getServerName() {
return ForwardedHeaderUtils.
adaptFromForwardedHeaders(exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).
build().getHost();
return ForwardedHeaderUtils.adaptFromForwardedHeaders(
exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).build().getHost();
}

@Override
public int getServerPort() {
return ForwardedHeaderUtils.
adaptFromForwardedHeaders(exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).
build().getPort();
return ForwardedHeaderUtils.adaptFromForwardedHeaders(
exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).build().getPort();
}

@Override
public String getScheme() {
return ForwardedHeaderUtils.
adaptFromForwardedHeaders(exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).
build().getScheme();
return ForwardedHeaderUtils.adaptFromForwardedHeaders(
exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).build().getScheme();
}

@Override
public boolean isSecure() {
return this.exchange.getRequest().getSslInfo() != null;
return exchange.getRequest().getSslInfo() != null;
}

@Override
public String getFullRequestURL() {
return ForwardedHeaderUtils.
adaptFromForwardedHeaders(exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).
build().toUriString();
return ForwardedHeaderUtils.adaptFromForwardedHeaders(
exchange.getRequest().getURI(), exchange.getRequest().getHeaders()).build().toUriString();
}

@Override
public Collection<Cookie> getRequestCookies() {
MultiValueMap<String, HttpCookie> cookies = this.exchange.getRequest().getCookies();
MultiValueMap<String, HttpCookie> cookies = exchange.getRequest().getCookies();

Collection<Cookie> pac4jCookies = new LinkedHashSet<>();
cookies.toSingleValueMap().values().forEach(c -> {
Expand All @@ -190,7 +191,7 @@ public void addResponseCookie(final Cookie cookie) {
c.maxAge(cookie.getMaxAge());
c.httpOnly(cookie.isHttpOnly());
c.domain(cookie.getDomain());
this.exchange.getResponse().addCookie(c.build());
exchange.getResponse().addCookie(c.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class WAProperties extends SyncopeProperties {

private static final long serialVersionUID = 7925827623055998239L;

private long contextRefreshDelay = 15;
private int contextRefreshDelay = 15;

public long getContextRefreshDelay() {
public int getContextRefreshDelay() {
return contextRefreshDelay;
}

public void setContextRefreshDelay(final long contextRefreshDelay) {
public void setContextRefreshDelay(final int contextRefreshDelay) {
this.contextRefreshDelay = contextRefreshDelay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStart;
import org.apache.syncope.common.keymaster.client.api.startstop.KeymasterStop;
import org.apache.syncope.common.lib.types.IdRepoEntitlement;
import org.apache.syncope.wa.bootstrap.WAProperties;
import org.apache.syncope.wa.bootstrap.WARestClient;
import org.apache.syncope.wa.bootstrap.mapping.AttrReleaseMapper;
Expand Down Expand Up @@ -100,6 +101,10 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration(proxyBeanMethods = false)
public class WAContext {
Expand Down Expand Up @@ -376,6 +381,16 @@ public SyncopeWAInfoContributor syncopeWAInfoContributor(final WAProperties waPr
return new SyncopeWAInfoContributor(waProperties);
}

@ConditionalOnMissingBean
@Bean
public UserDetailsService actuatorUserDetailsService(final WAProperties waProperties) {
UserDetails user = User.withUsername(waProperties.getAnonymousUser()).
password("{noop}" + waProperties.getAnonymousKey()).
roles(IdRepoEntitlement.ANONYMOUS).
build();
return new InMemoryUserDetailsManager(user);
}

@Bean
public KeymasterStart keymasterStart() {
return new KeymasterStart(NetworkService.Type.WA);
Expand Down
3 changes: 0 additions & 3 deletions wa/starter/src/main/resources/wa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ cas.sso.services.allow-missing-service-parameter=true
# by default for now.
cas.acceptable-usage-policy.core.enabled=false

spring.security.user.name=${anonymousUser}
spring.security.user.password=${anonymousKey}

springdoc.show-actuator=true
springdoc.model-and-view-allowed=true
springdoc.writer-with-default-pretty-printer=true
Expand Down
4 changes: 4 additions & 0 deletions wa/starter/src/test/resources/debug/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ under the License.
<appender-ref ref="main"/>
</asyncLogger>

<asyncLogger name="io.micrometer" additivity="false" level="ERROR">
<appender-ref ref="main"/>
</asyncLogger>

<asyncLogger name="org.springframework" additivity="false" level="INFO">
<appender-ref ref="main"/>
</asyncLogger>
Expand Down
6 changes: 4 additions & 2 deletions wa/starter/src/test/resources/debug/wa-debug.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
# under the License.
spring.main.allow-circular-references=true

#keymaster.address=http://localhost:9080/syncope/rest/keymaster
keymaster.address=https://localhost:9443/syncope/rest/keymaster
keymaster.address=http://localhost:9080/syncope/rest/keymaster
#keymaster.address=https://localhost:9443/syncope/rest/keymaster
keymaster.username=${anonymousUser}
keymaster.password=${anonymousKey}

management.endpoints.web.exposure.include=info,health,env,beans,loggers,ssoSessions,registeredServices,refresh,authenticationHandlers,authenticationPolicies,resolveAttributes

cas.server.name=http://localhost:8080
cas.server.prefix=${cas.server.name}/syncope-wa
cas.authn.accept.users=admin::password
Expand Down

0 comments on commit d55ef48

Please sign in to comment.