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


Java AuthorizationRequest类代码示例

本文整理汇总了Java中org.xdi.oxauth.client.AuthorizationRequest的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationRequest类的具体用法?Java AuthorizationRequest怎么用?Java AuthorizationRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getRedirectionUrl

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String getRedirectionUrl(final WebContext context) {
	init();

	final String state = RandomStringUtils.randomAlphanumeric(10);
	final String nonce = RandomStringUtils.randomAlphanumeric(10);

	final AuthorizationRequest authorizationRequest = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), this.clientId, this.appConfiguration.getOpenIdScopes(),
			this.appConfiguration.getOpenIdRedirectUrl(), null);

	authorizationRequest.setState(state);
	authorizationRequest.setNonce(nonce);

	context.setSessionAttribute(getName() + STATE_PARAMETER, state);

	final String redirectionUrl = this.openIdConfiguration.getAuthorizationEndpoint() + "?" + authorizationRequest.getQueryString();
	logger.debug("oxAuth redirection Url: '{}'", redirectionUrl);

	return redirectionUrl;
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:23,代码来源:OpenIdClient.java

示例2: getRedirectionUrl

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
/**
 * {@InheritDoc}
 */
public String getRedirectionUrl(final WebContext context) {
	init();

	final String state = RandomStringUtils.randomAlphanumeric(10);
	final String nonce = RandomStringUtils.randomAlphanumeric(10);

	final AuthorizationRequest authorizationRequest = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), this.clientId, this.appConfiguration.getOpenIdScopes(),
			this.appConfiguration.getOpenIdRedirectUrl(), null);

	authorizationRequest.setState(state);
	authorizationRequest.setNonce(nonce);

	context.setSessionAttribute(getName() + STATE_PARAMETER, state);

	final String redirectionUrl = this.openIdConfiguration.getAuthorizationEndpoint() + "?" + authorizationRequest.getQueryString();
	logger.debug("oxAuth redirection Url: '{}'", redirectionUrl);

	return redirectionUrl;
}
 
开发者ID:GluuFederation,项目名称:oxTrust,代码行数:23,代码来源:OpenIdClient.java

