use of org.springframework.security.oauth2.common.json.JSONObject in project OpenClinica by OpenClinica.
the class RandomizeService method getRandomizationCode.
// Rest Call to OCUI to get Randomization
public String getRandomizationCode(EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans, RuleSetBean ruleSet) throws JSONException {
StudySubjectDAO ssdao = new StudySubjectDAO<>(ds);
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
// study subject oid
String identifier = ssBean.getOid();
StudyDAO sdao = new StudyDAO<>(ds);
StudyBean sBean = (StudyBean) sdao.findByPK(ssBean.getStudyId());
// site or study oid
String siteIdentifier = sBean.getOid();
// site or study name
String name = sBean.getName();
UserAccountDAO udao = new UserAccountDAO(ds);
int userId = 0;
if (eventCrfBean.getUpdaterId() == 0) {
userId = eventCrfBean.getOwnerId();
} else {
userId = eventCrfBean.getUpdaterId();
}
UserAccountBean uBean = (UserAccountBean) udao.findByPK(userId);
String user = uBean.getName();
// sBean should be parent study
// put randomization object in cache
StudyBean study = getParentStudy(sBean.getOid());
SeRandomizationDTO randomization = null;
try {
randomization = getCachedRandomizationDTOObject(study.getOid(), false);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String randomiseUrl = randomization.getUrl();
String username = randomization.getUsername();
String password = randomization.getPassword();
String timezone = "America/New_York";
// String randomiseUrl = "https://evaluation.sealedenvelope.com/redpill/seti2";
// String username = "oc";
// String password = "secret";
HttpHeaders headers = createHeaders(username, password);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// retrieve json object if Randomization exist ,otherwise return a null object
JSONObject jsonRandObject = retrieveARandomisation(randomiseUrl, ssBean, headers);
if (jsonRandObject != null) {
return (String) jsonRandObject.get("code");
} else {
// if Site identifier exists ,then update otherwise create new Site identifier
addOrUpdateASite(randomiseUrl, sBean, headers, timezone);
// send for Randomization
JSONObject jsonRandomisedObject = randomiseSubject(randomiseUrl, ssBean, sBean, headers, user, stratificationFactorBeans, eventCrfBean, ruleSet);
if (jsonRandomisedObject != null)
return (String) jsonRandomisedObject.get("code");
else
return "";
}
}
use of org.springframework.security.oauth2.common.json.JSONObject in project spring-security by spring-projects.
the class JwtIssuerReactiveAuthenticationManagerResolverTests method resolveWhenUsingTrustedIssuerThenReturnsAuthenticationManager.
@Test
public void resolveWhenUsingTrustedIssuerThenReturnsAuthenticationManager() throws Exception {
try (MockWebServer server = new MockWebServer()) {
String issuer = server.url("").toString();
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(JWK_SET));
JWSObject jws = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload(new JSONObject(Collections.singletonMap(JwtClaimNames.ISS, issuer))));
jws.sign(new RSASSASigner(TestKeys.DEFAULT_PRIVATE_KEY));
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver(issuer);
ReactiveAuthenticationManager authenticationManager = authenticationManagerResolver.resolve(null).block();
assertThat(authenticationManager).isNotNull();
BearerTokenAuthenticationToken token = withBearerToken(jws.serialize());
Authentication authentication = authenticationManager.authenticate(token).block();
assertThat(authentication).isNotNull();
assertThat(authentication.isAuthenticated()).isTrue();
}
}
use of org.springframework.security.oauth2.common.json.JSONObject in project spring-security by spring-projects.
the class NimbusOpaqueTokenIntrospectorTests method introspectWhenActiveTokenThenParsesValuesInResponse.
@Test
public void introspectWhenActiveTokenThenParsesValuesInResponse() {
Map<String, Object> introspectedValues = new HashMap<>();
introspectedValues.put(OAuth2TokenIntrospectionClaimNames.ACTIVE, true);
introspectedValues.put(OAuth2TokenIntrospectionClaimNames.AUD, Arrays.asList("aud"));
introspectedValues.put(OAuth2TokenIntrospectionClaimNames.NBF, 29348723984L);
RestOperations restOperations = mock(RestOperations.class);
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willReturn(response(new JSONObject(introspectedValues).toJSONString()));
OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token");
// @formatter:off
assertThat(authority.getAttributes()).isNotNull().containsEntry(OAuth2TokenIntrospectionClaimNames.ACTIVE, true).containsEntry(OAuth2TokenIntrospectionClaimNames.AUD, Arrays.asList("aud")).containsEntry(OAuth2TokenIntrospectionClaimNames.NBF, Instant.ofEpochSecond(29348723984L)).doesNotContainKey(OAuth2TokenIntrospectionClaimNames.CLIENT_ID).doesNotContainKey(OAuth2TokenIntrospectionClaimNames.SCOPE);
// @formatter:on
}
use of org.springframework.security.oauth2.common.json.JSONObject in project spring-security by spring-projects.
the class BearerTokenAuthenticationTests method constructorWhenDefaultParametersThenSetsPrincipalToAttributesCopy.
// gh-6843
@Test
public void constructorWhenDefaultParametersThenSetsPrincipalToAttributesCopy() {
JSONObject attributes = new JSONObject();
attributes.put("active", true);
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(attributes, null);
BearerTokenAuthentication token = new BearerTokenAuthentication(principal, this.token, null);
assertThat(token.getPrincipal()).isNotSameAs(attributes);
assertThat(token.getTokenAttributes()).isNotSameAs(attributes);
}
use of org.springframework.security.oauth2.common.json.JSONObject in project spring-security by spring-projects.
the class BearerTokenAuthenticationTests method toStringWhenAttributesContainsURLThenDoesNotFail.
// gh-6843
@Test
public void toStringWhenAttributesContainsURLThenDoesNotFail() throws Exception {
JSONObject attributes = new JSONObject(Collections.singletonMap("iss", new URL("https://idp.example.com")));
OAuth2AuthenticatedPrincipal principal = new DefaultOAuth2AuthenticatedPrincipal(attributes, null);
BearerTokenAuthentication token = new BearerTokenAuthentication(principal, this.token, null);
token.toString();
}
Aggregations