Commit bd14ce93 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

700: Migrate from old SP libraries to consolidated version

Task-Url: https://minfba.de.dariah.eu/mantisbt/view.php?id=700
parent ae1748c8
......@@ -35,6 +35,15 @@
<version>1.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<distributionManagement>
......
package eu.dariah.de.dariahsp.model;
import org.springframework.security.core.GrantedAuthority;
public interface Role extends GrantedAuthority {
public int getId();
public int getLevel();
public String getDescription();
}
package eu.dariah.de.dariahsp.model;
import java.util.Collection;
import org.springframework.security.core.userdetails.UserDetails;
public class SimpleUserDetails implements UserDetails, StagedUserDetails {
private static final long serialVersionUID = -1504226378983075730L;
private Collection<Role> authorities;
protected String id;
private String endpointId;
private String endpointName;
private String username;
private boolean expired;
private String language;
private boolean hasAllAttributes;
public SimpleUserDetails() {}
public SimpleUserDetails(User user, Collection<Role> authorities) {
this.id = user.getId();
this.username = user.getNameId();
this.expired = user.isExpired();
this.endpointId = user.getEndpointId();
this.language = user.getLanguage();
this.authorities = authorities;
this.endpointName = user.getEndpointName();
this.hasAllAttributes = false;
}
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getEndpointId() { return endpointId; }
public void setEndpointId(String endpointId) { this.endpointId = endpointId; }
public String getEndpointName() { return endpointName; }
public void setEndpointName(String endpointName) { this.endpointName = endpointName; }
public boolean isExpired() { return expired; }
public void setExpired(boolean expired) { this.expired = expired; }
public String getLanguage() { return language; }
public void setLanguage(String language) { this.language = language; }
public boolean isHasAllAttributes() { return hasAllAttributes; }
public void setHasAllAttributes(boolean hasAllAttributes) { this.hasAllAttributes = hasAllAttributes; }
public void setAuthorities(Collection<Role> authorities) { this.authorities = authorities; }
public void setUsername(String username) { this.username = username; }
public String getUsername() { return username; }
public String getPassword() { return ""; }
public Collection<Role> getAuthorities() { return authorities; }
public boolean isAccountNonExpired() { return !expired; }
public boolean isAccountNonLocked() { return !expired; }
public boolean isCredentialsNonExpired() { return !expired; }
public boolean isEnabled() { return !expired; }
public int getMaxAuthorityLevel() {
int level = 0;
if (getAuthorities() != null) {
for (Role auth : getAuthorities()) {
if (auth instanceof Role && ((Role) auth).getLevel() > level) {
level = ((Role) auth).getLevel();
}
}
}
return level;
}
public boolean isAuthorized(Role compRole) {
return getMaxAuthorityLevel() >= compRole.getLevel();
}
}
\ No newline at end of file
package eu.dariah.de.dariahsp.model;
public interface StagedUserDetails {
public int getMaxAuthorityLevel();
public boolean isAuthorized(Role compRole);
}
package eu.dariah.de.dariahsp.model;
public interface User {
public String getId();
public String getNameId();
public boolean isExpired();
public String getEndpointId();
public String getEndpointName();
public String getLanguage();
}
......@@ -8,8 +8,9 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import de.dariah.aai.javasp.base.SimpleUserDetails;
import eu.dariah.de.dariahsp.web.model.AuthPojo;
import eu.dariah.de.dariahsp.model.SimpleUserDetails;
import eu.dariah.de.dariahsp.model.web.AuthPojo;
public class AuthInfoHelper {
......
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