From 2a3dec708169aadbed26d4e6cf1ef2551eb15f8a Mon Sep 17 00:00:00 2001 From: Joze RIHTARSIC <joze.RIHTARSIC@ext.ec.europa.eu> Date: Thu, 5 May 2022 17:22:15 +0200 Subject: [PATCH] Fix authentication for cas --- smp-angular/src/app/security/security.service.ts | 1 - .../edelivery/smp/auth/SMPAuthorizationService.java | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/smp-angular/src/app/security/security.service.ts b/smp-angular/src/app/security/security.service.ts index 02210b828..db7c512b5 100644 --- a/smp-angular/src/app/security/security.service.ts +++ b/smp-angular/src/app/security/security.service.ts @@ -17,7 +17,6 @@ export class SecurityService { private http: HttpClient, private alertService: AlertMessageService, private securityEventService: SecurityEventService, - private lookups: GlobalLookups ) { this.securityEventService.onLogoutSuccessEvent().subscribe(() => window.location.reload()); this.securityEventService.onLogoutErrorEvent().subscribe((error) => this.alertService.error(error)); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java index 92c8718db..3ac7d6209 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java @@ -9,6 +9,7 @@ import eu.europa.ec.edelivery.smp.services.ServiceGroupService; import eu.europa.ec.edelivery.smp.utils.SessionSecurityUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.cas.authentication.CasAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.session.SessionAuthenticationException; @@ -91,7 +92,7 @@ public class SMPAuthorizationService { return userRO; } - private SMPAuthenticationToken getSessionAuthentication() { + private Authentication getSessionAuthentication() { if (SecurityContextHolder.getContext() == null) { LOG.warn("No users is logged-in! Session security context is null!"); return null; @@ -101,15 +102,16 @@ public class SMPAuthorizationService { LOG.warn("No users is logged-in! Authentication is null or not authenticated!"); return null; } - if (!(authentication instanceof SMPAuthenticationToken)) { + if (!(authentication instanceof SMPAuthenticationToken + || authentication instanceof CasAuthenticationToken)) { LOG.warn("User is logged and authenticated with not supported Authentication [{}]!", authentication.getClass()); return null; } - return (SMPAuthenticationToken) authentication; + return authentication; } - private SMPAuthenticationToken getAndValidateSessionAuthentication() { - SMPAuthenticationToken authentication = getSessionAuthentication(); + private Authentication getAndValidateSessionAuthentication() { + Authentication authentication = getSessionAuthentication(); if (authentication == null) { throw new SessionAuthenticationException(ERR_INVALID_OR_NULL); } -- GitLab