use of org.gluu.radius.model.ServerConfiguration in project oxTrust by GluuFederation.
the class GluuRadiusConfigWebResource method updateServerConfiguration.
@PUT
@Operation(summary = "Get Radius Server Configuration", description = "Update Radius Server Configuration")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ServerConfiguration.class)), description = "Success"), @ApiResponse(responseCode = "403", description = "Gluu Radius is not installed"), @ApiResponse(responseCode = "404", description = "Gluu Radius configuration not found"), @ApiResponse(responseCode = "500", description = "Internal server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateServerConfiguration(ServerConfiguration newConfig) {
log(logger, "Update radius server configuration");
try {
if (ProductInstallationChecker.isGluuRadiusInstalled() == false)
return Response.status(Response.Status.FORBIDDEN).build();
Objects.requireNonNull(newConfig);
ServerConfiguration oldConfig = gluuRadiusConfigService.getServerConfiguration();
if (oldConfig == null)
return Response.status(Response.Status.NOT_FOUND).build();
if (newConfig.getListenInterface() == null)
newConfig.setListenInterface(oldConfig.getListenInterface());
if (newConfig.getAuthPort() == null)
newConfig.setAuthPort(oldConfig.getAuthPort());
if (newConfig.getAcctPort() == null)
newConfig.setAcctPort(oldConfig.getAcctPort());
if (newConfig.getOpenidBaseUrl() == null)
newConfig.setOpenidBaseUrl(oldConfig.getOpenidBaseUrl());
if (newConfig.getOpenidUsername() == null) {
newConfig.setOpenidUsername(oldConfig.getOpenidUsername());
newConfig.setOpenidPassword(oldConfig.getOpenidPassword());
} else {
OxAuthClient client = clientService.getClientByInum(newConfig.getOpenidUsername());
if (client == null) {
newConfig.setOpenidUsername(oldConfig.getOpenidUsername());
newConfig.setOpenidPassword(oldConfig.getOpenidPassword());
} else {
newConfig.setOpenidPassword(client.getEncodedClientSecret());
}
}
String acrValue = newConfig.getAcrValue();
if (acrValue == null || (acrValue != null && !isValidAcrValue(acrValue)))
newConfig.setAcrValue(oldConfig.getAcrValue());
List<String> scopes = newConfig.getScopes();
if (scopes == null || (scopes != null && scopes.isEmpty()))
newConfig.setScopes(oldConfig.getScopes());
else {
List<String> newscopes = scopes;
for (String scope : scopes) {
// if just one scope is invalid , use the old ones (safe)
if (!isValidScope(scope)) {
newscopes = oldConfig.getScopes();
break;
}
}
newConfig.setScopes(newscopes);
}
if (newConfig.getAuthenticationTimeout() == null || newConfig.getAuthenticationTimeout() <= 0)
newConfig.setAuthenticationTimeout(oldConfig.getAuthenticationTimeout());
gluuRadiusConfigService.updateServerConfiguration(newConfig);
return Response.ok(gluuRadiusConfigService.getServerConfiguration()).build();
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Aggregations