/**
- * PUT /polices/device : Update an device policies.
+ * PUT /policies/device : Update an device policies.
*
* @param uiPolicesUpdate list the ui policies to update device policies
* @return the ResponseEntity with status 200 (OK)
@ApiResponse(code = 400, message = "Bad Request. The reason is contained in the tags “errorKey”, “message”, “title”"),
@ApiResponse(code = 500, message = "Internal server error. The user has to repeat action.")
})
- @RequestMapping(value ="/polices/device", method = RequestMethod.PUT)
+ @RequestMapping(value ="/policies/device", method = RequestMethod.PUT)
public ResponseEntity<List<UIPolicies.UIPolicy>> updateDevicePolicies(
@ApiParam(value = "device id", required = true) @RequestParam(value = "id") Long id, @Valid @RequestBody UIPoliciesUpdate uiPolicesUpdate);
/**
- * GET /polices : get all the polices.
+ * GET /policies : get all the polices.
*
* @return the ResponseEntity with status 200 (OK) and the list of polices
*/
@ApiResponse(code = 400, message = "Bad Request. The reason is contained in the tags “errorKey”, “message”, “title”"),
@ApiResponse(code = 500, message = "Internal server error. The user has to repeat action.")
})
- @RequestMapping(value ="/polices", method = RequestMethod.GET)
+ @RequestMapping(value ="/policies", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<List<UIPolicies>> getAllPolices();
/**
- * GET /polices/device?id : get the device polices.
+ * GET /policies/device?id : get the device polices.
*
* @param id the id of the device
* @return the ResponseEntity with status 200 (OK) and the list of polices
@ApiResponse(code = 400, message = "Bad Request. The reason is contained in the tags “errorKey”, “message”, “title”"),
@ApiResponse(code = 500, message = "Internal server error. The user has to repeat action.")
})
- @RequestMapping(value ="/polices/device", method = RequestMethod.GET)
+ @RequestMapping(value ="/policies/device", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<List<UIPolicies>> getDevicePolices(
@ApiParam(value = "device id", required = true) @RequestParam(value = "id") Long id);
*/
package com.samsung.samserver.web.rest.service.device;
-import com.samsung.samserver.web.rest.service.vm.DInfo;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.samsung.samserver.web.rest.service.vm.*;
import org.slf4j.*;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import com.samsung.samserver.web.rest.errors.DeviceServiceError;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
+import java.io.IOException;
import java.time.Instant;
-import java.util.Optional;
+import java.util.*;
/**
* REST service implementation for register device.
private final DeviceTypeService deviceTypeService;
private final DeviceService deviceService;
+ @Autowired
+ private PolicyTypeService policyTypeService;
+
+ @Autowired
+ private PolicesUpdateService policesUpdateService;
+
public RegisterDeviceRestService(DeviceTypeService deviceTypeService, DeviceService deviceService) {
this.deviceTypeService = deviceTypeService;
this.deviceService = deviceService;
}
+ private List<UIPolicies.UIPolicy> getUIPolicyList(){
+ Map<String, PolicyType> allPolicies = policyTypeService.findAllAsMap();
+ List<UIPolicies.UIPolicy> uiPolicyList = new ArrayList<>();
+ ObjectMapper mapper = new ObjectMapper();
+ for (Map.Entry<String ,PolicyType> entry : allPolicies.entrySet()) {
+ PolicyType policyType = entry.getValue();
+ try {
+ UIPolicies.UIPolicy uiPolicy = mapper.readValue(policyType.getDefval(), new TypeReference<UIPolicies.UIPolicy>(){});
+ uiPolicyList.add(uiPolicy);
+ } catch (IOException e) {
+ log.error("register device: prepare device policies state request: message: {} stacktrace: {}", e.getMessage(), e.getStackTrace());
+ }
+ }
+ return uiPolicyList;
+ }
+
public ResponseEntity<String> registerDevice(@Valid @RequestBody DInfo dInfo, HttpServletRequest request) {
log.debug("request to register device : {}", dInfo);
.osver(dInfo.getOsver())
.ipaddr(request.getRemoteAddr())
.dtype(dt.get()));
+
+ policesUpdateService.prepareStateRequest(result, getUIPolicyList());
+
return ResponseEntity.ok()
.headers(new HttpHeaders())
.body(result.getDuid());
-id;name;descr;category;opt;defval;supported;mapping
-1;bluetooth;;bluetooth;;{""type"":""flag"",""name"":""bluetooth"",""value"":1,""uiname"":""Bluetooth"",""descr":""Defines if the use of the bluetooth is allowed"",""state":1};1;integer
-2;bluetooth_tethering;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_tethering"",""value"":1,""uiname"":""Bluetooth tethering"",""descr":""Defines if the use of the bluetooth tethering is allowed"",""state":1};1;integer
-3;bluetooth_desktop_connectivity;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_desktop_connectivity"",""value"":1,""uiname"":""Bluetooth desktop connectivity"",""descr":""Defines if the use of the bluetooth desktop connectivity is allowed"",""state":1};1;integer
-4;bluetooth_pairing;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_pairing"",""value"":1,""uiname"":""Bluetooth pairing"",""descr":""Defines if the use of the bluetooth pairing is allowed"",""state":1};1;integer
-5;browser;;common;;{""type"":""flag"",""name"":""browser"",""value"":1,""uiname"":""Browser"",""descr":""Defines if the use of the browser is allowed"",""state":1};1;integer
-6;camera;;common;;{""type"":""flag"",""name"":""camera"",""value"":1,""uiname"":""Camera"",""descr":""Defines if the use of the camera is allowed"",""state":1};1;integer
-7;clipboard;;common;;{""type"":""flag"",""name"":""clipboard"",""value"":1,""uiname"":""Clipboard"",""descr":""Defines if the use of the clipboard is allowed"",""state":1};1;integer
-8;external_storage;;common;;{""type"":""flag"",""name"":""external_storage"",""value"":1,""uiname"":""External storage"",""descr":""Defines if the use of the external storage is allowed"",""state":1};1;integer
-9;location;;common;;{""type"":""flag"",""name"":""location"",""value"":1,""uiname"":""Geolocation"",""descr":""Defines if the use of the geolocation is allowed"",""state":1};1;integer
-10;messaging;;common;;{""type"":""select"",""name"":""messaging"",""items"":[{""key"":""sim1"",""value"":""1""},{""key"":""sim2"",""value"":""0""}],""uiname"":""Messaging"",""descr":""Defines if the use of the messaging is allowed"",""state":1};1;indexed
-11;microphone;;common;;{""type"":""flag"",""name"":""microphone"",""value"":1,""uiname"":""Microphone"",""descr":""Defines if the use of the microphone is allowed"",""state":1};1;integer
-12;popimap_email;;common;;{""type"":""flag"",""name"":""popimap_email"",""value"":1,""uiname"":""POP IMAP eMail"",""descr":""Defines if the use of the POP or IMAP email is allowed"",""state":1};1;integer
-13;usb_tethering;;common;;{""type"":""flag"",""name"":""usb_tethering"",""value"":1,""uiname"":""USB tethering"",""descr":""Defines if the use of the USB tethering is allowed"",""state":1};1;integer
-14;password_history;;password;;{""type"":""input-number"",""name"":""password_history"",""value"":100,""uiname"":""History"",""descr":""Defines if the password history is stated and if rules are defined"",""state":1};1;integer
-15;password_minimum_length;;password;;{""type"":""input-number"",""name"":""password_minimum_length"",""value"":6,""uiname"":""Minimum length"",""descr":""Defines the minimum password length"",""state":1};1;integer
-16;password_minimum_complexity;;password;;{""type"":""input-number"",""name"":""password_minimum_complexity"",""value"":2,""uiname"":""Minimum complexity"",""descr":""Defines the minimum password complexity"",""state":1};1;integer
-17;password_inactivity_timeout;;password;;{""type"":""input-number"",""name"":""password_inactivity_timeout"",""value"":30,""uiname"":""Inactivity timeout"",""descr":""Defines the inactivity time to lock"",""state":1};1;integer
-18;password_expired;;password;;{""type"":""input-number"",""name"":""password_expired"",""value"":90,""uiname"":""Expiration"",""descr":""Defines when the password will expire: 0 - never; positive number - number of days to expire"",""state":1};1;integer
-19;password_maximum_failure_count;;password;;{""type"":""input-number"",""name"":""password_maximum_failure_count"",""value"":10,""uiname"":""Maximum failed attempts"",""descr":""Defines how many times the user are allowed to type the wrong password before the device is blocked"",""state":1};1;integer
-20;password_numeric_sequences_length;;password;;{""type"":""input-number"",""name"":""password_numeric_sequences_length"",""value"":10,""uiname"":""Numeric sequences length"",""descr":""Defines the numeric sequences length"",""state":1};1;integer
-21;password_maximum_character_occurrences;;password;;{""type"":""input-number"",""name"":""password_maximum_character_occurrences"",""value"":10,""uiname"":""Maximum character occurrences"",""descr":""Defines the maximum character occurrences"",""state":1};1;integer
-22;password_quality;;password;;{""type"":""multiselect"",""name"":""password_quality"",""items"":[{""key"":""UNSPECIFIED"",""value"": 0},{""key"":""SIMPLE_PASSWORD"",""value"":1},{""key"":""SOMETHING"",""value"":1},{""key"":""ALPHABETIC"",""value"":1},{""key"":""ALPHANUMERIC"",""value"":0}],""uiname"":""Quality"",""descr":""Defines the password quality"",""state":1};1;integer
-23;wifi;;wifi;;{""type"":""flag"",""name"":""wifi"",""value"":1,""uiname"":""Wi-Fi"",""descr":""Defines if the use of the Wi-Fi is allowed"",""state":1};1;integer
-24;wifi_tethering;;wifi;;{""type"":""flag"",""name"":""wifi_tethering"",""value"":1,""uiname"":""Wi-Fi tethering"",""descr":""Defines if the use of the Wi-Fi tethering is allowed"",""state":1};1;integer
-25;wifi_profile_change;;wifi;;{""type"":""flag"",""name"":""wifi_profile_change"",""value"":1,""uiname"":""Wi-Fi profile change"",""descr":""Defines if the change of the Wi-Fi profile is allowed"",""state":1};1;integer
\ No newline at end of file
+id;name;descr;category;opt;defval;supported;mapping;uitype
+1;bluetooth;;bluetooth;;{""type"":""flag"",""name"":""bluetooth"",""value"":1,""uiname"":""Bluetooth"",""descr":""Defines if the use of the bluetooth is allowed"",""state":1};1;integer;flag
+2;bluetooth_tethering;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_tethering"",""value"":1,""uiname"":""Bluetooth tethering"",""descr":""Defines if the use of the bluetooth tethering is allowed"",""state":1};1;integer;flag
+3;bluetooth_desktop_connectivity;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_desktop_connectivity"",""value"":1,""uiname"":""Bluetooth desktop connectivity"",""descr":""Defines if the use of the bluetooth desktop connectivity is allowed"",""state":1};1;integer;flag
+4;bluetooth_pairing;;bluetooth;;{""type"":""flag"",""name"":""bluetooth_pairing"",""value"":1,""uiname"":""Bluetooth pairing"",""descr":""Defines if the use of the bluetooth pairing is allowed"",""state":1};1;integer;flag
+5;browser;;common;;{""type"":""flag"",""name"":""browser"",""value"":1,""uiname"":""Browser"",""descr":""Defines if the use of the browser is allowed"",""state":1};1;integer;flag
+6;camera;;common;;{""type"":""flag"",""name"":""camera"",""value"":1,""uiname"":""Camera"",""descr":""Defines if the use of the camera is allowed"",""state":1};1;integer;flag
+7;clipboard;;common;;{""type"":""flag"",""name"":""clipboard"",""value"":1,""uiname"":""Clipboard"",""descr":""Defines if the use of the clipboard is allowed"",""state":1};1;integer;flag
+8;external_storage;;common;;{""type"":""flag"",""name"":""external_storage"",""value"":1,""uiname"":""External storage"",""descr":""Defines if the use of the external storage is allowed"",""state":1};1;integer;flag
+9;location;;common;;{""type"":""flag"",""name"":""location"",""value"":1,""uiname"":""Geolocation"",""descr":""Defines if the use of the geolocation is allowed"",""state":1};1;integer;flag
+10;messaging;;common;;{""type"":""select"",""name"":""messaging"",""items"":[{""key"":""sim1"",""value"":""1""},{""key"":""sim2"",""value"":""0""}],""uiname"":""Messaging"",""descr":""Defines if the use of the messaging is allowed"",""state":1};1;indexed;select
+11;microphone;;common;;{""type"":""flag"",""name"":""microphone"",""value"":1,""uiname"":""Microphone"",""descr":""Defines if the use of the microphone is allowed"",""state":1};1;integer;flag
+12;popimap_email;;common;;{""type"":""flag"",""name"":""popimap_email"",""value"":1,""uiname"":""POP IMAP eMail"",""descr":""Defines if the use of the POP or IMAP email is allowed"",""state":1};1;integer;flag
+13;usb_tethering;;common;;{""type"":""flag"",""name"":""usb_tethering"",""value"":1,""uiname"":""USB tethering"",""descr":""Defines if the use of the USB tethering is allowed"",""state":1};1;integer;flag
+14;password_history;;password;;{""type"":""input-number"",""name"":""password_history"",""value"":100,""uiname"":""History"",""descr":""Defines if the password history is stated and if rules are defined"",""state":1};1;integer;input-number
+15;password_minimum_length;;password;;{""type"":""input-number"",""name"":""password_minimum_length"",""value"":6,""uiname"":""Minimum length"",""descr":""Defines the minimum password length"",""state":1};1;integer;input-number
+16;password_minimum_complexity;;password;;{""type"":""input-number"",""name"":""password_minimum_complexity"",""value"":2,""uiname"":""Minimum complexity"",""descr":""Defines the minimum password complexity"",""state":1};1;integer;input-number
+17;password_inactivity_timeout;;password;;{""type"":""input-number"",""name"":""password_inactivity_timeout"",""value"":30,""uiname"":""Inactivity timeout"",""descr":""Defines the inactivity time to lock"",""state":1};1;integer;input-number
+18;password_expired;;password;;{""type"":""input-number"",""name"":""password_expired"",""value"":90,""uiname"":""Expiration"",""descr":""Defines when the password will expire: 0 - never; positive number - number of days to expire"",""state":1};1;integer;input-number
+19;password_maximum_failure_count;;password;;{""type"":""input-number"",""name"":""password_maximum_failure_count"",""value"":10,""uiname"":""Maximum failed attempts"",""descr":""Defines how many times the user are allowed to type the wrong password before the device is blocked"",""state":1};1;integer;input-number
+20;password_numeric_sequences_length;;password;;{""type"":""input-number"",""name"":""password_numeric_sequences_length"",""value"":10,""uiname"":""Numeric sequences length"",""descr":""Defines the numeric sequences length"",""state":1};1;integer;input-number
+21;password_maximum_character_occurrences;;password;;{""type"":""input-number"",""name"":""password_maximum_character_occurrences"",""value"":10,""uiname"":""Maximum character occurrences"",""descr":""Defines the maximum character occurrences"",""state":1};1;integer;input-number
+22;password_quality;;password;;{""type"":""multiselect"",""name"":""password_quality"",""items"":[{""key"":""UNSPECIFIED"",""value"": 0},{""key"":""SIMPLE_PASSWORD"",""value"":1},{""key"":""SOMETHING"",""value"":1},{""key"":""ALPHABETIC"",""value"":1},{""key"":""ALPHANUMERIC"",""value"":0}],""uiname"":""Quality"",""descr":""Defines the password quality"",""state":1};1;integer;multiselect
+23;wifi;;wifi;;{""type"":""flag"",""name"":""wifi"",""value"":1,""uiname"":""Wi-Fi"",""descr":""Defines if the use of the Wi-Fi is allowed"",""state":1};1;integer;flag
+24;wifi_tethering;;wifi;;{""type"":""flag"",""name"":""wifi_tethering"",""value"":1,""uiname"":""Wi-Fi tethering"",""descr":""Defines if the use of the Wi-Fi tethering is allowed"",""state":1};1;integer;flag
+25;wifi_profile_change;;wifi;;{""type"":""flag"",""name"":""wifi_profile_change"",""value"":1,""uiname"":""Wi-Fi profile change"",""descr":""Defines if the change of the Wi-Fi profile is allowed"",""state":1};1;integer;flag
\ No newline at end of file