当前位置: 首页>>代码示例>>Java>>正文


Java AuthorizationRequest.getRedirectUri方法代码示例

本文整理汇总了Java中org.springframework.security.oauth2.provider.AuthorizationRequest.getRedirectUri方法的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationRequest.getRedirectUri方法的具体用法?Java AuthorizationRequest.getRedirectUri怎么用?Java AuthorizationRequest.getRedirectUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.oauth2.provider.AuthorizationRequest的用法示例。


在下文中一共展示了AuthorizationRequest.getRedirectUri方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ensureRedirectUriIsAuthorized

import org.springframework.security.oauth2.provider.AuthorizationRequest; //导入方法依赖的package包/类
/**
 * Ensure redirect uri is authorized.
 *
 * @param authorizationRequest the authorization request
 * @param client               the client
 */
private static void ensureRedirectUriIsAuthorized(final AuthorizationRequest authorizationRequest, 
                                           final ClientDetailsEntity client) {
    if (!Strings.isNullOrEmpty(authorizationRequest.getRedirectUri())) {
        boolean found = false;
        final Iterator<String> it = client.getRedirectUris().iterator();

        while (!found && it.hasNext()) {
            found = it.next().equals(authorizationRequest.getRedirectUri());
        }
        if (!found) {
            throw new OIDCException("Redirect uri in the authorization request " +
                    authorizationRequest.getRedirectUri()
                    + " is not registered for client " + client.getClientId());
        }
    }
}
 
开发者ID:uchicago,项目名称:shibboleth-oidc,代码行数:23,代码来源:BuildAuthorizationRequestContextAction.java

示例2: getSuccessfulRedirect

import org.springframework.security.oauth2.provider.AuthorizationRequest; //导入方法依赖的package包/类
private String getSuccessfulRedirect(AuthorizationRequest authorizationRequest, String authorizationCode) {

		if (authorizationCode == null) {
			throw new IllegalStateException("No authorization code found in the current request scope.");
		}

		String requestedRedirect = authorizationRequest.getRedirectUri();
		String[] fragments = requestedRedirect.split("#");
		String state = authorizationRequest.getState();

		StringBuilder url = new StringBuilder(fragments[0]);
		if (requestedRedirect.indexOf('?') < 0) {
			url.append('?');
		}
		else {
			url.append('&');
		}
		url.append("code=").append(authorizationCode);

		if (state != null) {
			url.append("&state=").append(state);
		}

		if (fragments.length > 1) {
			url.append("#" + fragments[1]);
		}

		return url.toString();
	}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:30,代码来源:AuthorizationEndpoint.java

示例3: approveOrDeny

