use of org.springframework.web.servlet.view.RedirectView in project ORCID-Source by ORCID.
the class OrcidInfo method publicPreviewRedir.
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[x]}")
public ModelAndView publicPreviewRedir(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") int pageNo, @RequestParam(value = "maxResults", defaultValue = "15") int maxResults, @PathVariable("orcid") String orcid) {
RedirectView rv = new RedirectView();
rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
rv.setUrl(getBasePath() + orcid.toUpperCase());
return new ModelAndView(rv);
}
use of org.springframework.web.servlet.view.RedirectView in project ORCID-Source by ORCID.
the class OauthRegistrationControllerTest method testStripHtmlFromNames.
@SuppressWarnings("unchecked")
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
HttpSession session = mock(HttpSession.class);
RequestInfoForm rf = new RequestInfoForm();
RedirectView mv = new RedirectView();
when(servletRequest.getSession()).thenReturn(session);
when(servletRequest.getSession().getAttribute("requestInfoForm")).thenReturn(rf);
when(authorizationEndpoint.approveOrDeny(Matchers.anyMap(), Matchers.anyMap(), Matchers.any(SessionStatus.class), Matchers.any(Principal.class))).thenReturn(mv);
when(authenticationManager.authenticate(Matchers.any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
@Override
public Authentication answer(InvocationOnMock invocation) throws Throwable {
OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
return mockedAuthentication;
}
});
Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
OauthRegistrationForm reg = new OauthRegistrationForm();
org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
fv.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
reg.setActivitiesVisibilityDefault(fv);
reg.setEmail(email);
reg.setEmailConfirm(email);
reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
reg.setPassword(Text.valueOf("1234abcd"));
reg.setPasswordConfirm(Text.valueOf("1234abcd"));
reg.setValNumClient(2L);
reg.setValNumServer(4L);
reg.setApproved(true);
Checkbox c = new Checkbox();
c.setValue(true);
reg.setTermsOfUse(c);
reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
reg.setPersistentTokenEnabled(true);
oauthRegistrationController.registerAndAuthorize(servletRequest, servletResponse, reg);
ArgumentCaptor<HttpServletRequest> argument1 = ArgumentCaptor.forClass(HttpServletRequest.class);
ArgumentCaptor<Registration> argument2 = ArgumentCaptor.forClass(Registration.class);
ArgumentCaptor<Boolean> argument3 = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<Locale> argument4 = ArgumentCaptor.forClass(Locale.class);
ArgumentCaptor<String> argument5 = ArgumentCaptor.forClass(String.class);
verify(registrationController).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture(), argument5.capture());
assertNotNull(argument2.getValue());
Registration registration = argument2.getValue();
assertEquals(email.getValue(), registration.getEmail().getValue());
assertEquals("Given Names", registration.getGivenNames().getValue());
assertEquals("Family Name", registration.getFamilyNames().getValue());
}
use of org.springframework.web.servlet.view.RedirectView in project opennms by OpenNMS.
the class ApplicationController method handleRequestInternal.
/**
* {@inheritDoc}
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String removeApplicationIdString = getNonEmptyParameter(request, "removeApplicationId");
String newApplicationName = getNonEmptyParameter(request, "newApplicationName");
String applicationIdString = getNonEmptyParameter(request, "applicationid");
String editString = getNonEmptyParameter(request, "edit");
String ifServiceIdString = getNonEmptyParameter(request, "ifserviceid");
if (removeApplicationIdString != null) {
m_adminApplicationService.removeApplication(removeApplicationIdString);
return new ModelAndView(new RedirectView("/admin/applications.htm", true));
}
if (newApplicationName != null) {
m_adminApplicationService.addNewApplication(newApplicationName);
/*
* We could be smart and take the user straight to the edit page
* for this new application, which would be great, however it's
* not so great if the site has a huge number of available
* applications and they need to edit application member services
* from the service pages. So, we don't do it.
*/
return new ModelAndView(new RedirectView("/admin/applications.htm", true));
}
if (applicationIdString != null && editString != null) {
String editAction = getNonEmptyParameter(request, "action");
if (editAction != null) {
String[] toAdd = request.getParameterValues("toAdd");
String[] toDelete = request.getParameterValues("toDelete");
m_adminApplicationService.performEdit(applicationIdString, editAction, toAdd, toDelete);
ModelAndView modelAndView = new ModelAndView(new RedirectView("/admin/applications.htm", true));
modelAndView.addObject("applicationid", applicationIdString);
modelAndView.addObject("edit", "edit");
return modelAndView;
}
EditModel model = m_adminApplicationService.findApplicationAndAllMonitoredServices(applicationIdString);
return new ModelAndView("/admin/editApplication", "model", model);
}
if (applicationIdString != null) {
return new ModelAndView("/admin/showApplication", "model", m_adminApplicationService.getApplication(applicationIdString));
}
if (ifServiceIdString != null && editString != null) {
String editAction = getNonEmptyParameter(request, "action");
if (editAction != null) {
String[] toAdd = request.getParameterValues("toAdd");
String[] toDelete = request.getParameterValues("toDelete");
m_adminApplicationService.performServiceEdit(ifServiceIdString, editAction, toAdd, toDelete);
ModelAndView modelAndView = new ModelAndView(new RedirectView("/admin/applications.htm", true));
modelAndView.addObject("ifserviceid", ifServiceIdString);
modelAndView.addObject("edit", "edit");
return modelAndView;
}
ServiceEditModel model = m_adminApplicationService.findServiceApplications(ifServiceIdString);
return new ModelAndView("/admin/editServiceApplications", "model", model);
}
List<OnmsApplication> sortedApplications = m_adminApplicationService.findAllApplications();
return new ModelAndView("/admin/applications", "applications", sortedApplications);
}
use of org.springframework.web.servlet.view.RedirectView in project opennms by OpenNMS.
the class AcknowledgeAlarmByFilterController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Acknowledge the events specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] filterStrings = request.getParameterValues("filter");
String action = request.getParameter("actionCode");
if (filterStrings == null) {
filterStrings = new String[0];
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "filter", "actionCode" });
}
// handle the filter parameters
ArrayList<Filter> filterArray = new ArrayList<>();
for (String filterString : filterStrings) {
Filter filter = AlarmUtil.getFilter(filterString, getServletContext());
if (filter != null) {
filterArray.add(filter);
}
}
Filter[] filters = filterArray.toArray(new Filter[filterArray.size()]);
OnmsCriteria criteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters));
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.acknowledgeMatchingAlarms(request.getRemoteUser(), new Date(), criteria);
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.unacknowledgeMatchingAlarms(criteria, request.getRemoteUser());
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
use of org.springframework.web.servlet.view.RedirectView in project opennms by OpenNMS.
the class AcknowledgeAlarmController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Acknowledge the alarms specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] alarmIdStrings = request.getParameterValues("alarm");
String action = request.getParameter("actionCode");
if (alarmIdStrings == null) {
throw new MissingParameterException("alarm", new String[] { "alarm", "actionCode" });
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "alarm", "actionCode" });
}
// convert the alarm id strings to ints
int[] alarmIds = new int[alarmIdStrings.length];
for (int i = 0; i < alarmIds.length; i++) {
alarmIds[i] = WebSecurityUtils.safeParseInt(alarmIdStrings[i]);
}
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.acknowledgeAlarms(alarmIds, request.getRemoteUser(), new Date());
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.unacknowledgeAlarms(alarmIds, request.getRemoteUser());
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
Aggregations