use of com.epam.ta.reportportal.exception.ReportPortalException 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.exception.ReportPortalException in project service-authorization by reportportal.
the class DeleteAuthIntegrationHandlerImpl method deleteOauthSettingsById.
@Override
public OperationCompletionRS deleteOauthSettingsById(String oauthProviderId) {
OAuthRegistration oAuthRegistration = clientRegistrationRepository.findOAuthRegistrationById(oauthProviderId).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, Suppliers.formattedSupplier("Oauth settings with id = {} have not been found.", oauthProviderId).get()));
clientRegistrationRepository.deleteById(oAuthRegistration.getId());
return new OperationCompletionRS(Suppliers.formattedSupplier("Oauth settings with id = '{}' have been successfully removed.", oauthProviderId).get());
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.
the class UiAuthenticationSuccessEventHandler method onApplicationEvent.
@EventListener
@Transactional
public void onApplicationEvent(UiUserSignedInEvent event) {
String username = event.getAuthentication().getName();
userRepository.updateLastLoginDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(event.getTimestamp()), ZoneOffset.UTC), username);
if (MapUtils.isEmpty(acquireUser(event.getAuthentication()).getProjectDetails())) {
User user = userRepository.findByLogin(username).orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, username));
Project project = personalProjectService.generatePersonalProject(user);
user.getProjects().addAll(project.getUsers());
}
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class UserRepositoryCustomImpl method replaceUserPhoto.
@Override
public String replaceUserPhoto(String login, BinaryData binaryData) {
Query q = query(where(User.LOGIN).is(login));
q.fields().include(User.LOGIN).include("_id").include(User.PHOTO_ID);
User user = mongoOperations.findOne(q, User.class);
if (null == user) {
throw new ReportPortalException("User with name '" + login + "' not found");
}
return replaceUserPhoto(user, binaryData);
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project commons-dao by reportportal.
the class AttachmentBinaryDataServiceImpl method load.
@Override
public BinaryData load(Long fileId, ReportPortalUser.ProjectDetails projectDetails) {
try {
Attachment attachment = attachmentRepository.findById(fileId).orElseThrow(() -> new ReportPortalException(ErrorType.ATTACHMENT_NOT_FOUND, fileId));
InputStream data = dataStoreService.load(attachment.getFileId()).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_TO_LOAD_BINARY_DATA, fileId));
expect(attachment.getProjectId(), Predicate.isEqual(projectDetails.getProjectId())).verify(ErrorType.ACCESS_DENIED, formattedSupplier("You are not assigned to project '{}'", projectDetails.getProjectName()));
return new BinaryData(attachment.getContentType(), (long) data.available(), data);
} catch (IOException e) {
LOGGER.error("Unable to load binary data", e);
throw new ReportPortalException(ErrorType.UNCLASSIFIED_REPORT_PORTAL_ERROR, "Unable to load binary data");
}
}
Aggregations