Commit e0f41ab6 authored by bertl4398's avatar bertl4398

Merge pull request #3 from indigo-dc/cleanup

fixes + code style
parents c80f809f 7ea7a0f4
Pipeline #1977 skipped
......@@ -17,11 +17,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
......@@ -51,19 +51,23 @@ public class RestServiceController {
* @param response the HttpServletResponse
* @return a JSON serialized list of SCIM users containing the modifications done
*/
@RequestMapping(path = "/link", method = RequestMethod.POST)
public List<ScimUser> linkUsers(@RequestHeader("Authorization") String basicAuthorization,
@RequestMapping(path = "/link", method = RequestMethod.POST, consumes = "application/scim+json",
produces = "application/scim+json")
public ResponseEntity<?> linkUsers(@RequestHeader("Authorization") String basicAuthorization,
@RequestBody List<ScimUser> scimUsers, HttpServletResponse response) {
verifyAuthorization(basicAuthorization);
if (!verifyAuthorization(basicAuthorization)) {
return new ResponseEntity<String>("REST Service Unauthorized", HttpStatus.UNAUTHORIZED);
}
log.debug("Request body {}", scimUsers);
List<ScimUser> modifiedUsers = identityHarmonizer.harmonizeIdentities(scimUsers);
if (!modifiedUsers.isEmpty()) {
return modifiedUsers;
return new ResponseEntity<List<ScimUser>>(modifiedUsers, HttpStatus.OK);
}
throw new ConflictException();
return new ResponseEntity<String>("Conflicting information", HttpStatus.CONFLICT);
}
/**
......@@ -74,64 +78,33 @@ public class RestServiceController {
* @param response the HttpServletResponse
* @return A JSON serialized list of SCIM users containing the local user information.
*/
@RequestMapping(path = "/unlink", method = RequestMethod.POST)
public List<ScimUser> unlinkUsers(@RequestHeader("Authorization") String basicAuthorization,
@RequestMapping(path = "/unlink", method = RequestMethod.POST, consumes = "application/scim+json",
produces = "application/scim+json")
public ResponseEntity<?> unlinkUsers(@RequestHeader("Authorization") String basicAuthorization,
@RequestBody List<ScimUser> scimUsers, HttpServletResponse response) {
verifyAuthorization(basicAuthorization);
if (!verifyAuthorization(basicAuthorization)) {
return new ResponseEntity<String>("REST Service Unauthorized", HttpStatus.UNAUTHORIZED);
}
log.debug("Request body {}", scimUsers);
List<ScimUser> modifiedUsers = identityHarmonizer.unlinkUsers(scimUsers);
if (!modifiedUsers.isEmpty()) {
return modifiedUsers;
return new ResponseEntity<List<ScimUser>>(modifiedUsers, HttpStatus.OK);
}
throw new ConflictException();
return new ResponseEntity<String>("Conflicting information", HttpStatus.CONFLICT);
}
private void verifyAuthorization(String basicAuthorization) {
private boolean verifyAuthorization(String basicAuthorization) {
String encodedCredentials = basicAuthorization.split(" ")[1];
String[] credentials = new String(Base64.decodeBase64(encodedCredentials)).split(":");
if (!credentials[0].equals(restUser) || !credentials[1].equals(restPassword)) {
log.error("Wrong credentials {} {}", credentials[0], credentials[1]);
throw new UnauthorizedException();
}
}
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
public class UnauthorizedException extends RuntimeException {
private static final long serialVersionUID = 6396195910009296687L;
public UnauthorizedException() {
super();
}
public UnauthorizedException(String message) {
super(message);
}
public UnauthorizedException(Throwable ex) {
super(ex);
}
}
@ResponseStatus(value = HttpStatus.CONFLICT)
public class ConflictException extends RuntimeException {
private static final long serialVersionUID = -9070725142810603956L;
public ConflictException() {
super();
}
public ConflictException(String message) {
super(message);
}
public ConflictException(Throwable ex) {
super(ex);
if (credentials[0].equals(restUser) && credentials[1].equals(restPassword)) {
return true;
}
log.error("Wrong credentials {} {}", credentials[0], credentials[1]);
return false;
}
}
......@@ -10,11 +10,13 @@
package edu.kit.scc.scim;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScimGroup {
@JsonProperty(value = "$ref")
private String ref;
private String value;
private String $ref;
private String display;
public String getValue() {
......@@ -25,12 +27,12 @@ public class ScimGroup {
this.value = value;
}
public String get$ref() {
return $ref;
public String getRef() {
return ref;
}
public void set$ref(String $ref) {
this.$ref = $ref;
public void setRef(String ref) {
this.ref = ref;
}
public String getDisplay() {
......@@ -44,7 +46,7 @@ public class ScimGroup {
@Override
public String toString() {
return "ScimGroup [" + (value != null ? "value=" + value + ", " : "")
+ ($ref != null ? "$ref=" + $ref + ", " : "")
+ (display != null ? "display=" + display : "") + "]";
+ (ref != null ? "$ref=" + ref + ", " : "") + (display != null ? "display=" + display : "")
+ "]";
}
}
......@@ -295,7 +295,7 @@ public class ScimUser {
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class x509Certificate {
public static class X509Certificate {
private String value;
public String getValue() {
......
......@@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScimUser1_0 {
public class ScimUser10 {
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Name {
......
......@@ -47,6 +47,7 @@
"groups": [
{
"display": "umbrella_umbrella",
"$ref": "https://example.com/v2/Groups/e9e30dba-f08f-4109-8486-d5c6a331660",
"value": "500084"
}
],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment