This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PassportConfigurationWebResource.java
104 lines (95 loc) · 4.76 KB
/
PassportConfigurationWebResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package org.gluu.oxtrust.api.server.api.impl;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gluu.config.oxtrust.AppConfiguration;
import org.gluu.oxtrust.api.server.model.PassportConfig;
import org.gluu.oxtrust.api.server.util.ApiConstants;
import org.gluu.oxtrust.api.server.util.Constants;
import org.gluu.oxtrust.service.JsonConfigurationService;
import org.gluu.oxtrust.service.filter.ProtectedApi;
import org.slf4j.Logger;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
@Path(ApiConstants.CONFIGURATION + ApiConstants.PASSPORT)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApplicationScoped
public class PassportConfigurationWebResource extends BaseWebResource {
@Inject
private Logger logger;
@Inject
private JsonConfigurationService jsonConfigurationService;
@GET
@Operation(summary = "Retrieve passport configuration", description = "Retrieve passport configuration")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = PassportConfig.class)), description = Constants.RESULT_SUCCESS),
@ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response retrievePassportConfiguration() {
try {
log(logger, "Retrieving oxtrust configuration");
AppConfiguration oxTrustappConfiguration = jsonConfigurationService.getOxTrustappConfiguration();
PassportConfig passportConfig = new PassportConfig();
passportConfig.setPassportUmaClientId(oxTrustappConfiguration.getPassportUmaClientId());
passportConfig.setPassportUmaClientKeyId(oxTrustappConfiguration.getPassportUmaClientKeyId());
passportConfig.setPassportUmaClientKeyStoreFile(oxTrustappConfiguration.getPassportUmaClientKeyStoreFile());
passportConfig.setPassportUmaClientKeyStorePassword(
oxTrustappConfiguration.getPassportUmaClientKeyStorePassword());
passportConfig.setPassportUmaResourceId(oxTrustappConfiguration.getPassportUmaResourceId());
passportConfig.setPassportUmaScope(oxTrustappConfiguration.getPassportUmaScope());
return Response.ok(passportConfig).build();
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
@PUT
@Operation(summary = "Update passport configuration", description = "Update passport configuration")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = PassportConfig.class)), description = Constants.RESULT_SUCCESS),
@ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updatePassportConfiguration(PassportConfig passportConfig) {
try {
log(logger, "Processing passport configuration update");
Preconditions.checkNotNull(passportConfig, "Attempt to update null");
AppConfiguration appConfiguration = jsonConfigurationService.getOxTrustappConfiguration();
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaClientId())) {
appConfiguration.setPassportUmaClientId(passportConfig.getPassportUmaClientId());
}
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaClientKeyId())) {
appConfiguration.setPassportUmaClientKeyId(passportConfig.getPassportUmaClientKeyId());
}
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaClientKeyStoreFile())) {
appConfiguration.setPassportUmaClientKeyStoreFile(passportConfig.getPassportUmaClientKeyStoreFile());
}
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaClientKeyStorePassword())) {
appConfiguration
.setPassportUmaClientKeyStorePassword(passportConfig.getPassportUmaClientKeyStorePassword());
}
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaResourceId())) {
appConfiguration.setPassportUmaResourceId(passportConfig.getPassportUmaResourceId());
}
if (!Strings.isNullOrEmpty(passportConfig.getPassportUmaScope())) {
appConfiguration.setPassportUmaScope(passportConfig.getPassportUmaScope());
}
jsonConfigurationService.saveOxTrustappConfiguration(appConfiguration);
return Response.ok(Constants.RESULT_SUCCESS).build();
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
}