use of com.epam.ta.reportportal.exception.ReportPortalException 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);
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.
the class SamlIntegrationStrategy method populateProviderDetails.
private void populateProviderDetails(Integration samlIntegration) {
Map<String, Object> params = samlIntegration.getParams().getParams();
ExternalIdentityProviderConfiguration externalConfiguration = new ExternalIdentityProviderConfiguration().setMetadata(SamlParameter.IDP_METADATA_URL.getRequiredParameter(samlIntegration));
IdentityProviderMetadata remoteProvider = serviceProviderProvisioning.getHostedProvider().getRemoteProvider(externalConfiguration);
params.put(IDP_URL.getParameterName(), remoteProvider.getEntityId());
params.put(IDP_ALIAS.getParameterName(), remoteProvider.getEntityAlias());
NameId nameId = ofNullable(remoteProvider.getDefaultNameId()).orElseGet(() -> {
Optional<NameId> first = remoteProvider.getProviders().stream().filter(IdentityProvider.class::isInstance).map(IdentityProvider.class::cast).flatMap(v -> v.getNameIds().stream()).filter(Objects::nonNull).findFirst();
return first.orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Provider does not contain information about identification mapping"));
});
params.put(IDP_NAME_ID.getParameterName(), nameId.toString());
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.
the class SamlUserReplicator method replicateUser.
public User replicateUser(ReportPortalSamlAuthentication samlAuthentication) {
String userName = CROP_DOMAIN.apply(samlAuthentication.getPrincipal());
Optional<User> userOptional = userRepository.findByLogin(userName);
if (userOptional.isPresent()) {
return userOptional.get();
}
IntegrationType samlIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.SAML.getName()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.SAML.getName()));
List<Integration> providers = integrationRepository.findAllGlobalByType(samlIntegrationType);
Optional<Integration> samlProvider = providers.stream().filter(provider -> {
Optional<String> idpUrlOptional = SamlParameter.IDP_URL.getParameter(provider);
return idpUrlOptional.isPresent() && idpUrlOptional.get().equalsIgnoreCase(samlAuthentication.getIssuer());
}).findFirst();
User user = new User();
user.setLogin(userName);
List<Attribute> details = samlAuthentication.getDetails();
if (samlProvider.isPresent()) {
populateUserDetailsIfSettingsArePresent(user, samlProvider.get(), details);
} else {
populateUserDetails(user, details);
}
user.setUserType(UserType.SAML);
user.setRole(UserRole.USER);
user.setExpired(false);
Project project = generatePersonalProject(user);
user.getProjects().add(project.getUsers().iterator().next());
user.setMetadata(defaultMetaData());
userRepository.save(user);
return user;
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.
the class BasicPasswordAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
boolean accountNonLocked = !failureEventHandler.isBlocked(request.get());
if (!accountNonLocked) {
throw new ReportPortalException(ErrorType.ADDRESS_LOCKED);
}
Authentication auth = super.authenticate(authentication);
eventPublisher.publishEvent(new UiUserSignedInEvent(auth));
return auth;
}
use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.
the class DeleteAuthIntegrationHandlerImpl method deleteAuthIntegrationById.
@Override
public OperationCompletionRS deleteAuthIntegrationById(Long integrationId) {
Integration integration = integrationRepository.findById(integrationId).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, integrationId));
BusinessRule.expect(integration.getType().getIntegrationGroup(), equalTo(IntegrationGroupEnum.AUTH)).verify(ErrorType.BAD_REQUEST_ERROR, "Integration should have an 'AUTH' integration group type.");
integrationRepository.deleteById(integrationId);
if (AuthIntegrationType.SAML.getName().equals(integration.getType().getName())) {
eventPublisher.publishEvent(new SamlProvidersReloadEvent(integration.getType()));
}
return new OperationCompletionRS("Auth integration with id= " + integrationId + " has been successfully removed.");
}
Aggregations