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


Java AuthorizationRequest.setState方法代码示例

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


在下文中一共展示了AuthorizationRequest.setState方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: requestParameterMethodES512X509CertStep2

import org.xdi.oxauth.client.AuthorizationRequest; //导入方法依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri", "ES512_keyId", "dnName", "keyStoreFile",
		"keyStoreSecret" })
@Test(dependsOnMethods = "requestParameterMethodES512X509CertStep1")
public void requestParameterMethodES512X509CertStep2(final String authorizePath, final String userId,
		final String userSecret, final String redirectUri, final String keyId, final String dnName,
		final String keyStoreFile, final String keyStoreSecret) throws Exception {
	Builder request = null;
	try {
		OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);

		List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
		List<String> scopes = Arrays.asList("openid");
		String nonce = UUID.randomUUID().toString();
		String state = UUID.randomUUID().toString();

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

		JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
				SignatureAlgorithm.ES512, cryptoProvider);
		jwtAuthorizationRequest.setKeyId(keyId);
		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" })));
		String authJwt = jwtAuthorizationRequest.getEncodedJwt();
		authorizationRequest.setRequest(authJwt);
		System.out.println("Request JWT: " + authJwt);

		request = ResteasyClientBuilder.newClient()
				.target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
		request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
		request.header("Accept", MediaType.TEXT_PLAIN);
	} catch (Exception ex) {
		fail(ex.getMessage(), ex);
	}

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

	showResponse("requestParameterMethodES512X509CertStep2", 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(), "Query string is null");

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

		assertNotNull(params.get("access_token"), "The accessToken is null");
		assertNotNull(params.get("scope"), "The scope is null");
		assertNotNull(params.get("state"), "The state is null");
	} catch (URISyntaxException e) {
		fail(e.getMessage(), e);
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:70,代码来源:OpenIDRequestObjectWithESAlgEmbeddedTest.java

示例8: requestAuthorizationCode

import org.xdi.oxauth.client.AuthorizationRequest; //导入方法依赖的package包/类
private void requestAuthorizationCode(final String authorizePath, final String userId, final String userSecret,
		final String umaClientId, final String umaRedirectUri, final String p_scopeType) throws Exception {
	List<ResponseType> responseTypes = new ArrayList<ResponseType>();
	responseTypes.add(ResponseType.CODE);
	responseTypes.add(ResponseType.ID_TOKEN);

	List<String> scopes = new ArrayList<String>();
	scopes.add(p_scopeType);

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

	AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, umaClientId, scopes,
			umaRedirectUri, nonce);
	authorizationRequest.setState(state);
	authorizationRequest.setAuthUsername(userId);
	authorizationRequest.setAuthPassword(userSecret);
	authorizationRequest.getPrompts().add(Prompt.NONE);

	Builder request = ResteasyClientBuilder.newClient()
			.target(baseUri.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);

	BaseTest.showResponse("TTokenClient.requestAuthorizationCode() : ", response, entity);

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

	if (response.getLocation() != null) {
		try {
			final String location = response.getLocation().toString();
			final int fragmentIndex = location.indexOf("#");

			Map<String, String> params = new HashMap<String, String>();
			if (fragmentIndex != -1) {
				String fragment = location.substring(fragmentIndex + 1);
				params = QueryStringDecoder.decode(fragment);
			} else {
				int queryStringIndex = location.indexOf("?");
				if (queryStringIndex != -1) {
					String queryString = location.substring(queryStringIndex + 1);
					params = QueryStringDecoder.decode(queryString);
				}
			}

			assertNotNull(params.get("code"), "The code is null");
			assertNotNull(params.get("scope"), "The scope is null");
			assertNotNull(params.get("state"), "The state is null");

			token.setAuthorizationCode(params.get("code"));
			token.setScope(params.get("scope"));
		} catch (Exception e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:61,代码来源:TTokenRequest.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: requestUserInfoHS256Step2

import org.xdi.oxauth.client.AuthorizationRequest; //导入方法依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "requestUserInfoHS256Step1")
public void requestUserInfoHS256Step2(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);
	List<String> scopes = Arrays.asList("openid");
	String nonce = UUID.randomUUID().toString();

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

	OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();

	JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
			SignatureAlgorithm.HS256, clientSecret1, 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)));
	String authJwt = jwtAuthorizationRequest.getEncodedJwt();
	authorizationRequest.setRequest(authJwt);
	System.out.println("Request JWT: " + authJwt);

	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("requestUserInfoHS256Step2", 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(), "Query string is null");

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

		assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The accessToken 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);

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

示例14: requestUserInfoHS384Step2

import org.xdi.oxauth.client.AuthorizationRequest; //导入方法依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "requestUserInfoHS384Step1")
public void requestUserInfoHS384Step2(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);
	List<String> scopes = Arrays.asList("openid");
	String nonce = UUID.randomUUID().toString();

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

	OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();

	JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
			SignatureAlgorithm.HS384, clientSecret2, 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)));
	String authJwt = jwtAuthorizationRequest.getEncodedJwt();
	authorizationRequest.setRequest(authJwt);
	System.out.println("Request JWT: " + authJwt);

	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("requestUserInfoHS384Step2", 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(), "Query string is null");

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

		assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The accessToken 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);

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

示例15: requestUserInfoHS512Step2

import org.xdi.oxauth.client.AuthorizationRequest; //导入方法依赖的package包/类
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "requestUserInfoHS512Step1")
public void requestUserInfoHS512Step2(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);
	List<String> scopes = Arrays.asList("openid");
	String nonce = UUID.randomUUID().toString();

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

	OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();

	JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
			SignatureAlgorithm.HS512, clientSecret3, 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)));
	String authJwt = jwtAuthorizationRequest.getEncodedJwt();
	authorizationRequest.setRequest(authJwt);
	System.out.println("Request JWT: " + authJwt);

	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("requestUserInfoHS512Step2", 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(), "Query string is null");

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

		assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The accessToken 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);

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


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