CheckIdpEnabledAuthenticationManager implements AuthenticationManager { @Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { try { IdentityProvider idp = identityProviderProvisioning.retrieveByOriginIgnoreActiveFlag(getOrigin(), IdentityZoneHolder.get().getId()); if (!idp.isActive()) { throw new ProviderNotFoundException("Identity Provider \"" + idp.getName() + "\" has been disabled by administrator."); } } catch (EmptyResultDataAccessException x) { throw new ProviderNotFoundException("Unable to find identity provider for origin: " + getOrigin()); } return delegate.authenticate(authentication); } CheckIdpEnabledAuthenticationManager(AuthenticationManager delegate, String origin, final @Qualifier("identityProviderProvisioning") IdentityProviderProvisioning identityProviderProvisioning); String getOrigin(); @Override Authentication authenticate(final Authentication authentication);  }
@Test void authenticate() { Authentication auth = manager.authenticate(token); assertNotNull(auth); assertTrue(auth.isAuthenticated()); }
@Test void authenticateIdpDisabled() { IdentityProvider provider = identityProviderProvisioning.retrieveByOrigin(OriginKeys.UAA, IdentityZoneHolder.get().getId()); provider.setActive(false); identityProviderProvisioning.update(provider, IdentityZoneHolder.get().getId()); assertThrows(ProviderNotFoundException.class, () -> manager.authenticate(token)); }