Java Code Examples for org.springframework.security.oauth2.provider.AuthorizationRequest#setApproved()

The following examples show how to use org.springframework.security.oauth2.provider.AuthorizationRequest#setApproved() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAPOfflineTokenServicesCloud.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
static OAuth2Authentication getOAuth2Authentication(String clientId, Set<String> scopes) {
	Authentication userAuthentication = null; // TODO no SAPUserDetails support. Using spring alternative?

	final AuthorizationRequest authorizationRequest = new AuthorizationRequest(clientId, scopes);
	authorizationRequest.setAuthorities(getAuthorities(scopes));
	authorizationRequest.setApproved(true);

	return new OAuth2Authentication(authorizationRequest.createOAuth2Request(), userAuthentication);
}
 
Example 2
Source File: OAuth2AuthenticationConverter.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2Authentication convert(Jwt jwt) {
	AuthenticationToken authenticationToken = (AuthenticationToken) super.convert(jwt);
	String clientId = jwt.getClaimAsString(CLAIM_CLIENT_ID);
	AuthorizationRequest authorizationRequest = new AuthorizationRequest(clientId,
			authenticationToken.getAuthorities().stream().map(Objects::toString).collect(Collectors.toList()));
	authorizationRequest.setApproved(true);
	authorizationRequest.setAuthorities(authenticationToken.getAuthorities());

	return new OAuth2Authentication(authorizationRequest.createOAuth2Request(), authenticationToken);
}
 
Example 3
Source File: OsiamUserApprovalHandler.java    From osiam with MIT License 5 votes vote down vote up
@Override
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest,
                                                Authentication userAuthentication) {
    ClientDetails client = osiamClientDetailsService.loadClientByClientId(authorizationRequest.getClientId());
    if (client.isAutoApprove("") || hasRememberedApprovalForClient(authorizationRequest, client)) {
        authorizationRequest.setApproved(true);
        HashMap<String, String> newApprovalParameters = new HashMap<>(authorizationRequest.getApprovalParameters());
        newApprovalParameters.put(IS_PRE_APPROVED_PARAMETER, "true");
        authorizationRequest.setApprovalParameters(Collections.unmodifiableMap(newApprovalParameters));
    }
    return authorizationRequest;
}
 
Example 4
Source File: EspiUserApprovalHandler.java    From OpenESPI-DataCustodian-java with Apache License 2.0 5 votes vote down vote up
/**
 * Allows automatic approval for a white list of clients in the implicit grant case.
 * 
 * @param authorizationRequest The authorization request.
 * @param userAuthentication the current user authentication
 * 
 * @return An updated request if it has already been approved by the current user.
 */
@Override
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest,
		Authentication userAuthentication) {

	boolean approved = false;
	// If we are allowed to check existing approvals this will short circuit the decision
	if (useApprovalStore) {
		authorizationRequest = super.checkForPreApproval(authorizationRequest, userAuthentication);
		approved = authorizationRequest.isApproved();
	}
	else {
		if (clientDetailsService != null) {
			Collection<String> requestedScopes = authorizationRequest.getScope();
			try {
				ClientDetails client = clientDetailsService
						.loadClientByClientId(authorizationRequest.getClientId());
				for (String scope : requestedScopes) {
					if (client.isAutoApprove(scope) || client.isAutoApprove("all")) {
						approved = true;
						break;
					}
				}
			}
			catch (ClientRegistrationException e) {
			}
		}
	}
	authorizationRequest.setApproved(approved);

	return authorizationRequest;
}