Fix roles (#20)

This commit is contained in:
malkoas 2022-10-12 18:34:07 +03:00 committed by GitHub
parent 6856872154
commit d3d68ad688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -24,20 +24,21 @@ public class RoleAccessService {
accessData.getServiceName(),
accessData.getMethodName(),
accessData.getUserEmail());
break;
return;
} else if (role.equalsIgnoreCase(getServiceName(accessData))) {
log.info("Rights allowed in all service {} for user {}",
accessData.getServiceName(),
accessData.getUserEmail());
break;
} else {
throw new AuthorizationException(
String.format("User %s don't have access to %s in service %s",
accessData.getUserEmail(),
accessData.getMethodName(),
accessData.getServiceName()));
return;
}
}
throw new AuthorizationException(
String.format("User %s don't have access to %s in service %s",
accessData.getUserEmail(),
accessData.getMethodName(),
accessData.getServiceName()));
}
private String getServiceName(AccessData accessData) {

View File

@ -30,7 +30,8 @@ public abstract class AbstractKeycloakOpenIdAsWiremockConfig {
}
protected String generateSimpleJwtWithRoles() {
return keycloakOpenIdStub.generateJwt("messages", "messages:methodName", "unknown");
return keycloakOpenIdStub.generateJwt("Deanonimus", "unknown", "Domain", "messages:methodName");
}
protected String generateSimpleJwtWithoutRoles() {

View File

@ -62,7 +62,7 @@ class WachterControllerTest extends AbstractKeycloakOpenIdAsWiremockConfig {
when(httpClient.execute(any())).thenReturn(httpResponse);
mvc.perform(post("/wachter")
.header("Authorization", "Bearer " + generateSimpleJwtWithRoles())
.header("Service", "messages")
.header("Service", "Domain")
.header("X-Request-ID", randomUUID())
.header("X-Request-Deadline", Instant.now().plus(1, ChronoUnit.DAYS).toString())
.content(TMessageUtil.createTMessage(protocolFactory)))