import org.springframework.security.oauth2.provider.AuthorizationRequest; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST, params = OAuth2Utils.USER_OAUTH_APPROVAL)
public View approveOrDeny(@RequestParam Map<String, String> approvalParameters, Map<String, ?> model,
		SessionStatus sessionStatus, Principal principal) {

	if (!(principal instanceof Authentication)) {
		sessionStatus.setComplete();
		throw new InsufficientAuthenticationException(
				"User must be authenticated with Spring Security before authorizing an access token.");
	}

	AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");

	if (authorizationRequest == null) {
		sessionStatus.setComplete();
		throw new InvalidRequestException("Cannot approve uninitialized authorization request.");
	}

	try {
		Set<String> responseTypes = authorizationRequest.getResponseTypes();

		authorizationRequest.setApprovalParameters(approvalParameters);
		authorizationRequest = userApprovalHandler.updateAfterApproval(authorizationRequest, (Authentication) principal);
		boolean approved = userApprovalHandler.isApproved(authorizationRequest, (Authentication) principal);
		authorizationRequest.setApproved(approved);

		if (authorizationRequest.getRedirectUri() == null) {
			sessionStatus.setComplete();
			throw new InvalidRequestException("Cannot approve request when no redirect URI is provided.");
		}
		
		if (!authorizationRequest.isApproved()) {
			return new RedirectView(getUnsuccessfulRedirect(authorizationRequest, new UserDeniedAuthorizationException(
					"User denied access"), responseTypes.contains("token")), false, true, false);
		}

		if (responseTypes.contains("token")) {
			return getImplicitGrantResponse(authorizationRequest).getView();
		}

		return getAuthorizationCodeResponse(authorizationRequest, (Authentication) principal);
	}
	finally {
		sessionStatus.setComplete();
	}

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:47,代码来源:AuthorizationEndpoint.java

示例4: appendAccessToken

import org.springframework.security.oauth2.provider.AuthorizationRequest; //导入方法依赖的package包/类
private String appendAccessToken(AuthorizationRequest authorizationRequest, OAuth2AccessToken accessToken) {
       
       Map<String, Object> vars = new HashMap<String, Object>();
       
	String requestedRedirect = authorizationRequest.getRedirectUri();
	if (accessToken == null) {
		throw new InvalidRequestException("An implicit grant could not be made");
	}
	StringBuilder url = new StringBuilder(requestedRedirect);
	if (requestedRedirect.contains("#")) {
		url.append("&");
	}
	else {
		url.append("#");
	}

	url.append("access_token={access_token}");
	url.append("&token_type={token_type}");
	vars.put("access_token", accessToken.getValue());
	vars.put("token_type", accessToken.getTokenType());
	String state = authorizationRequest.getState();
       
	if (state != null) {
		url.append("&state={state}");
		vars.put("state", state);
	}
	Date expiration = accessToken.getExpiration();
	if (expiration != null) {
		long expires_in = (expiration.getTime() - System.currentTimeMillis()) / 1000;
		url.append("&expires_in={expires_in}");
		vars.put("expires_in", expires_in);
	}
	String originalScope = authorizationRequest.getRequestParameters().get(OAuth2Utils.SCOPE);
	if (originalScope==null || !OAuth2Utils.parseParameterList(originalScope).equals(accessToken.getScope())) {
		url.append("&" + OAuth2Utils.SCOPE + "={scope}");
		vars.put("scope", OAuth2Utils.formatParameterList(accessToken.getScope()));
	}
	Map<String, Object> additionalInformation = accessToken.getAdditionalInformation();
	for (String key : additionalInformation.keySet()) {
		Object value = additionalInformation.get(key);
		if (value != null) {
			url.append("&" + key + "={extra_" + key + "}");
			vars.put("extra_" + key, value);
		}
	}
	UriTemplate template = new UriTemplate(url.toString());
	// Do not include the refresh token (even if there is one)
	return template.expand(vars).toString();
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:50,代码来源:AuthorizationEndpoint.java

示例5: getUnsuccessfulRedirect

import org.springframework.security.oauth2.provider.AuthorizationRequest; //导入方法依赖的package包/类
private String getUnsuccessfulRedirect(AuthorizationRequest authorizationRequest, OAuth2Exception failure,
		boolean fragment) {

	if (authorizationRequest == null || authorizationRequest.getRedirectUri() == null) {
		// we have no redirect for the user. very sad.
		throw new UnapprovedClientAuthenticationException("Authorization failure, and no redirect URI.", failure);
	}

	String redirectUri = authorizationRequest.getRedirectUri();

	// extract existing fragments if any
	String[] fragments = redirectUri.split("#");

	StringBuilder url = new StringBuilder(fragment ? redirectUri : fragments[0]);

	char separator = fragment ? '#' : '?';
	if (redirectUri.indexOf(separator) < 0) {
		url.append(separator);
	}
	else {
		url.append('&');
	}
	url.append("error=").append(failure.getOAuth2ErrorCode());
	try {

		url.append("&error_description=").append(URLEncoder.encode(failure.getMessage(), "UTF-8"));

		if (authorizationRequest.getState() != null) {
			url.append('&').append("state=").append(authorizationRequest.getState());
		}

		if (failure.getAdditionalInformation() != null) {
			for (Map.Entry<String, String> additionalInfo : failure.getAdditionalInformation().entrySet()) {
				url.append('&').append(additionalInfo.getKey()).append('=')
						.append(URLEncoder.encode(additionalInfo.getValue(), "UTF-8"));
			}
		}

	}
	catch (UnsupportedEncodingException e) {
		throw new IllegalStateException(e);
	}

	if (!fragment && fragments.length > 1) {
		url.append("#" + fragments[1]);
	}

	return url.toString();

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:51,代码来源:AuthorizationEndpoint.java


注:本文中的org.springframework.security.oauth2.provider.AuthorizationRequest.getRedirectUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。