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);
}
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";
}
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);
}
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.");
}
}
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;
}
Aggregations