All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.api.SpringSecurityService Maven / Gradle / Ivy

package com.formkiq.server.api;

import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * Spring Security Services.
 *
 */
@Service
public class SpringSecurityService {

    /**
     * Verify user has access to Client.
     * @param clientid {@link String}
     */
    public void verifyUserHasAccessToClient(final String clientid) {

        Authentication auth = SecurityContextHolder.getContext()
                .getAuthentication();

        if (auth instanceof OAuth2Authentication) {

            OAuth2Authentication a = (OAuth2Authentication) auth;
            if (!StringUtils.isEmpty(clientid)
                    && clientid.equals(a.getOAuth2Request().getClientId())) {
                return;
            }
        }

        throw new BadCredentialsException(
                "User does not have access to Client");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy