use of com.epam.ta.reportportal.entity.integration.Integration in project service-authorization by reportportal.
the class AuthIntegrationStrategy method createIntegration.
public Integration createIntegration(IntegrationType integrationType, UpdateAuthRQ request, String username) {
updateAuthRequestValidator.validate(request);
final Integration integration = new AuthIntegrationBuilder().addCreator(username).addIntegrationType(integrationType).addCreationDate(LocalDateTime.now(ZoneOffset.UTC)).build();
fill(integration, request);
return save(integration);
}
use of com.epam.ta.reportportal.entity.integration.Integration in project service-authorization by reportportal.
the class SamlProvidersReloadEventHandler method onApplicationEvent.
@Override
public void onApplicationEvent(SamlProvidersReloadEvent event) {
final IntegrationType integrationType = event.getIntegrationType();
final List<Integration> integrations = integrationRepository.findAllGlobalByType(integrationType);
LocalServiceProviderConfiguration serviceProvider = samlConfiguration.getServiceProvider();
serviceProvider.getProviders().clear();
serviceProvider.getProviders().addAll(SamlConverter.TO_EXTERNAL_PROVIDER_CONFIG.apply(integrations));
}
use of com.epam.ta.reportportal.entity.integration.Integration in project service-authorization by reportportal.
the class ActiveDirectoryAuthProvider method getDelegate.
@Override
protected AuthenticationProvider getDelegate() {
Integration integration = integrationRepository.findAllByTypeIn(AuthIntegrationType.ACTIVE_DIRECTORY.getName()).stream().findFirst().orElseThrow(() -> new BadCredentialsException("Active Directory is not configured"));
ActiveDirectoryLdapAuthenticationProvider adAuth = new ActiveDirectoryLdapAuthenticationProvider(LdapParameter.DOMAIN.getParameter(integration).orElse(null), LdapParameter.URL.getRequiredParameter(integration), LdapParameter.BASE_DN.getRequiredParameter(integration));
adAuth.setAuthoritiesMapper(new NullAuthoritiesMapper());
adAuth.setUserDetailsContextMapper(detailsContextMapper);
LdapParameter.SEARCH_FILTER_REMOVE_NOT_PRESENT.getParameter(integration).ifPresent(adAuth::setSearchFilter);
return adAuth;
}
use of com.epam.ta.reportportal.entity.integration.Integration in project service-authorization by reportportal.
the class LdapAuthProvider method getDelegate.
@Override
protected AuthenticationProvider getDelegate() {
Integration integration = integrationRepository.findAllByTypeIn(AuthIntegrationType.LDAP.getName()).stream().findFirst().orElseThrow(() -> new BadCredentialsException("LDAP is not configured"));
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(singletonList(LdapParameter.URL.getRequiredParameter(integration)), LdapParameter.BASE_DN.getRequiredParameter(integration));
LdapParameter.MANAGER_PASSWORD.getParameter(integration).ifPresent(it -> contextSource.setPassword(encryptor.decrypt(it)));
LdapParameter.MANAGER_DN.getParameter(integration).ifPresent(contextSource::setUserDn);
contextSource.afterPropertiesSet();
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> builder = new LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder>().contextSource(contextSource).ldapAuthoritiesPopulator(new NullLdapAuthoritiesPopulator()).userDetailsContextMapper(detailsContextMapper);
/*
* Basically, groups are not used
*/
LdapParameter.GROUP_SEARCH_FILTER.getParameter(integration).ifPresent(builder::groupSearchFilter);
LdapParameter.GROUP_SEARCH_BASE.getParameter(integration).ifPresent(builder::groupSearchBase);
LdapParameter.USER_SEARCH_FILTER.getParameter(integration).ifPresent(builder::userSearchFilter);
LdapParameter.PASSWORD_ENCODER_TYPE.getParameter(integration).ifPresent(it -> {
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder>.PasswordCompareConfigurer passwordCompareConfigurer = builder.passwordCompare();
LdapParameter.PASSWORD_ATTRIBUTE.getParameter(integration).ifPresent(passwordCompareConfigurer::passwordAttribute);
/*
* DIRTY HACK. If LDAP's password has solt, ldaptemplate.compare operation does not work
* since we don't know server's salt.
* To enable local password comparison, we need to provide password encoder from crypto's package
* This is why we just wrap old encoder with new one interface
* New encoder cannot be used everywhere since it does not have implementation for LDAP
*/
final PasswordEncoder delegate = PasswordEncoderFactories.createDelegatingPasswordEncoder();
builder.passwordEncoder(new org.springframework.security.crypto.password.PasswordEncoder() {
@Override
public String encode(CharSequence rawPassword) {
return delegate.encode(rawPassword);
}
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
return delegate.matches(rawPassword, encodedPassword);
}
});
});
LdapParameter.USER_DN_PATTERN.getParameter(integration).ifPresent(builder::userDnPatterns);
try {
return (AuthenticationProvider) Accessible.on(builder).method(LdapAuthenticationProviderConfigurer.class.getDeclaredMethod("build")).invoke();
} catch (Throwable e) {
throw new ReportPortalException("Cannot build LDAP auth provider", e);
}
}
use of com.epam.ta.reportportal.entity.integration.Integration in project service-authorization by reportportal.
the class AuthIntegrationStrategy method updateIntegration.
public Integration updateIntegration(IntegrationType integrationType, Long integrationId, UpdateAuthRQ request) {
updateAuthRequestValidator.validate(request);
final Integration integration = integrationRepository.findByIdAndTypeIdAndProjectIdIsNull(integrationId, integrationType.getId()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, integrationType.getName()));
fill(integration, request);
return save(integration);
}
Aggregations