Search in sources :

Example 46 with RedirectView

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);
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with RedirectView

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());
}
Also used : Locale(java.util.Locale) HttpServletRequest(javax.servlet.http.HttpServletRequest) OauthRegistrationForm(org.orcid.pojo.ajaxForm.OauthRegistrationForm) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Registration(org.orcid.pojo.ajaxForm.Registration) SessionStatus(org.springframework.web.bind.support.SessionStatus) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RedirectView(org.springframework.web.servlet.view.RedirectView) Principal(java.security.Principal) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 48 with RedirectView

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);
}
Also used : EditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.EditModel) ServiceEditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.ServiceEditModel) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ServiceEditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.ServiceEditModel)

Example 49 with RedirectView

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);
}
Also used : ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Date(java.util.Date) ServletException(javax.servlet.ServletException) Filter(org.opennms.web.filter.Filter) RedirectView(org.springframework.web.servlet.view.RedirectView) MissingParameterException(org.opennms.web.servlet.MissingParameterException) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria)

Example 50 with RedirectView

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);
}
Also used : ServletException(javax.servlet.ServletException) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) MissingParameterException(org.opennms.web.servlet.MissingParameterException) Date(java.util.Date)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)86 ModelAndView (org.springframework.web.servlet.ModelAndView)70 Test (org.junit.Test)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 HashMap (java.util.HashMap)18 View (org.springframework.web.servlet.View)17 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)8 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)8 DefaultUserApprovalHandler (org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler)8 ServletException (javax.servlet.ServletException)7 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 TokenGranter (org.springframework.security.oauth2.provider.TokenGranter)7 Principal (org.apereo.cas.authentication.principal.Principal)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)6 CasProfile (org.pac4j.cas.profile.CasProfile)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6