This commit is contained in:
Michele Artini 2022-09-21 10:25:48 +02:00
parent e0143ab27e
commit 20f7a1da77
4 changed files with 30 additions and 15 deletions

View File

@ -21,6 +21,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.security.web.access.AccessDeniedHandler;
import eu.dnetlib.organizations.controller.UserInfo; import eu.dnetlib.organizations.controller.UserInfo;
import eu.dnetlib.organizations.controller.UserRole;
import eu.dnetlib.organizations.utils.OpenOrgsConstants; import eu.dnetlib.organizations.utils.OpenOrgsConstants;
@Profile("dev") @Profile("dev")
@ -92,7 +93,7 @@ public class MockSecurityConfig extends WebSecurityConfigurerAdapter {
.usersByUsernameQuery("select ?, '{MD5}" + DigestUtils.md5Hex(DEFAULT_PASSWORD) + "', true") .usersByUsernameQuery("select ?, '{MD5}" + DigestUtils.md5Hex(DEFAULT_PASSWORD) + "', true")
.authoritiesByUsernameQuery("with const as (SELECT ? as email) " .authoritiesByUsernameQuery("with const as (SELECT ? as email) "
+ "select c.email, 'ROLE_" + OpenOrgsConstants.OPENORGS_ROLE_PREFIX + "'||coalesce(u.role, '" + "select c.email, 'ROLE_" + OpenOrgsConstants.OPENORGS_ROLE_PREFIX + "'||coalesce(u.role, '"
+ OpenOrgsConstants.NOT_AUTORIZED_ROLE + UserRole.NOT_AUTHORIZED
+ "') from const c left outer join users u on (u.email = c.email)"); + "') from const c left outer join users u on (u.email = c.email)");
} }

View File

@ -65,6 +65,11 @@ public class HomeController extends AbstractDnetController {
return authentication != null ? UserInfo.getEmail(authentication) : null; return authentication != null ? UserInfo.getEmail(authentication) : null;
} }
@ModelAttribute("role")
public UserRole getUserRole(final Authentication authentication) {
return authentication != null ? UserInfo.findRole(authentication) : null;
}
@ModelAttribute("fullname") @ModelAttribute("fullname")
public String getUserFullname(final Authentication authentication) { public String getUserFullname(final Authentication authentication) {
return authentication != null ? UserInfo.getFullname(authentication) : null; return authentication != null ? UserInfo.getFullname(authentication) : null;

View File

@ -42,6 +42,7 @@ public class UserInfo {
} }
public static UserRole findRole(final Authentication authentication) { public static UserRole findRole(final Authentication authentication) {
return authentication.getAuthorities() return authentication.getAuthorities()
.stream() .stream()
.map(GrantedAuthority::getAuthority) .map(GrantedAuthority::getAuthority)

View File

@ -50,23 +50,31 @@
</p> </p>
<form class="small"> <form class="small">
<div class="form-group"> <div class="form-group row">
<label>Fullname</label> <label class="col-sm-2 col-form-label">Fullname</label>
<input type="text" readonly class="form-control-plaintext" th:value="${fullname}" /> <div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" th:value="${fullname}" />
</div>
</div> </div>
<div class="form-group"> <div class="form-group row">
<label>Organization</label> <label class="col-sm-2 col-form-label">Organization</label>
<input type="text" readonly class="form-control-plaintext" th:value="${organization}" /> <div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" th:value="${organization}" />
</div>
</div> </div>
<div class="form-group"> <div class="form-group row">
<label>Reference person</label> <label class="col-sm-2 col-form-label">Reference person</label>
<input type="text" class="form-control" ng-model="referencePerson"> <div class="col-sm-10">
<small class="form-text text-muted">Please indicate your reference person (if available)</small> <input type="text" class="form-control" ng-model="referencePerson">
<small class="form-text text-muted">Please indicate your reference person (if available)</small>
</div>
</div> </div>
<div class="form-group"> <div class="form-group row">
<label>Request message</label> <label class="col-sm-2 col-form-label">Request message</label>
<textarea class="form-control" ng-model="requestMessage" cols="4"></textarea> <div class="col-sm-10">
<small class="form-text text-muted">Specify the reasons for your request</small> <textarea class="form-control" ng-model="requestMessage" cols="4"></textarea>
<small class="form-text text-muted">Specify the reason of your request</small>
</div>
</div> </div>
<div class="card" style="margin-top: 25px"> <div class="card" style="margin-top: 25px">