use of org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken in project spring-security by spring-projects.
the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults.
@Test
public void logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults() {
ClientRegistration registration = TestClientRegistrations.clientRegistration().build();
ReactiveClientRegistrationRepository repository = new InMemoryReactiveClientRegistrationRepository(registration);
OidcClientInitiatedServerLogoutSuccessHandler handler = new OidcClientInitiatedServerLogoutSuccessHandler(repository);
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, registration.getRegistrationId());
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
handler.setLogoutSuccessUrl(URI.create("https://default"));
handler.onLogoutSuccess(f, token).block();
assertThat(redirectedUrl(this.exchange)).isEqualTo("https://default");
}
use of org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken in project spring-security by spring-projects.
the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect.
@Test
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect() throws IOException, ServletException {
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
MockServerHttpRequest request = MockServerHttpRequest.get("https://rp.example.org/").build();
given(this.exchange.getRequest()).willReturn(request);
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
this.handler.setPostLogoutRedirectUri("{baseUrl}");
this.handler.onLogoutSuccess(f, token).block();
assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org");
}
use of org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken in project spring-security by spring-projects.
the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenUsingPostLogoutRedirectUriThenIncludesItInRedirect.
@Test
public void logoutWhenUsingPostLogoutRedirectUriThenIncludesItInRedirect() {
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
this.handler.setPostLogoutRedirectUri(URI.create("https://postlogout?encodedparam=value"));
this.handler.onLogoutSuccess(f, token).block();
assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://postlogout?encodedparam%3Dvalue");
}
use of org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken in project dhis2-core by dhis2.
the class AuthenticationLoggerListener method onApplicationEvent.
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (!log.isWarnEnabled()) {
return;
}
if (SessionFixationProtectionEvent.class.isAssignableFrom(event.getClass()) || InteractiveAuthenticationSuccessEvent.class.isAssignableFrom(event.getClass())) {
return;
}
String eventClassName = String.format("Authentication event: %s; ", ClassUtils.getShortName(event.getClass()));
String authName = StringUtils.firstNonEmpty(event.getAuthentication().getName(), "");
String ipAddress = "";
String sessionId = "";
String exceptionMessage = "";
if (event instanceof AbstractAuthenticationFailureEvent) {
exceptionMessage = "exception: " + ((AbstractAuthenticationFailureEvent) event).getException().getMessage();
}
Object details = event.getAuthentication().getDetails();
if (details != null && ForwardedIpAwareWebAuthenticationDetails.class.isAssignableFrom(details.getClass())) {
ForwardedIpAwareWebAuthenticationDetails authDetails = (ForwardedIpAwareWebAuthenticationDetails) details;
ipAddress = String.format("ip: %s; ", authDetails.getIp());
sessionId = hashSessionId(authDetails.getSessionId());
} else if (OAuth2LoginAuthenticationToken.class.isAssignableFrom(event.getAuthentication().getClass())) {
OAuth2LoginAuthenticationToken authenticationToken = (OAuth2LoginAuthenticationToken) event.getAuthentication();
DhisOidcUser principal = (DhisOidcUser) authenticationToken.getPrincipal();
if (principal != null) {
User user = principal.getUser();
authName = user.getUsername();
}
WebAuthenticationDetails oauthDetails = (WebAuthenticationDetails) authenticationToken.getDetails();
ipAddress = String.format("ip: %s; ", oauthDetails.getRemoteAddress());
sessionId = hashSessionId(oauthDetails.getSessionId());
} else if (OAuth2AuthenticationToken.class.isAssignableFrom(event.getSource().getClass())) {
OAuth2AuthenticationToken authenticationToken = (OAuth2AuthenticationToken) event.getSource();
DhisOidcUser principal = (DhisOidcUser) authenticationToken.getPrincipal();
if (principal != null) {
User user = principal.getUser();
authName = user.getUsername();
}
}
String userNamePrefix = Strings.isNullOrEmpty(authName) ? "" : String.format("username: %s; ", authName);
log.info(TextUtils.removeNonEssentialChars(eventClassName + userNamePrefix + ipAddress + sessionId + exceptionMessage));
}
use of org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken in project books by aidanwhiteley.
the class Oauth2AuthenticationUtils method getAuthenticationProvider.
public User.AuthenticationProvider getAuthenticationProvider(OAuth2AuthenticationToken auth) {
OAuth2AuthorizedClient authorizedClient = this.getAuthorizedClient(auth);
String clientId = authorizedClient.getClientRegistration().getClientId();
if (clientId.equals(googleClientClientId)) {
return GOOGLE;
} else if (clientId.equals(facebookClientClientId)) {
return FACEBOOK;
} else {
LOGGER.error("Unknown clientId specified of {} so cant determine authentication provider.", clientId);
throw new IllegalArgumentException("Uknown client id specified");
}
}
Aggregations