Search in sources :

Example 1 with ClientDetails

use of org.maxkey.entity.apps.oauth2.provider.ClientDetails in project powerauth-webflow by wultra.

the class OAuth2AuthorizationServerConfiguration method configureAuthorizationEndpoint.

/**
 * Configures authorization endpoint.
 * @param authorizationEndpoint Authorization endpoint.
 */
@Autowired
public void configureAuthorizationEndpoint(AuthorizationEndpoint authorizationEndpoint) {
    // WORKAROUND: Cancel the session just before the redirect
    DefaultRedirectResolver redirectResolver = new DefaultRedirectResolver() {

        @Override
        public String resolveRedirect(String requestedRedirect, ClientDetails client) throws OAuth2Exception {
            SecurityContextHolder.clearContext();
            return super.resolveRedirect(requestedRedirect, client);
        }
    };
    redirectResolver.setMatchPorts(false);
    authorizationEndpoint.setRedirectResolver(redirectResolver);
}
Also used : DefaultRedirectResolver(org.springframework.security.oauth2.provider.endpoint.DefaultRedirectResolver) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 2 with ClientDetails

use of org.maxkey.entity.apps.oauth2.provider.ClientDetails in project alexa-oauth-sample by alexa-samples.

the class ClientsController method showEditForm.

@RequestMapping(value = "/form", method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String showEditForm(@RequestParam(value = "client", required = false) String clientId, Model model) {
    ClientDetails clientDetails;
    if (clientId != null) {
        clientDetails = clientsDetailsService.loadClientByClientId(clientId);
    } else {
        clientDetails = new BaseClientDetails();
    }
    model.addAttribute("clientDetails", clientDetails);
    return "clientForm";
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ClientDetails

use of org.maxkey.entity.apps.oauth2.provider.ClientDetails in project alexa-oauth-sample by alexa-samples.

the class DynamoDBClientDetailsDAO method addOrUpdateClientDetails.

/**
 * Add or update a client details in database.
 *
 * @param clientDetails client details.
 */
public void addOrUpdateClientDetails(@NonNull ClientDetails clientDetails) {
    List<String> autoApproveList = clientDetails.getScope().stream().filter(scope -> clientDetails.isAutoApprove(scope)).collect(Collectors.toList());
    OAuthClientDetails oAuthClientDetails = OAuthClientDetails.builder().clientId(clientDetails.getClientId()).authorities(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())).authorizedGrantTypes(StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())).scopes(StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())).webServerRedirectUri(StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())).accessTokenValidity(clientDetails.getAccessTokenValiditySeconds()).refreshTokenValidity(clientDetails.getRefreshTokenValiditySeconds()).autoapprove(StringUtils.collectionToCommaDelimitedString(autoApproveList)).build();
    DynamoDBMapperConfig dynamoDBMapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES).build();
    dynamoDBMapper.save(oAuthClientDetails, dynamoDBMapperConfig);
}
Also used : ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException) NonNull(lombok.NonNull) ClientAlreadyExistsException(org.springframework.security.oauth2.provider.ClientAlreadyExistsException) OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SaveBehavior(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig.SaveBehavior) NoSuchClientException(org.springframework.security.oauth2.provider.NoSuchClientException) Collectors(java.util.stream.Collectors) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) DynamoDBMapperConfig(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) ClientRegistrationService(org.springframework.security.oauth2.provider.ClientRegistrationService) StringUtils(org.springframework.util.StringUtils) DynamoDBMapperConfig(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig) OAuthClientDetails(com.oauth.server.dto.OAuthClientDetails)

Example 4 with ClientDetails

use of org.maxkey.entity.apps.oauth2.provider.ClientDetails in project sw360 by eclipse.

the class Sw360UserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    UserDetails result = null;
    Authentication clientAuthentication = SecurityContextHolder.getContext().getAuthentication();
    if (clientAuthentication != null && clientAuthentication instanceof UsernamePasswordAuthenticationToken) {
        String clientId = ((org.springframework.security.core.userdetails.User) clientAuthentication.getPrincipal()).getUsername();
        try {
            ClientDetails clientDetails = clientProvider.loadClientByClientId(clientId);
            log.debug("Sw360ClientDetailsService returned client " + clientDetails + " for id " + clientId + " from authentication details.");
            User user = userProvider.provideUserDetails(username, null);
            log.debug("Sw360UserDetailsProvider returned user " + user);
            if (clientDetails != null && user != null) {
                result = new org.springframework.security.core.userdetails.User(user.getEmail(), "PreAuthenticatedPassword", authoritiesCalculator.mergedAuthoritiesOf(user, clientDetails));
            }
        } catch (ClientRegistrationException e) {
            log.warn("No valid client for id " + clientId + " could be found. It is possible that it is " + "locked, expired, disabled, or invalid for any other reason.");
            throw new UsernameNotFoundException("We cannot provide UserDetails for an invalid client: ", e);
        }
    } else {
        log.warn("Called in unwanted case: " + clientAuthentication);
    }
    if (result != null) {
        return result;
    } else {
        throw new UsernameNotFoundException("No user with username " + username + " found in sw360 users.");
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UserDetails(org.springframework.security.core.userdetails.UserDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Authentication(org.springframework.security.core.Authentication) ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException)

Example 5 with ClientDetails

use of org.maxkey.entity.apps.oauth2.provider.ClientDetails in project sw360 by eclipse.

the class Sw360LiferayAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String userIdentifier = authentication.getName();
    Object possiblePassword = authentication.getCredentials();
    if (possiblePassword == null) {
        return null;
    }
    String password = possiblePassword.toString();
    if (isValidString(sw360PortalServerURL) && isValidString(sw360LiferayCompanyId)) {
        // Verify if the user exists in sw360 and set the corresponding authority (read, write)
        if (isAuthorized(userIdentifier, password)) {
            User user = sw360CustomHeaderUserDetailsProvider.provideUserDetails(userIdentifier, userIdentifier);
            if (!Objects.isNull(user)) {
                ClientDetails clientDetails = extractClient(authentication);
                return new UsernamePasswordAuthenticationToken(userIdentifier, password, sw360UserAndClientAuthoritiesCalculator.mergedAuthoritiesOf(user, clientDetails));
            }
        }
    }
    return null;
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)215 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)134 Test (org.junit.jupiter.api.Test)83 Test (org.junit.Test)31 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 ClientDetailsHelper.arrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.arrayFromString)25 ClientDetailsHelper.clientArrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientArrayFromString)25 ClientDetailsHelper.clientFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientFromString)25 ResultActions (org.springframework.test.web.servlet.ResultActions)24 HashMap (java.util.HashMap)19 ClientDetails (org.maxkey.entity.apps.oauth2.provider.ClientDetails)18 NoSuchClientException (org.springframework.security.oauth2.provider.NoSuchClientException)18 ClientDetailsModification (org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)17 Authentication (org.springframework.security.core.Authentication)17 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)16 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)16 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)15 Matchers.containsString (org.hamcrest.Matchers.containsString)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14