示例3: JwtAuthorizationRequest

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
private JwtAuthorizationRequest(
        AuthorizationRequest authorizationRequest, SignatureAlgorithm signatureAlgorithm,
        AbstractCryptoProvider cryptoProvider, KeyEncryptionAlgorithm keyEncryptionAlgorithm,
        BlockEncryptionAlgorithm blockEncryptionAlgorithm, String sharedKey) {
    setAuthorizationRequestParams(authorizationRequest);

    this.type = JwtType.JWT;
    this.signatureAlgorithm = signatureAlgorithm;
    this.cryptoProvider = cryptoProvider;
    this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
    this.blockEncryptionAlgorithm = blockEncryptionAlgorithm;
    this.sharedKey = sharedKey;

    this.userInfoMember = new UserInfoMember();
    this.idTokenMember = new IdTokenMember();
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:17,代码来源:JwtAuthorizationRequest.java

示例4: setAuthorizationRequestParams

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
private void setAuthorizationRequestParams(AuthorizationRequest authorizationRequest) {
    if (authorizationRequest != null) {
        this.responseTypes = authorizationRequest.getResponseTypes();
        this.clientId = authorizationRequest.getClientId();
        this.scopes = authorizationRequest.getScopes();
        this.redirectUri = authorizationRequest.getRedirectUri();
        this.state = authorizationRequest.getState();
        this.nonce = authorizationRequest.getNonce();
        this.display = authorizationRequest.getDisplay();
        this.prompts = authorizationRequest.getPrompts();
        this.maxAge = authorizationRequest.getMaxAge();
        this.uiLocales = authorizationRequest.getUiLocales();
        this.claimsLocales = authorizationRequest.getClaimsLocales();
        this.idTokenHint = authorizationRequest.getIdTokenHint();
        this.loginHint = authorizationRequest.getLoginHint();
        this.acrValues = authorizationRequest.getAcrValues();
        this.registration = authorizationRequest.getRegistration();
        this.requestUniqueId = authorizationRequest.isRequestSessionId();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:21,代码来源:JwtAuthorizationRequest.java

示例5: rejectRequestWithoutResponseType

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({"userId", "userSecret"})
@Test
public void rejectRequestWithoutResponseType(final String userId, final String userSecret) throws Exception {
    showTitle("OC5:FeatureTest-Reject Request Without response type");

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(null, null, null, null, null);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(authorizationRequest);
    AuthorizationResponse authorizationResponse = authorizeClient.exec();

    showClient(authorizeClient);
    assertEquals(authorizationResponse.getStatus(), 400, "Unexpected response code: " + authorizationResponse.getStatus());
    assertNotNull(authorizationResponse.getErrorType(), "The error type is null");
    assertNotNull(authorizationResponse.getErrorDescription(), "The error description is null");
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:19,代码来源:RejectRequestWithoutResponseType.java

示例6: getOpenIdRequestObject

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
public String getOpenIdRequestObject() {
    openIdRequestObject = "";

    try {
        if (useOpenIdRequestObject) {
            AuthorizationRequest req = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
            req.setState(state);
            req.setRequestUri(requestUri);
            req.setMaxAge(maxAge);
            req.setUiLocales(StringUtils.spaceSeparatedToList(uiLocales));
            req.setClaimsLocales(StringUtils.spaceSeparatedToList(claimsLocales));
            req.setIdTokenHint(idTokenHint);
            req.setLoginHint(loginHint);
            req.setAcrValues(StringUtils.spaceSeparatedToList(acrValues));
            req.setRegistration(registration);
            req.setDisplay(display);
            req.getPrompts().addAll(prompt);

            OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
            JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(
                    req, SignatureAlgorithm.NONE, (String) null, cryptoProvider);
            jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
            jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull()));
            jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, ClaimValue.createValueList(new String[]{"2"})));
            jwtAuthorizationRequest.getIdTokenMember().setMaxAge(86400);
            openIdRequestObject = jwtAuthorizationRequest.getDecodedJwt();
        }
    } catch (Exception e) {
    	log.error(e.getMessage(), e);
    }

    return openIdRequestObject;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:38,代码来源:AuthorizationAction.java

示例7: omittedResponseTypesStep4

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
/**
 * Authorization request with the other Response types combination should
 * fail.
 */
@Test(dependsOnMethods = "omittedResponseTypesStep3b", dataProvider = "omittedResponseTypesStep4DataProvider")
public void omittedResponseTypesStep4(final String authorizePath, final String userId, final String userSecret,
                                      final String redirectUri, final List<ResponseType> responseTypes) throws Exception {
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, nonce);
    authorizationRequest.setState("af0ifjsldkj");
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("omittedResponseTypesStep4", response, entity);

    if (response.getStatus() == 400) {
        assertNotNull(entity, "Unexpected result: " + entity);
        try {
            JSONObject jsonObj = new JSONObject(entity);
            assertTrue(jsonObj.has("error"), "The error type is null");
            assertTrue(jsonObj.has("error_description"), "The error description is null");
        } catch (JSONException e) {
            e.printStackTrace();
            fail(e.getMessage() + "\nResponse was: " + entity);
        }
    } else {
        fail("Unexpected response code: " + response.getStatus());
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:42,代码来源:ResponseTypesRestrictionEmbeddedTest.java

示例8: responseTypesCodeIdTokenStep4

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
/**
 * Authorization request with the other Response types combination should
 * fail.
 */
@Test(dependsOnMethods = "omittedResponseTypesStep3b", dataProvider = "responseTypesCodeIdTokenStep4DataProvider")
public void responseTypesCodeIdTokenStep4(final String authorizePath, final String userId, final String userSecret,
                                          final String redirectUri, final List<ResponseType> responseTypes) throws Exception {
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes,
            redirectUri, nonce);
    authorizationRequest.setState("af0ifjsldkj");
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("responseTypesCodeIdTokenStep4", response, entity);

    if (response.getStatus() == 400) {
        assertNotNull(entity, "Unexpected result: " + entity);
        try {
            JSONObject jsonObj = new JSONObject(entity);
            assertTrue(jsonObj.has("error"), "The error type is null");
            assertTrue(jsonObj.has("error_description"), "The error description is null");
        } catch (JSONException e) {
            e.printStackTrace();
            fail(e.getMessage() + "\nResponse was: " + entity);
        }
    } else {
        fail("Unexpected response code: " + response.getStatus());
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:42,代码来源:ResponseTypesRestrictionEmbeddedTest.java

示例9: responseTypesTokenIdTokenStep4

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
/**
 * Authorization request with the other Response types combination should
 * fail.
 */
@Test(dependsOnMethods = "responseTypesTokenIdTokenStep3", dataProvider = "responseTypesTokenIdTokenStep4DataProvider")
public void responseTypesTokenIdTokenStep4(final String authorizePath, final String userId, final String userSecret,
                                           final String redirectUri, final List<ResponseType> responseTypes) throws Exception {
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId3, scopes,
            redirectUri, nonce);
    authorizationRequest.setState("af0ifjsldkj");
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);

    Builder request = ResteasyClientBuilder.newClient()
            .target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);

    Response response = request.get();
    String entity = response.readEntity(String.class);

    showResponse("responseTypesTokenIdTokenStep4", response, entity);

    if (response.getStatus() == 400) {
        assertNotNull(entity, "Unexpected result: " + entity);
        try {
            JSONObject jsonObj = new JSONObject(entity);
            assertTrue(jsonObj.has("error"), "The error type is null");
            assertTrue(jsonObj.has("error_description"), "The error description is null");
        } catch (JSONException e) {
            e.printStackTrace();
            fail(e.getMessage() + "\nResponse was: " + entity);
        }
    } else {
        fail("Unexpected response code: " + response.getStatus());
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:42,代码来源:ResponseTypesRestrictionEmbeddedTest.java

示例10: getOAuthRedirectUrl

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
public String getOAuthRedirectUrl(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
	String authorizeUrl = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_AUTHORIZE_URL, null);
	String clientScopes = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_SCOPE, null);

	String clientId = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_ID, null);
	String clientSecret = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, null);
	if (clientSecret != null) {
	    try {
	    	clientSecret = StringEncrypter.defaultInstance().decrypt(clientSecret, Configuration.instance().getCryptoPropertyValue());
	    } catch (EncryptionException ex) {
	    log.error("Failed to decrypt property: " + Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, ex);
	    }
	}

	String redirectUri = constructRedirectUrl(request);

	List<String> scopes = Arrays.asList(clientScopes.split(StringUtils.SPACE));
	List<ResponseType> responseTypes = Arrays.asList(ResponseType.ID_TOKEN, ResponseType.CODE);

	String nonce = UUID.randomUUID().toString();
	String rfp = UUID.randomUUID().toString();
	String jti = UUID.randomUUID().toString();
	
               // Lookup for relying party ID
               final String key = request.getParameter(ExternalAuthentication.CONVERSATION_KEY);
               request.getSession().setAttribute(SESSION_CONVERSATION_KEY, key);
               ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, request);
               
               String relyingPartyId = "";
               final RelyingPartyContext relyingPartyCtx = prc.getSubcontext(RelyingPartyContext.class);
               if (relyingPartyCtx != null) {
                   relyingPartyId = relyingPartyCtx.getRelyingPartyId();
                   log.info("relyingPartyId found: " + relyingPartyId);
               }
               else
                   log.warn("No RelyingPartyContext was available");

               // JWT
	OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
	JwtState jwtState = new JwtState(SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
	jwtState.setRfp(rfp);
	jwtState.setJti(jti);
               if (relyingPartyId != null && !"".equals(relyingPartyId)) {
                   String additionalClaims = String.format("{relyingPartyId: '%s'}", relyingPartyId);
                   jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
               } else 
                   log.warn("No relyingPartyId was available");
	String encodedState = jwtState.getEncodedJwt();

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
	authorizationRequest.setState(encodedState);

	Cookie currentShibstateCookie = getCurrentShibstateCookie(request);
	if (currentShibstateCookie != null) {
		String requestUri = decodeCookieValue(currentShibstateCookie.getValue());
		log.debug("requestUri = \"" + requestUri + "\"");

		String authenticationMode = determineAuthenticationMode(requestUri);

		if (StringHelper.isNotEmpty(authenticationMode)) {
			log.debug("acr_values = \"" + authenticationMode + "\"");
			authorizationRequest.setAcrValues(Arrays.asList(authenticationMode));
			updateShibstateCookie(response, currentShibstateCookie, requestUri,
					"/" + Configuration.OXAUTH_ACR_VALUES + "/" + authenticationMode);
		}
	}

	return authorizeUrl + "?" + authorizationRequest.getQueryString();
}
 
