Commit b6cfef28 authored by michael.simon's avatar michael.simon
Browse files

redirect after service register

parent 294a825e
......@@ -10,7 +10,7 @@ public interface SamlIdpService {
long registerAuthnRequest(AuthnRequest authnRequest);
void resumeAuthnRequest(Long authnRequestId, Long userId, Long authnRequestIdpConfigId,
String resumeAuthnRequest(Long authnRequestId, Long userId, Long authnRequestIdpConfigId,
HttpServletResponse resonse) throws SamlAuthenticationException;
}
......@@ -132,7 +132,7 @@ public class SamlIdpServiceImpl implements SamlIdpService {
}
@Override
public void resumeAuthnRequest(Long authnRequestId, Long userId,
public String resumeAuthnRequest(Long authnRequestId, Long userId,
Long authnRequestIdpConfigId, HttpServletResponse response) throws SamlAuthenticationException {
SamlIdpConfigurationEntity idpConfig = idpConfigDao.findById(authnRequestIdpConfigId);
......@@ -155,15 +155,9 @@ public class SamlIdpServiceImpl implements SamlIdpService {
logger.debug("Service for SP found: {}", service);
RegistryEntity registry = registryDao.findByServiceAndUserAndStatus(service, user, RegistryStatus.ACTIVE);
if (registry == null) {
try {
logger.info("No active registration for user {} and service {}, redirecting to register page",
user.getEppn(), service.getName());
response.sendRedirect("/user/register-service.xhtml?serviceId=" + service.getId());
return;
} catch (IOException e) {
logger.warn("Cannot send to register page", e);
throw new SamlAuthenticationException("Cannot send to register page");
}
logger.info("No active registration for user {} and service {}, redirecting to register page",
user.getEppn(), service.getName());
return "/user/register-service.xhtml?serviceId=" + service.getId();
}
}
......@@ -247,6 +241,8 @@ public class SamlIdpServiceImpl implements SamlIdpService {
try {
postEncoder.initialize();
postEncoder.encode();
return null;
} catch (MessageEncodingException | ComponentInitializationException e) {
logger.warn("Exception occured", e);
throw new SamlAuthenticationException(e);
......
......@@ -241,15 +241,22 @@ public class RegisterServiceBean implements Serializable {
return null;
}
if (service.getServiceProps().containsKey("redirect_after_register")) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
try {
try {
if (service.getServiceProps().containsKey("redirect_after_register")) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.redirect(service.getServiceProps().get("redirect_after_register"));
sessionManager.setOriginalRequestPath(null);
return null;
} catch (IOException e) {
logger.info("Could not redirect client", e);
}
}
}
else if (sessionManager.getOriginalRequestPath() != null) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.redirect(sessionManager.getOriginalRequestPath());
sessionManager.setOriginalRequestPath(null);
return null;
}
} catch (IOException e) {
logger.info("Could not redirect client", e);
}
return ViewIds.INDEX_USER + "?faces-redirect=true";
}
......
......@@ -175,11 +175,12 @@ public class RegisterUserBean implements Serializable {
sessionManager.setUserId(entity.getId());
if (sessionManager.getOriginalRequestPath() != null) {
String orig = sessionManager.getOriginalRequestPath();
sessionManager.setOriginalRequestPath(null);
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
try {
externalContext.redirect(sessionManager.getOriginalRequestPath());
externalContext.redirect(orig);
} catch (IOException e) {
messageGenerator.addResolvedErrorMessage("error_msg", e.toString(), false);
}
......
......@@ -50,8 +50,13 @@ public class Saml2IdpRedirectResponseHandler {
}
try {
samlIdpService.resumeAuthnRequest(session.getAuthnRequestId(), session.getUserId(),
session.getAuthnRequestIdpConfigId(), response);
String redirect = samlIdpService.resumeAuthnRequest(session.getAuthnRequestId(), session.getUserId(),
session.getAuthnRequestIdpConfigId(), response);
if (redirect != null) {
session.setOriginalRequestPath(request.getRequestURI());
response.sendRedirect(redirect);
}
} catch (SamlAuthenticationException e) {
throw new ServletException(e);
}
......
......@@ -157,8 +157,9 @@ public class Saml2PostHandler {
session.setLocale(user.getLocale());
if (session.getOriginalRequestPath() != null) {
String orig = session.getOriginalRequestPath();
session.setOriginalRequestPath(null);
response.sendRedirect(session.getOriginalRequestPath());
response.sendRedirect(orig);
}
else
response.sendRedirect("/index.xhtml");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment