147 List<ResponseType> responseTypes =
new ArrayList<ResponseType>();
148 responseTypes.add(ResponseType.CODE);
149 responseTypes.add(ResponseType.ID_TOKEN);
151 List<String> scopes =
new ArrayList<String>();
152 scopes.add(p_scopeType);
154 String state = UUID.randomUUID().toString();
155 String nonce = UUID.randomUUID().toString();
157 AuthorizationRequest authorizationRequest =
new AuthorizationRequest(responseTypes, umaClientId, scopes,
158 umaRedirectUri, nonce);
159 authorizationRequest.setState(state);
160 authorizationRequest.setAuthUsername(userId);
161 authorizationRequest.setAuthPassword(userSecret);
162 authorizationRequest.getPrompts().add(Prompt.NONE);
164 Builder request = ResteasyClientBuilder.newClient()
165 .target(
baseUri.toString() + authorizePath +
"?" + authorizationRequest.getQueryString()).request();
166 request.header(
"Authorization",
"Basic " + authorizationRequest.getEncodedCredentials());
167 request.header(
"Accept", MediaType.TEXT_PLAIN);
168 Response response = request.get();
169 String entity = response.readEntity(String.class);
171 BaseTest.showResponse(
"TTokenClient.requestAuthorizationCode() : ", response, entity);
173 assertEquals(response.getStatus(), 302,
"Unexpected response code.");
174 assertNotNull(response.getLocation(),
"Unexpected result: " + response.getLocation());
176 if (response.getLocation() != null) {
178 final String location = response.getLocation().toString();
179 final int fragmentIndex = location.indexOf(
"#");
181 Map<String, String> params =
new HashMap<String, String>();
182 if (fragmentIndex != -1) {
183 String fragment = location.substring(fragmentIndex + 1);
184 params = QueryStringDecoder.decode(fragment);
186 int queryStringIndex = location.indexOf(
"?");
187 if (queryStringIndex != -1) {
188 String queryString = location.substring(queryStringIndex + 1);
189 params = QueryStringDecoder.decode(queryString);
193 assertNotNull(params.get(
"code"),
"The code is null");
194 assertNotNull(params.get(
"scope"),
"The scope is null");
195 assertNotNull(params.get(
"state"),
"The state is null");
199 }
catch (Exception e) {
201 fail(e.getMessage());
Token setScope(String p_scope)
Definition: Token.java:67
final URI baseUri
Definition: TTokenRequest.java:53
final Token token
Definition: TTokenRequest.java:54
Token setAuthorizationCode(String p_authorizationCode)
Definition: Token.java:40