Search in sources :

Example 1 with UserProvider

use of org.togglz.core.user.UserProvider in project ORCID-Source by ORCID.

the class OrcidTogglzConfiguration method getUserProvider.

@Override
public UserProvider getUserProvider() {
    return new UserProvider() {

        @Override
        public FeatureUser getCurrentUser() {
            boolean isAdmin = false;
            String userOrcid = null;
            SecurityContext context = SecurityContextHolder.getContext();
            if (context != null && context.getAuthentication() != null) {
                Authentication authentication = context.getAuthentication();
                if (authentication != null) {
                    Object principal = authentication.getPrincipal();
                    if (principal instanceof OrcidProfileUserDetails) {
                        OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
                        isAdmin = OrcidType.ADMIN.equals(userDetails.getOrcidType());
                        userOrcid = userDetails.getOrcid();
                    }
                }
            }
            return new SimpleFeatureUser(userOrcid, isAdmin);
        }
    };
}
Also used : UserProvider(org.togglz.core.user.UserProvider) SimpleFeatureUser(org.togglz.core.user.SimpleFeatureUser) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails)

Aggregations

OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 SimpleFeatureUser (org.togglz.core.user.SimpleFeatureUser)1 UserProvider (org.togglz.core.user.UserProvider)1