Skip to content

Commit

Permalink
#207 use apereo cas client instead of jasig
Browse files Browse the repository at this point in the history
  • Loading branch information
jelemux committed Mar 29, 2023
1 parent 398a7bf commit 1386205
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 79 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<!-- cas authentication -->

<dependency>
<groupId>org.jasig.cas.client</groupId>
<groupId>org.apereo.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>${cas-client.version}</version>
</dependency>
Expand Down Expand Up @@ -382,7 +382,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cas-client.version>3.4.1</cas-client.version>
<cas-client.version>4.0.1</cas-client.version>
<java.version>11</java.version>
<jaxb.version>2.3.0</jaxb.version>
<!-- <tomcat.version>9.0.69</tomcat.version>-->
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cloudogu/smeagol/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.common.base.Strings;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.apereo.cas.client.authentication.AttributePrincipal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.annotations.VisibleForTesting;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jasig.cas.client.authentication.AuthenticationRedirectStrategy;
import org.apereo.cas.client.authentication.AuthenticationRedirectStrategy;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;

Expand All @@ -21,19 +21,13 @@ public class AjaxAwareAuthenticationRedirectStrategy implements AuthenticationRe
@VisibleForTesting
static final String AJAX_HEADER_VALUE = "XMLHttpRequest";

// @Override
// public void redirect(HttpServletRequest request, HttpServletResponse response, String potentialRedirectUrl) throws IOException {
// if (isAjaxRequest(request)) {
// sendAjaxResponse(response, potentialRedirectUrl);
// } else {
// sendNormalResponse(response, potentialRedirectUrl);
// }
// }


@Override
public void redirect(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, String s) throws IOException {
// TODO
public void redirect(HttpServletRequest request, HttpServletResponse response, String potentialRedirectUrl) throws IOException {
if (isAjaxRequest(request)) {
sendAjaxResponse(response, potentialRedirectUrl);
} else {
sendNormalResponse(response, potentialRedirectUrl);
}
}

private boolean isAjaxRequest(HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.cloudogu.smeagol.authc.infrastructure;

import com.cloudogu.smeagol.Stage;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.Filter;
import jakarta.servlet.http.HttpSessionListener;
import org.jasig.cas.client.authentication.AuthenticationFilter;
import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
import org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter;
import org.apereo.cas.client.authentication.AuthenticationFilter;
import org.apereo.cas.client.session.SingleSignOutFilter;
import org.apereo.cas.client.session.SingleSignOutHttpSessionListener;
import org.apereo.cas.client.util.HttpServletRequestWrapperFilter;
import org.apereo.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,8 +16,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

Expand All @@ -33,7 +30,7 @@ public class CasInfrastructureRegistration {

private Map<String,String> casSettings;

// @Autowired
@Autowired
public CasInfrastructureRegistration(CasConfiguration configuration, Stage stage) {
this.casSettings = configuration.createCasSettings();
if (stage == Stage.DEVELOPMENT) {
Expand All @@ -51,21 +48,7 @@ public CasInfrastructureRegistration(CasConfiguration configuration, Stage stage
@Bean
public ServletListenerRegistrationBean<HttpSessionListener> singleSignOutListener() {
ServletListenerRegistrationBean<HttpSessionListener> listener = new ServletListenerRegistrationBean<>();
// TODO
// listener.setListener(new SingleSignOutHttpSessionListener());
listener.setListener(new HttpSessionListener() {
private final SingleSignOutHttpSessionListener sessionListener = new SingleSignOutHttpSessionListener();
@Override
public void sessionCreated(HttpSessionEvent se) {
// sessionListener.sessionCreated(new javax.servlet.http.HttpSessionEvent();
HttpSessionListener.super.sessionCreated(se);
}

@Override
public void sessionDestroyed(HttpSessionEvent se) {
HttpSessionListener.super.sessionDestroyed(se);
}
});
listener.setListener(new SingleSignOutHttpSessionListener());
return listener;
}

Expand All @@ -74,51 +57,29 @@ public void sessionDestroyed(HttpSessionEvent se) {
*
* @return filter registration
*/
// @Bean
@Bean
public FilterRegistrationBean singleSignOutFilter() {
// // TODO
// return casFilterRegistration(new SingleSignOutFilter(), 0);
return casFilterRegistration(new Filter() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

}
}, 0);
return casFilterRegistration(new SingleSignOutFilter(), 0);
}

/**
* Registers a servlet filter who is responsible for validating received cas tickets.
*
* @return filter registration
*/
// @Bean
@Bean
public FilterRegistrationBean proxyReceivingTicketValidationFilter() {
// TODO
// return casFilterRegistration(new Cas30ProxyReceivingTicketValidationFilter(), 1);
return casFilterRegistration(new Filter() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

}
}, 1);
return casFilterRegistration(new Cas30ProxyReceivingTicketValidationFilter(), 1);
}

/**
* Registers a servlet filter who is responsible for the cas authentication flow.
*
* @return filter registration
*/
// @Bean
@Bean
public FilterRegistrationBean authenticationFilter() {

// TODO
// return casFilterRegistration(new AuthenticationFilter(), 2);
return casFilterRegistration(new Filter() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

}
}, 2);
return casFilterRegistration(new AuthenticationFilter(), 2);
}

/**
Expand All @@ -127,17 +88,9 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
*
* @return filter registration
*/
// @Bean
@Bean
public FilterRegistrationBean requestWrapperFilter() {

// TODO
// return casFilterRegistration(new HttpServletRequestWrapperFilter(), 3);
return casFilterRegistration(new Filter() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

}
}, 3);
return casFilterRegistration(new HttpServletRequestWrapperFilter(), 3);
}

private FilterRegistrationBean casFilterRegistration(Filter filter, int order){
Expand Down

0 comments on commit 1386205

Please sign in to comment.