-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../java/edu/internet2/tier/shibboleth/admin/ui/security/repository/AdminRoleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.security.repository; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminRole; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Spring Data repository to manage entities of type {@link AdminRole}. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public interface AdminRoleRepository { | ||
|
||
Optional<AdminRole> findByName(final String name); | ||
} |
14 changes: 14 additions & 0 deletions
14
.../java/edu/internet2/tier/shibboleth/admin/ui/security/repository/AdminUserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.security.repository; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminUser; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* Spring Data repository to manage entities of type {@link AdminUser}. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public interface AdminUserRepository extends JpaRepository<AdminUser, Long> { | ||
|
||
AdminUser findByUsername(String username); | ||
} |
40 changes: 40 additions & 0 deletions
40
...java/edu/internet2/tier/shibboleth/admin/ui/security/springsecurity/AdminUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.security.springsecurity; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminRole; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.model.AdminUser; | ||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.AdminUserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Spring Security {@link UserDetailsService} implementation for local administration of admin users ins the system. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
@RequiredArgsConstructor | ||
public class AdminUserService implements UserDetailsService { | ||
|
||
private final AdminUserRepository adminUserRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
AdminUser user = adminUserRepository.findByUsername(username); | ||
|
||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>(); | ||
for (AdminRole role : user.getRoles()) { | ||
grantedAuthorities.add(new SimpleGrantedAuthority(role.getName())); | ||
} | ||
|
||
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities); | ||
} | ||
} | ||
|