开发者ID:GluuFederation,项目名称:oxTrust,代码行数:70,代码来源:AuthenticationFilter.java

示例11: obtainAccessToken

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({"userId", "userSecret", "redirectUris"})
@Test(invocationCount = 1000, threadPoolSize = 100)
public void obtainAccessToken(final String userId, final String userSecret, String redirectUris) throws Exception {
    showTitle("requestClientAssociate1");

    redirectUris = "https://client.example.com/cb";

    final List<ResponseType> responseTypes = new ArrayList<ResponseType>();
    responseTypes.add(ResponseType.CODE);
    responseTypes.add(ResponseType.ID_TOKEN);

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
                    StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setResponseTypes(responseTypes);
    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());

    final String clientId = response.getClientId();
    final String clientSecret = response.getClientSecret();

    // 1. Request authorization and receive the authorization code.

    final List<String> scopes = Arrays.asList("openid", "profile", "address", "email");

    final AuthorizationRequest request = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUris, null);
    request.setState("af0ifjsldkj");
    request.setAuthUsername(userId);
    request.setAuthPassword(userSecret);
    request.getPrompts().add(Prompt.NONE);

    final AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(request);
    final AuthorizationResponse response1 = authorizeClient.exec();

    ClientUtils.showClient(authorizeClient);

    final String scope = response1.getScope();
    final String authorizationCode = response1.getCode();
    assertTrue(Util.allNotBlank(authorizationCode));


    // 2. Request access token using the authorization code.
    final TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
    tokenRequest.setCode(authorizationCode);
    tokenRequest.setRedirectUri(redirectUris);
    tokenRequest.setAuthUsername(clientId);
    tokenRequest.setAuthPassword(clientSecret);
    tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
    tokenRequest.setScope(scope);

    final TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
    tokenClient1.setRequest(tokenRequest);
    final TokenResponse response2 = tokenClient1.exec();
    ClientUtils.showClient(authorizeClient);

    assertTrue(response2.getStatus() == 200);
    final String patToken = response2.getAccessToken();
    final String patRefreshToken = response2.getRefreshToken();
    assertTrue(Util.allNotBlank(patToken, patRefreshToken));
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:69,代码来源:ObtainAccessTokenLoadTest.java

