@ -7,11 +7,20 @@ import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.security.cas.CasUserIdentity;
|
||||
import com.plannaplan.security.cas.CasValidationExcepiton;
|
||||
import com.plannaplan.security.cas.CasValidator;
|
||||
import com.plannaplan.security.cas.CustomUAMCasValidator;
|
||||
import com.plannaplan.security.cas.DefaultUAMCasValidator;
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -33,9 +42,19 @@ import io.swagger.annotations.ApiParam;
|
||||
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
|
||||
public class ConfigController {
|
||||
|
||||
@Value("${plannaplan.frontendUrl}")
|
||||
private String serviceUrl;
|
||||
|
||||
@Value("${plannaplan.dev}")
|
||||
private boolean isDev;
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService contrl;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
@PostMapping(path = "/config", consumes = { "multipart/form-data" })
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||
@ -64,8 +83,25 @@ public class ConfigController {
|
||||
}
|
||||
|
||||
public ResponseEntity<String> initAdmin(@RequestParam("ticket") String ticket){
|
||||
if (this.userService.adminExists()){
|
||||
return new ResponseEntity<>("Admin had been already created.", HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
return null;
|
||||
final CasValidator validator = isDev ? new DefaultUAMCasValidator(serviceUrl, ticket)
|
||||
: new CustomUAMCasValidator(serviceUrl, ticket);
|
||||
|
||||
try {
|
||||
final CasUserIdentity casUserIdentity = validator.validate();
|
||||
final String usosId = casUserIdentity.getUsosId();
|
||||
final String authority = casUserIdentity.getEmail();
|
||||
this.userService.save(new User(null, null, authority, usosId, UserRoles.ADMIN));
|
||||
|
||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||
} catch (CasValidationExcepiton e) {
|
||||
return new ResponseEntity<>("CAS validation failed", HttpStatus.UNAUTHORIZED);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>("Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -62,7 +62,6 @@ public class TokenController {
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/token/refresh")
|
||||
|
Reference in New Issue
Block a user