[Trunk | Authorization Library]: AuthorizationService.java: Add anonymous user roles and add method "getAaiId()" (currently we get aaiId from password field - to be changed).
This commit is contained in:
parent
ab4b0a525d
commit
02c53df43a
|
@ -1,8 +1,10 @@
|
|||
package eu.dnetlib.uoaauthorizationlibrary.security;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -10,10 +12,13 @@ import java.util.List;
|
|||
|
||||
@Component(value = "AuthorizationService")
|
||||
public class AuthorizationService {
|
||||
private final Logger log = Logger.getLogger(this.getClass());
|
||||
|
||||
|
||||
public final String SUPER_ADMIN = "SUPER_ADMINISTRATOR";
|
||||
public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
|
||||
public final String USER_ADMIN = "USER_MANAGER";
|
||||
public final String ANONYMOUS_USER = "ROLE_ANONYMOUS";
|
||||
|
||||
private String mapType(String type) {
|
||||
if(type.equals("organization")) {
|
||||
|
@ -52,14 +57,26 @@ public class AuthorizationService {
|
|||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
List<String> roles = new ArrayList<>();
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if(authentication != null) {
|
||||
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
|
||||
if(authorities != null) {
|
||||
authorities.forEach((authority) -> roles.add(authority.getAuthority()));
|
||||
List<String> roles = new ArrayList<>();
|
||||
authorities.forEach((authority) -> {
|
||||
roles.add(authority.getAuthority());
|
||||
});
|
||||
return roles;
|
||||
}
|
||||
}
|
||||
return roles;
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAaiId() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if(authentication != null) {
|
||||
User user = (User) authentication.getPrincipal();
|
||||
return user.getPassword();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue