use of fi.otavanopisto.pyramus.rest.model.WhoAmI in project muikku by otavanopisto.
the class PyramusMocksRest method student1LoginMock.
public static void student1LoginMock() throws JsonProcessingException {
stubFor(get(urlEqualTo("/dnm")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("").withStatus(204)));
stubFor(get(urlMatching("/users/authorize.*")).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/login?_stg=rsp&code=1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
stubFor(post(urlEqualTo("/1/oauth/token")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"expires_in\":3600,\"refresh_token\":\"12312ewsdf34fsd234r43rfsw32rf33e\",\"access_token\":\"ur84ur839843ruwf39843ru39ru37y2e\"}").withStatus(200)));
List<String> emails = new ArrayList<String>();
emails.add("testuser@example.com");
WhoAmI whoAmI = new WhoAmI((long) 1, "Test", "User", emails);
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String whoAmIJson = objectMapper.writeValueAsString(whoAmI);
stubFor(get(urlEqualTo("/1/system/whoami")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(whoAmIJson).withStatus(200)));
}
use of fi.otavanopisto.pyramus.rest.model.WhoAmI in project muikku by otavanopisto.
the class PyramusMocksRest method adminLoginMock.
public static void adminLoginMock() throws JsonProcessingException {
stubFor(get(urlEqualTo("/dnm")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("").withStatus(204)));
stubFor(get(urlMatching("/users/authorize.*")).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/login?_stg=rsp&code=1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
stubFor(post(urlEqualTo("/1/oauth/token")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"expires_in\":3600,\"refresh_token\":\"12312ewsdf34fsd234r43rfsw32rf33e\",\"access_token\":\"ur84ur839843ruwf39843ru39ru37y2e\"}").withStatus(200)));
List<String> emails = new ArrayList<String>();
emails.add("admin@example.com");
WhoAmI whoAmI = new WhoAmI((long) 4, "Admin", "User", emails);
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String whoAmIJson = objectMapper.writeValueAsString(whoAmI);
stubFor(get(urlEqualTo("/1/system/whoami")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(whoAmIJson).withStatus(200)));
}
use of fi.otavanopisto.pyramus.rest.model.WhoAmI in project muikku by otavanopisto.
the class PyramusMocks method loginMock.
private static void loginMock(Long userId, String email, String firstName, String lastName) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
stubFor(get(urlEqualTo("/dnm")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("").withStatus(204)));
stubFor(get(urlMatching("/users/authorize.*")).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/login?_stg=rsp&code=1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
stubFor(post(urlEqualTo("/1/oauth/token")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"expires_in\":3600,\"refresh_token\":\"12312ewsdf34fsd234r43rfsw32rf33e\",\"access_token\":\"ur84ur839843ruwf39843ru39ru37y2e\"}").withStatus(200)));
List<String> emails = new ArrayList<String>();
emails.add(email);
WhoAmI whoAmI = new WhoAmI(userId, firstName, lastName, emails);
String whoAmIJson = objectMapper.writeValueAsString(whoAmI);
stubFor(get(urlEqualTo("/1/system/whoami")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(whoAmIJson).withStatus(200)));
stubFor(get(urlEqualTo("/users/logout.page?redirectUrl=https://dev.muikku.fi:" + System.getProperty("it.port.https"))).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/")));
}
use of fi.otavanopisto.pyramus.rest.model.WhoAmI in project muikku by otavanopisto.
the class PyramusAuthenticationStrategy method processResponse.
@Override
protected AuthenticationResult processResponse(AuthSource authSource, Map<String, String[]> requestParameters, OAuthService service, String[] requestedScopes) {
ObjectMapper objectMapper = new ObjectMapper();
String verifier = getFirstRequestParameter(requestParameters, "code");
Verifier v = new Verifier(verifier);
Token accessToken = service.getAccessToken(null, v);
PyramusAccessToken pyramusAccessToken;
try {
pyramusAccessToken = objectMapper.readValue(accessToken.getRawResponse(), PyramusAccessToken.class);
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(Calendar.SECOND, pyramusAccessToken.getExpiresIn());
Date expires = calendar.getTime();
sessionController.addOAuthAccessToken("pyramus", expires, accessToken.getToken(), pyramusAccessToken.getRefreshToken());
} catch (IOException e) {
logger.log(Level.SEVERE, "Token extraction failed a JSON parsing error", e);
return new AuthenticationResult(AuthenticationResult.Status.ERROR);
}
WhoAmI whoAmI = null;
OAuthRequest request = new OAuthRequest(Verb.GET, getWhoAmIUrl());
service.signRequest(accessToken, request);
Response response = request.send();
try {
whoAmI = objectMapper.readValue(response.getBody(), WhoAmI.class);
} catch (IOException e) {
logger.log(Level.SEVERE, "Logging in failed because of a JSON parsing exception", e);
return new AuthenticationResult(AuthenticationResult.Status.ERROR);
}
return processLogin(authSource, requestParameters, whoAmI.getId().toString(), whoAmI.getEmails(), whoAmI.getFirstName(), whoAmI.getLastName());
}
use of fi.otavanopisto.pyramus.rest.model.WhoAmI in project muikku by otavanopisto.
the class PyramusMocksRest method teacherLoginMock.
public static void teacherLoginMock() throws JsonProcessingException {
stubFor(get(urlEqualTo("/dnm")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("").withStatus(204)));
stubFor(get(urlMatching("/users/authorize.*")).willReturn(aResponse().withStatus(302).withHeader("Location", "http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/login?_stg=rsp&code=1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
stubFor(post(urlEqualTo("/1/oauth/token")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"expires_in\":3600,\"refresh_token\":\"12312ewsdf34fsd234r43rfsw32rf33e\",\"access_token\":\"ur84ur839843ruwf39843ru39ru37y2e\"}").withStatus(200)));
List<String> emails = new ArrayList<String>();
emails.add("teacher@example.com");
WhoAmI whoAmI = new WhoAmI((long) 2, "Teacher", "User", emails);
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String whoAmIJson = objectMapper.writeValueAsString(whoAmI);
stubFor(get(urlEqualTo("/1/system/whoami")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(whoAmIJson).withStatus(200)));
}
Aggregations