use of com.epam.ta.reportportal.database.entity.settings.ServerSettings in project service-authorization by reportportal.
the class OAuthConfigurationEndpoint method getOAuthSettings.
/**
* Returns oauth integration settings
*
* @param profileId settings ProfileID
* @param oauthProviderName ID of third-party OAuth provider
* @return All defined OAuth integration settings
*/
@RequestMapping(value = "/{authId}", method = { GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns OAuth Server Settings", notes = "'default' profile is using till additional UI implementations")
public OAuthDetailsResource getOAuthSettings(@PathVariable String profileId, @PathVariable("authId") String oauthProviderName) {
ServerSettings settings = repository.findOne(profileId);
BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);
return Optional.ofNullable(settings.getoAuth2LoginDetails()).flatMap(details -> Optional.ofNullable(details.get(oauthProviderName))).map(OAuthDetailsConverters.TO_RESOURCE).orElseThrow(() -> new ReportPortalException(ErrorType.OAUTH_INTEGRATION_NOT_FOUND, oauthProviderName));
}
use of com.epam.ta.reportportal.database.entity.settings.ServerSettings in project service-authorization by reportportal.
the class OAuthConfigurationEndpoint method deleteOAuthSetting.
/**
* Deletes oauth integration settings
*
* @param profileId settings ProfileID
* @param oauthProviderName ID of third-party OAuth provider
* @return All defined OAuth integration settings
*/
@RequestMapping(value = "/{authId}", method = { DELETE })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Deletes OAuth Integration Settings", notes = "'default' profile is using till additional UI implementations")
public OperationCompletionRS deleteOAuthSetting(@PathVariable String profileId, @PathVariable("authId") String oauthProviderName) {
ServerSettings settings = repository.findOne(profileId);
BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);
Map<String, OAuth2LoginDetails> serverOAuthDetails = Optional.of(settings.getoAuth2LoginDetails()).orElse(new HashMap<>());
if (null != serverOAuthDetails.remove(oauthProviderName)) {
settings.setoAuth2LoginDetails(serverOAuthDetails);
repository.save(settings);
} else {
throw new ReportPortalException(ErrorType.OAUTH_INTEGRATION_NOT_FOUND);
}
return new OperationCompletionRS("Auth settings '" + oauthProviderName + "' were successfully removed");
}
use of com.epam.ta.reportportal.database.entity.settings.ServerSettings in project service-authorization by reportportal.
the class OAuthConfigurationEndpoint method updateOAuthSettings.
/**
* Updates oauth integration settings
*
* @param profileId settings ProfileID
* @param oauthDetails OAuth details resource update
* @param oauthProviderName ID of third-party OAuth provider
* @return All defined OAuth integration settings
*/
@RequestMapping(value = "/{authId}", method = { POST, PUT })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Updates OAuth Integration Settings", notes = "'default' profile is using till additional UI implementations")
public Map<String, OAuthDetailsResource> updateOAuthSettings(@PathVariable String profileId, @PathVariable("authId") String oauthProviderName, @RequestBody @Validated OAuthDetailsResource oauthDetails) {
Optional<OAuthProvider> oAuthProvider = Optional.ofNullable(providers.get(oauthProviderName));
BusinessRule.expect(oAuthProvider, isPresent()).verify(ErrorType.OAUTH_INTEGRATION_NOT_FOUND, profileId);
ServerSettings settings = repository.findOne(profileId);
BusinessRule.expect(settings, Predicates.notNull()).verify(ErrorType.SERVER_SETTINGS_NOT_FOUND, profileId);
Map<String, OAuth2LoginDetails> serverOAuthDetails = Optional.ofNullable(settings.getoAuth2LoginDetails()).orElse(new HashMap<>());
OAuth2LoginDetails loginDetails = OAuthDetailsConverters.FROM_RESOURCE.apply(oauthDetails);
oAuthProvider.get().applyDefaults(loginDetails);
serverOAuthDetails.put(oauthProviderName, loginDetails);
settings.setoAuth2LoginDetails(serverOAuthDetails);
repository.save(settings);
return serverOAuthDetails.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> OAuthDetailsConverters.TO_RESOURCE.apply(e.getValue())));
}
Aggregations