Search in sources :

Example 16 with ReportPortalException

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);
    }
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) NullLdapAuthoritiesPopulator(org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator) LdapAuthenticationProviderConfigurer(org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer)

Example 17 with ReportPortalException

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());
}
Also used : OAuthRegistration(com.epam.ta.reportportal.entity.oauth.OAuthRegistration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 18 with ReportPortalException

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());
    }
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) User(com.epam.ta.reportportal.entity.user.User) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) EventListener(org.springframework.context.event.EventListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with ReportPortalException

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);
}
Also used : User(com.epam.ta.reportportal.database.entity.user.User) Query(org.springframework.data.mongodb.core.query.Query) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 20 with ReportPortalException

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");
    }
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Attachment(com.epam.ta.reportportal.entity.attachment.Attachment) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData)

Aggregations

ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)33 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)6 AuthIntegrationType (com.epam.reportportal.auth.integration.AuthIntegrationType)5 BaseTest (com.epam.ta.reportportal.BaseTest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 Integration (com.epam.ta.reportportal.entity.integration.Integration)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 QueryBuilder (com.epam.ta.reportportal.commons.querygen.QueryBuilder)2 ID (com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID)2 JooqFieldNameTransformer.fieldName (com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName)2 QueryUtils (com.epam.ta.reportportal.dao.util.QueryUtils)2 ServerSettings (com.epam.ta.reportportal.database.entity.settings.ServerSettings)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Log (com.epam.ta.reportportal.entity.log.Log)2 JStatusEnum (com.epam.ta.reportportal.jooq.enums.JStatusEnum)2