Search in sources :

Example 1 with OAuth2LoginDetails

use of com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails 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");
}
Also used : OAuth2LoginDetails(com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ServerSettings(com.epam.ta.reportportal.database.entity.settings.ServerSettings) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with OAuth2LoginDetails

use of com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails in project service-authorization by reportportal.

the class OAuthDetailsConvertersTest method testToResource.

@Test
public void testToResource() {
    OAuth2LoginDetails oAuth2LoginDetails = new OAuth2LoginDetails();
    oAuth2LoginDetails.setScope(Collections.singletonList("user"));
    oAuth2LoginDetails.setGrantType("authorization_code");
    oAuth2LoginDetails.setClientId("f4cec43d4541283879c4");
    oAuth2LoginDetails.setClientSecret("a31aa6de3e27c11d90762cad11936727d6b0759e");
    oAuth2LoginDetails.setAccessTokenUri("https://github.com/login/oauth/access_token");
    oAuth2LoginDetails.setUserAuthorizationUri("https://github.com/login/oauth/authorize");
    oAuth2LoginDetails.setClientAuthenticationScheme("form");
    validate(OAuthDetailsConverters.TO_RESOURCE.apply(oAuth2LoginDetails), oAuth2LoginDetails);
}
Also used : OAuth2LoginDetails(com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails) Test(org.junit.Test)

Example 3 with OAuth2LoginDetails

use of com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails 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())));
}
Also used : OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) OAuth2LoginDetails(com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) OAuthDetailsResource(com.epam.ta.reportportal.ws.model.settings.OAuthDetailsResource) Controller(org.springframework.stereotype.Controller) ApiOperation(io.swagger.annotations.ApiOperation) Predicates(com.epam.ta.reportportal.commons.Predicates) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) OAuthProvider(com.epam.reportportal.auth.oauth.OAuthProvider) Api(io.swagger.annotations.Api) BusinessRule(com.epam.ta.reportportal.commons.validation.BusinessRule) Validated(org.springframework.validation.annotation.Validated) ServerSettingsRepository(com.epam.ta.reportportal.database.dao.ServerSettingsRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Predicates.isPresent(com.epam.ta.reportportal.commons.Predicates.isPresent) Collectors(java.util.stream.Collectors) ServerSettings(com.epam.ta.reportportal.database.entity.settings.ServerSettings) OAuthDetailsConverters(com.epam.reportportal.auth.converter.OAuthDetailsConverters) HttpStatus(org.springframework.http.HttpStatus) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) OAuth2LoginDetails(com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails) ServerSettings(com.epam.ta.reportportal.database.entity.settings.ServerSettings) OAuthProvider(com.epam.reportportal.auth.oauth.OAuthProvider) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

OAuth2LoginDetails (com.epam.ta.reportportal.database.entity.settings.OAuth2LoginDetails)3 ServerSettings (com.epam.ta.reportportal.database.entity.settings.ServerSettings)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)2 ApiOperation (io.swagger.annotations.ApiOperation)2 OAuthDetailsConverters (com.epam.reportportal.auth.converter.OAuthDetailsConverters)1 OAuthProvider (com.epam.reportportal.auth.oauth.OAuthProvider)1 Predicates (com.epam.ta.reportportal.commons.Predicates)1 Predicates.isPresent (com.epam.ta.reportportal.commons.Predicates.isPresent)1 BusinessRule (com.epam.ta.reportportal.commons.validation.BusinessRule)1 ServerSettingsRepository (com.epam.ta.reportportal.database.dao.ServerSettingsRepository)1 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)1 OAuthDetailsResource (com.epam.ta.reportportal.ws.model.settings.OAuthDetailsResource)1 Api (io.swagger.annotations.Api)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Test (org.junit.Test)1