Search in sources :

Example 96 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class PodcastReceiverAdminController method handleRequestInternal.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Integer channelId = ServletRequestUtils.getIntParameter(request, "channelId");
    if (request.getParameter("add") != null) {
        String url = StringUtils.trim(request.getParameter("add"));
        podcastService.createChannel(url);
        return new ModelAndView(new RedirectView("podcastChannels.view"));
    }
    if (request.getParameter("downloadEpisode") != null) {
        download(StringUtil.parseInts(request.getParameter("downloadEpisode")));
        return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
    }
    if (request.getParameter("deleteChannel") != null) {
        podcastService.deleteChannel(channelId);
        return new ModelAndView(new RedirectView("podcastChannels.view"));
    }
    if (request.getParameter("deleteEpisode") != null) {
        for (int episodeId : StringUtil.parseInts(request.getParameter("deleteEpisode"))) {
            podcastService.deleteEpisode(episodeId, true);
        }
        return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
    }
    if (request.getParameter("refresh") != null) {
        if (channelId != null) {
            podcastService.refreshChannel(channelId, true);
            return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
        } else {
            podcastService.refreshAllChannels(true);
            return new ModelAndView(new RedirectView("podcastChannels.view"));
        }
    }
    return new ModelAndView(new RedirectView("podcastChannels.view"));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 97 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class NowPlayingController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Player player = playerService.getPlayer(request, response);
    List<TransferStatus> statuses = statusService.getStreamStatusesForPlayer(player);
    MediaFile current = statuses.isEmpty() ? null : mediaFileService.getMediaFile(statuses.get(0).getFile());
    MediaFile dir = current == null ? null : mediaFileService.getParentOf(current);
    String url;
    if (dir != null && !mediaFileService.isRoot(dir)) {
        url = "main.view?id=" + dir.getId();
    } else {
        url = "home.view";
    }
    return new ModelAndView(new RedirectView(url));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) TransferStatus(org.libresonic.player.domain.TransferStatus) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 98 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class LoginController method login.

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // Auto-login if "user" and "password" parameters are given.
    String username = request.getParameter("user");
    String password = request.getParameter("password");
    if (username != null && password != null) {
        username = StringUtil.urlEncode(username);
        password = StringUtil.urlEncode(password);
        return new ModelAndView(new RedirectView("/login?" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY + "=" + username + "&" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + "=" + password));
    }
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("logout", request.getParameter("logout") != null);
    map.put("error", request.getParameter("error") != null);
    map.put("brand", settingsService.getBrand());
    map.put("loginMessage", settingsService.getLoginMessage());
    User admin = securityService.getUserByName(User.USERNAME_ADMIN);
    if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
        map.put("insecure", true);
    }
    return new ModelAndView("login", "model", map);
}
Also used : User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 99 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class DelegatedClientNavigationController method redirectToProvider.

/**
 * Redirect to provider. Receive the client name from the request and then try to determine and build the endpoint url
 * for the redirection. The redirection data/url must contain a delegated client ticket id so that the request be can
 * restored on the trip back. SAML clients use the relay-state session attribute while others use request parameters.
 *
 * @param request  the request
 * @param response the response
 * @return the view
 */