示例12: requestAuthorizationCodeWithResponseModeQuery

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationCodeWithResponseModeQuery(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri) throws Exception {
	final String state = UUID.randomUUID().toString();

	List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
	List<String> scopes = Arrays.asList("openid", "profile", "address", "email");

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes,
			redirectUri, null);
	authorizationRequest.setState(state);
	authorizationRequest.getPrompts().add(Prompt.NONE);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.setResponseMode(ResponseMode.QUERY);

	Builder request = ResteasyClientBuilder.newClient()
			.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
	request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
	request.header("Accept", MediaType.TEXT_PLAIN);

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestAuthorizationCodeWithResponseModeQuery", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	try {
		URI uri = new URI(response.getLocation().toString());
		assertNotNull(uri.getQuery(), "Query string is null");

		Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());

		assertNotNull(params.get(AuthorizeResponseParam.CODE), "The code is null");
		assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope is null");
		assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
		assertEquals(params.get(AuthorizeResponseParam.STATE), state);
	} catch (URISyntaxException e) {
		e.printStackTrace();
		fail("Response URI is not well formed");
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:46,代码来源:AuthorizeWithResponseModeEmbeddedTest.java

示例13: requestAuthorizationCodeWithResponseModeFragment

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationCodeWithResponseModeFragment(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri) throws Exception {

	final String state = UUID.randomUUID().toString();

	List<ResponseType> responseTypes = new ArrayList<ResponseType>();
	responseTypes.add(ResponseType.CODE);
	List<String> scopes = Arrays.asList("openid", "profile", "address", "email");

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes,
			redirectUri, null);
	authorizationRequest.setState(state);
	authorizationRequest.getPrompts().add(Prompt.NONE);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.setResponseMode(ResponseMode.FRAGMENT);

	Builder request = ResteasyClientBuilder.newClient()
			.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
	request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
	request.header("Accept", MediaType.TEXT_PLAIN);

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestAuthorizationCodeWithResponseModeFragment", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	try {
		URI uri = new URI(response.getLocation().toString());
		assertNotNull(uri.getFragment(), "Fragment is null");

		Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

		assertNotNull(params.get(AuthorizeResponseParam.CODE), "The code is null");
		assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope is null");
		assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");

		assertEquals(params.get(AuthorizeResponseParam.STATE), state);
	} catch (URISyntaxException e) {
		e.printStackTrace();
		fail("Response URI is not well formed");
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:49,代码来源:AuthorizeWithResponseModeEmbeddedTest.java

示例14: requestAuthorizationTokenWithResponseModeQuery

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationTokenWithResponseModeQuery(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri) throws Exception {

	final String state = UUID.randomUUID().toString();

	List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
	List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
	String nonce = UUID.randomUUID().toString();

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes,
			redirectUri, nonce);
	authorizationRequest.setState(state);
	authorizationRequest.getPrompts().add(Prompt.NONE);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.setResponseMode(ResponseMode.QUERY);

	Builder request = ResteasyClientBuilder.newClient()
			.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
	request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
	request.header("Accept", MediaType.TEXT_PLAIN);

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestAuthorizationTokenWithResponseModeQuery", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	if (response.getLocation() != null) {
		try {
			URI uri = new URI(response.getLocation().toString());
			assertNotNull(uri.getQuery(), "Query is null");

			Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());

			assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
			assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
			assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
			assertNotNull(params.get(AuthorizeResponseParam.EXPIRES_IN), "The expires in value is null");
			assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope must be null");
			assertNull(params.get("refresh_token"), "The refresh_token must be null");
			assertEquals(params.get(AuthorizeResponseParam.STATE), state);
		} catch (URISyntaxException e) {
			e.printStackTrace();
			fail("Response URI is not well formed");
		}
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:53,代码来源:AuthorizeWithResponseModeEmbeddedTest.java

