Search in sources :

Example 1 with SimpleFeatureUser

use of org.togglz.core.user.SimpleFeatureUser 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)

Example 2 with SimpleFeatureUser

use of org.togglz.core.user.SimpleFeatureUser 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.getDetails();
                    if (principal instanceof OrcidProfileUserDetails) {
                        OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal;
                        isAdmin = userDetails.getAuthorities().contains(OrcidWebRole.ROLE_ADMIN);
                        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)2 Authentication (org.springframework.security.core.Authentication)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 SimpleFeatureUser (org.togglz.core.user.SimpleFeatureUser)2 UserProvider (org.togglz.core.user.UserProvider)2