@GetMapping(ENDPOINT_REDIRECT)
public View redirectToProvider(final HttpServletRequest request, final HttpServletResponse response) {
    final String clientName = request.getParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER);
    try {
        final IndirectClient client = (IndirectClient<Credentials, CommonProfile>) this.clients.findClient(clientName);
        final J2EContext webContext = Pac4jUtils.getPac4jJ2EContext(request, response);
        final Ticket ticket = delegatedClientWebflowManager.store(webContext, client);
        final View result;
        final RedirectAction action = client.getRedirectAction(webContext);
        if (RedirectAction.RedirectType.SUCCESS.equals(action.getType())) {
            result = new DynamicHtmlView(action.getContent());
        } else {
            final URIBuilder builder = new URIBuilder(action.getLocation());
            final String url = builder.toString();
            LOGGER.debug("Redirecting client [{}] to [{}] based on identifier [{}]", client.getName(), url, ticket.getId());
            result = new RedirectView(url);
        }
        this.delegatedSessionCookieManager.store(webContext);
        return result;
    } catch (final HttpAction e) {
        if (e.getCode() == HttpStatus.UNAUTHORIZED.value()) {
            LOGGER.debug("Authentication request was denied from the provider [{}]", clientName, e);
        } else {
            LOGGER.warn(e.getMessage(), e);
        }
        throw new UnauthorizedServiceException(e.getMessage(), e);
    }
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) RedirectView(org.springframework.web.servlet.view.RedirectView) IndirectClient(org.pac4j.core.client.IndirectClient) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) J2EContext(org.pac4j.core.context.J2EContext) View(org.springframework.web.servlet.View) DynamicHtmlView(org.apereo.cas.web.view.DynamicHtmlView) RedirectView(org.springframework.web.servlet.view.RedirectView) DynamicHtmlView(org.apereo.cas.web.view.DynamicHtmlView) HttpAction(org.pac4j.core.exception.HttpAction) RedirectAction(org.pac4j.core.redirect.RedirectAction) URIBuilder(org.jasig.cas.client.util.URIBuilder) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 100 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class OAuth20AuthorizeControllerTests method verifyTokenRedirectToClientApproved.

@Test
public void verifyTokenRedirectToClientApproved() throws Exception {
    clearAllServices();
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.AUTHORIZE_URL);
    mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.TOKEN.name().toLowerCase());
    mockRequest.setServerName(CAS_SERVER);
    mockRequest.setServerPort(CAS_PORT);
    mockRequest.setScheme(CAS_SCHEME);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuthRegisteredService service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
    service.setBypassApprovalPrompt(false);
    this.servicesManager.save(service);
    final CasProfile profile = new CasProfile();
    profile.setId(ID);
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(FIRST_NAME_ATTRIBUTE, FIRST_NAME);
    attributes.put(LAST_NAME_ATTRIBUTE, LAST_NAME);
    profile.addAttributes(attributes);
    final MockHttpSession session = new MockHttpSession();
    mockRequest.setSession(session);
    session.putValue(Pac4jConstants.USER_PROFILES, profile);
    session.putValue(OAuth20Constants.BYPASS_APPROVAL_PROMPT, "true");
    final ModelAndView modelAndView = oAuth20AuthorizeEndpointController.handleRequest(mockRequest, mockResponse);
    final View view = modelAndView.getView();
    assertTrue(view instanceof RedirectView);
    final RedirectView redirectView = (RedirectView) view;
    final String redirectUrl = redirectView.getUrl();
    assertTrue(redirectUrl.startsWith(REDIRECT_URI + "#access_token="));
    final String code = StringUtils.substringBetween(redirectUrl, "#access_token=", "&token_type=bearer");
    final AccessToken accessToken = (AccessToken) this.ticketRegistry.getTicket(code);
    assertNotNull(accessToken);
    final Principal principal = accessToken.getAuthentication().getPrincipal();
    assertEquals(ID, principal.getId());
    final Map<String, Object> principalAttributes = principal.getAttributes();
    assertEquals(attributes.size(), principalAttributes.size());
    assertEquals(FIRST_NAME, principalAttributes.get(FIRST_NAME_ATTRIBUTE));
}
Also used : CasProfile(org.pac4j.cas.profile.CasProfile) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) View(org.springframework.web.servlet.View) AccessToken(org.apereo.cas.ticket.accesstoken.AccessToken) RedirectView(org.springframework.web.servlet.view.RedirectView) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)156 ModelAndView (org.springframework.web.servlet.ModelAndView)99 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)36 HashMap (java.util.HashMap)33 lombok.val (lombok.val)33 Test (org.junit.jupiter.api.Test)30 Test (org.junit.Test)25 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)23 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)23 View (org.springframework.web.servlet.View)19 CasProfile (org.pac4j.cas.profile.CasProfile)14 JEEContext (org.pac4j.core.context.JEEContext)14 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 MockHttpSession (org.springframework.mock.web.MockHttpSession)12 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 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