示例15: requestAuthorizationTokenWithResponseModeFragment

import org.xdi.oxauth.client.AuthorizationRequest; //导入依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationTokenWithResponseModeFragment(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri) throws Exception {

	final String state = UUID.randomUUID().toString();

	List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
	List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
	String nonce = UUID.randomUUID().toString();

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes,
			redirectUri, nonce);
	authorizationRequest.setState(state);
	authorizationRequest.getPrompts().add(Prompt.NONE);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.setResponseMode(ResponseMode.FRAGMENT);

	Builder request = ResteasyClientBuilder.newClient()
			.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
	request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
	request.header("Accept", MediaType.TEXT_PLAIN);

	Response response = request.get();
	String entity = response.readEntity(String.class);

	showResponse("requestAuthorizationTokenWithResponseModeFragment", response, entity);

	assertEquals(response.getStatus(), 302, "Unexpected response code.");
	assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());

	if (response.getLocation() != null) {
		try {
			URI uri = new URI(response.getLocation().toString());
			assertNotNull(uri.getFragment(), "Fragment is null");

			Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

			assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
			assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
			assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
			assertNotNull(params.get(AuthorizeResponseParam.EXPIRES_IN), "The expires in value is null");
			assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope must be null");
			assertNull(params.get("refresh_token"), "The refresh_token must be null");
			assertEquals(params.get(AuthorizeResponseParam.STATE), state);
		} catch (URISyntaxException e) {
			e.printStackTrace();
			fail("Response URI is not well formed");
		}
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:53,代码来源:AuthorizeWithResponseModeEmbeddedTest.java


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