當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientDetails.isAutoApprove方法代碼示例

本文整理匯總了Java中org.springframework.security.oauth2.provider.ClientDetails.isAutoApprove方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientDetails.isAutoApprove方法的具體用法?Java ClientDetails.isAutoApprove怎麽用?Java ClientDetails.isAutoApprove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.security.oauth2.provider.ClientDetails的用法示例。


在下文中一共展示了ClientDetails.isAutoApprove方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateDBObject

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
private void updateDBObject(DBObject dbo, ClientDetails clientDetails) {
    dbo.put(resourceIdsFieldName, clientDetails.getResourceIds());
    dbo.put(scopeFieldName, clientDetails.getScope());
    dbo.put(authorizedGrantTypesFieldName, clientDetails.getAuthorizedGrantTypes());
    dbo.put(registeredRedirectUrisFieldName, clientDetails.getRegisteredRedirectUri());
    dbo.put(authoritiesFieldName, AuthorityUtils.authorityListToSet(clientDetails.getAuthorities()));
    dbo.put(accessTokenValidityFieldName, clientDetails.getAccessTokenValiditySeconds());
    dbo.put(refreshTokenValidityFieldName, clientDetails.getRefreshTokenValiditySeconds());
    dbo.put(additionalInformationFieldName, clientDetails.getAdditionalInformation());
    Set<String> autoApprove = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            autoApprove.add(scope);
        }
    }
    dbo.put(autoApproveFieldName, autoApprove.size() == 1 ? autoApprove.iterator().next() : autoApprove);
}
 
開發者ID:cedac-software,項目名稱:spring-security-mongodb,代碼行數:18,代碼來源:MongoClientDetailsService.java

示例2: ByAutoApproveOfScope

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
private Predicate<String> ByAutoApproveOfScope(final ClientDetails clientDetails) {
	return new Predicate<String>() {
		@Override
		public boolean apply(final String scope) {
			return clientDetails.isAutoApprove(scope);
		}
	};
}
 
開發者ID:cloudade,項目名稱:authorization-server-with-mongodb,代碼行數:9,代碼來源:MongoClientDetailsService.java

示例3: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@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;
}
 
開發者ID:osiam,項目名稱:auth-server,代碼行數:13,代碼來源:OsiamUserApprovalHandler.java

示例4: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
@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;
}
 
開發者ID:osiam,項目名稱:osiam,代碼行數:13,代碼來源:OsiamUserApprovalHandler.java

示例5: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
/**
 * 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;

}
 
開發者ID:imCodePartnerAB,項目名稱:iVIS,代碼行數:41,代碼來源:IvisUserApprovalHandler.java

示例6: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
/**
 * 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;

}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:41,代碼來源:SparklrUserApprovalHandler.java

示例7: getAutoApproveScopes

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
private Set<String> getAutoApproveScopes(final ClientDetails clientDetails) {
	if (clientDetails.isAutoApprove("true")) {
		return newHashSet("true"); // all scopes autoapproved
	}
	return filter(clientDetails.getScope(), ByAutoApproveOfScope(clientDetails));
}
 
開發者ID:cloudade,項目名稱:authorization-server-with-mongodb,代碼行數:7,代碼來源:MongoClientDetailsService.java

示例8: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest,
		Authentication userAuthentication) {

	String clientId = authorizationRequest.getClientId();
	Collection<String> requestedScopes = authorizationRequest.getScope();
	Set<String> approvedScopes = new HashSet<String>();
	Set<String> validUserApprovedScopes = new HashSet<String>();

	if (clientDetailsService != null) {
		try {
			ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
			for (String scope : requestedScopes) {
				if (client.isAutoApprove(scope) || client.isAutoApprove("all")) {
					approvedScopes.add(scope);
				}
			}
			if (approvedScopes.containsAll(requestedScopes)) {
				authorizationRequest.setApproved(true);
				return authorizationRequest;
			}
		}
		catch (ClientRegistrationException e) {
			logger.warn("Client registration problem prevent autoapproval check for client=" + clientId);
		}
	}

	if (logger.isDebugEnabled()) {
		StringBuilder builder = new StringBuilder("Looking up user approved authorizations for ");
		builder.append("client_id=" + clientId);
		builder.append(" and username=" + userAuthentication.getName());
		logger.debug(builder.toString());
	}

	// Find the stored approvals for that user and client
	Collection<Approval> userApprovals = approvalStore.getApprovals(userAuthentication.getName(),
			clientId);

	// Look at the scopes and see if they have expired
	Date today = new Date();
	for (Approval approval : userApprovals) {
		if (approval.getExpiresAt().after(today)) {
			validUserApprovedScopes.add(approval.getScope());
			if (approval.getStatus() == ApprovalStatus.APPROVED) {
				approvedScopes.add(approval.getScope());
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Valid user approved/denied scopes are " + validUserApprovedScopes);
	}

	// If the requested scopes have already been acted upon by the user,
	// this request is approved
	if (validUserApprovedScopes.containsAll(requestedScopes)) {
		approvedScopes.retainAll(requestedScopes);
		// Set only the scopes that have been approved by the user
		authorizationRequest.setScope(approvedScopes);
		authorizationRequest.setApproved(true);
	}

	return authorizationRequest;

}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:65,代碼來源:ApprovalStoreUserApprovalHandler.java

示例9: checkForPreApproval

import org.springframework.security.oauth2.provider.ClientDetails; //導入方法依賴的package包/類
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
	
	boolean approved = false;
	
	String clientId = authorizationRequest.getClientId();
	Set<String> scopes = authorizationRequest.getScope();
	if (clientDetailsService!=null) {
		try {
			ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
			approved = true;
			for (String scope : scopes) {
				if (!client.isAutoApprove(scope)) {
					approved = false;
				}
			}
			if (approved) {
				authorizationRequest.setApproved(true);
				return authorizationRequest;
			}
		}
		catch (ClientRegistrationException e) {
			logger.warn("Client registration problem prevent autoapproval check for client=" + clientId);
		}		
	}
	
	OAuth2Request storedOAuth2Request = requestFactory.createOAuth2Request(authorizationRequest);
	
	OAuth2Authentication authentication = new OAuth2Authentication(storedOAuth2Request, userAuthentication);
	if (logger.isDebugEnabled()) {
		StringBuilder builder = new StringBuilder("Looking up existing token for ");
		builder.append("client_id=" + clientId);
		builder.append(", scope=" + scopes);
		builder.append(" and username=" + userAuthentication.getName());
		logger.debug(builder.toString());
	}

	OAuth2AccessToken accessToken = tokenStore.getAccessToken(authentication);
	logger.debug("Existing access token=" + accessToken);
	if (accessToken != null && !accessToken.isExpired()) {
		logger.debug("User already approved with token=" + accessToken);
		// A token was already granted and is still valid, so this is already approved
		approved = true;
	}
	else {
		logger.debug("Checking explicit approval");
		approved = userAuthentication.isAuthenticated() && approved;
	}
	
	authorizationRequest.setApproved(approved);

	return authorizationRequest;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:53,代碼來源:TokenStoreUserApprovalHandler.java


注:本文中的org.springframework.security.oauth2.provider.ClientDetails.isAutoApprove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。