mirror of
https://github.com/valitydev/wachter.git
synced 2024-11-06 00:35:24 +00:00
Fix roles (#20)
This commit is contained in:
parent
6856872154
commit
d3d68ad688
@ -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) {
|
||||
|
@ -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() {
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user