Skip to content

Commit 67b5c7d

Browse files
committed
UY-1204: refactor oauth servlet redirect into broswer based redirect.
1 parent 6d730a7 commit 67b5c7d

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

oauth/src/main/java/pl/edu/icm/unity/oauth/as/webauthz/OAuthAuthzUI.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import pl.edu.icm.unity.engine.api.idp.IdPEngine;
3636
import pl.edu.icm.unity.engine.api.policyAgreement.PolicyAgreementManagement;
3737
import pl.edu.icm.unity.engine.api.translation.out.TranslationResult;
38+
import pl.edu.icm.unity.engine.api.utils.FreemarkerAppHandler;
3839
import pl.edu.icm.unity.exceptions.EngineException;
3940
import pl.edu.icm.unity.oauth.as.OAuthASProperties;
4041
import pl.edu.icm.unity.oauth.as.OAuthAuthzContext;
@@ -84,6 +85,7 @@ public class OAuthAuthzUI extends UnityEndpointUIBase
8485
private IdentityParam identity;
8586
private ObjectFactory<PolicyAgreementScreen> policyAgreementScreenObjectFactory;
8687
private final OAuthIdpStatisticReporterFactory idpStatisticReporterFactory;
88+
private final FreemarkerAppHandler freemarkerHandler;
8789

8890
@Autowired
8991
public OAuthAuthzUI(MessageSource msg,
@@ -98,7 +100,8 @@ public OAuthAuthzUI(MessageSource msg,
98100
OAuthSessionService oauthSessionService,
99101
PolicyAgreementManagement policyAgreementsMan,
100102
ObjectFactory<PolicyAgreementScreen> policyAgreementScreenObjectFactory,
101-
OAuthIdpStatisticReporterFactory idpStatisticReporterFactory
103+
OAuthIdpStatisticReporterFactory idpStatisticReporterFactory,
104+
FreemarkerAppHandler freemarkerHandler
102105
)
103106
{
104107
super(msg, enquiryDialogLauncher);
@@ -114,6 +117,7 @@ public OAuthAuthzUI(MessageSource msg,
114117
this.policyAgreementsMan = policyAgreementsMan;
115118
this.policyAgreementScreenObjectFactory = policyAgreementScreenObjectFactory;
116119
this.idpStatisticReporterFactory = idpStatisticReporterFactory;
120+
this.freemarkerHandler = freemarkerHandler;
117121
}
118122

119123
@Override
@@ -238,7 +242,8 @@ private void showActiveValueSelectionScreen(ActiveValueSelectionConfig config)
238242

239243
private TranslationResult getTranslationResult(OAuthAuthzContext ctx) throws EopException
240244
{
241-
oauthResponseHandler = new OAuthResponseHandler(oauthSessionService, idpStatisticReporterFactory.getForEndpoint(endpointDescription.getEndpoint()));
245+
oauthResponseHandler = new OAuthResponseHandler(oauthSessionService,
246+
idpStatisticReporterFactory.getForEndpoint(endpointDescription.getEndpoint()), freemarkerHandler);
242247
try
243248
{
244249
return idpEngine.getUserInfo(ctx);

oauth/src/main/java/pl/edu/icm/unity/oauth/as/webauthz/OAuthAuthzWebEndpoint.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ public class OAuthAuthzWebEndpoint extends VaadinEndpoint
9292
private OAuthASProperties oauthProperties;
9393

9494
@Autowired
95-
public OAuthAuthzWebEndpoint(NetworkServer server, ApplicationContext applicationContext,
96-
FreemarkerAppHandler freemarkerHandler, @Qualifier("insecure") EntityManagement identitiesManagement,
97-
@Qualifier("insecure") AttributesManagement attributesManagement, PKIManagement pkiManagement,
98-
OAuthEndpointsCoordinator coordinator, ASConsentDeciderServletFactory dispatcherServletFactory,
99-
AdvertisedAddressProvider advertisedAddrProvider, MessageSource msg,
100-
RemoteRedirectedAuthnResponseProcessingFilter remoteAuthnResponseProcessingFilter, OAuthIdpStatisticReporterFactory idpReporterFactory)
95+
public OAuthAuthzWebEndpoint(NetworkServer server,
96+
ApplicationContext applicationContext,
97+
FreemarkerAppHandler freemarkerHandler,
98+
@Qualifier("insecure") EntityManagement identitiesManagement,
99+
@Qualifier("insecure") AttributesManagement attributesManagement,
100+
PKIManagement pkiManagement,
101+
OAuthEndpointsCoordinator coordinator,
102+
ASConsentDeciderServletFactory dispatcherServletFactory,
103+
AdvertisedAddressProvider advertisedAddrProvider,
104+
MessageSource msg,
105+
RemoteRedirectedAuthnResponseProcessingFilter remoteAuthnResponseProcessingFilter,
106+
OAuthIdpStatisticReporterFactory idpReporterFactory)
101107
{
102108
super(server, advertisedAddrProvider, msg, applicationContext, OAuthAuthzUI.class.getSimpleName(),
103109
OAUTH_UI_SERVLET_PATH, remoteAuthnResponseProcessingFilter);
@@ -188,7 +194,8 @@ protected ServletContextHandler getServletContextHandlerOverridable()
188194
getBootstrapHandler4Authn(OAUTH_ROUTING_SERVLET_PATH));
189195

190196
OAuthCancelHandler oAuthCancelHandler = new OAuthCancelHandler(
191-
new OAuthResponseHandler(oauthSessionService, idpReporterFactory.getForEndpoint(description.getEndpoint())));
197+
new OAuthResponseHandler(oauthSessionService,
198+
idpReporterFactory.getForEndpoint(description.getEndpoint()), freemarkerHandler));
192199
authenticationServlet.setCancelHandler(oAuthCancelHandler);
193200

194201
ServletHolder authnServletHolder = createVaadinServletHolder(authenticationServlet, true);

oauth/src/main/java/pl/edu/icm/unity/oauth/as/webauthz/OAuthResponseHandler.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
package pl.edu.icm.unity.oauth.as.webauthz;
66

77
import java.io.IOException;
8+
import java.io.PrintWriter;
9+
import java.util.HashMap;
10+
import java.util.Map;
811
import java.util.Optional;
912

1013
import com.nimbusds.oauth2.sdk.AuthorizationResponse;
11-
import com.nimbusds.oauth2.sdk.SerializeException;
1214
import com.vaadin.server.Page;
1315
import com.vaadin.server.SynchronizedRequestHandler;
1416
import com.vaadin.server.VaadinRequest;
1517
import com.vaadin.server.VaadinResponse;
1618
import com.vaadin.server.VaadinServletResponse;
1719
import com.vaadin.server.VaadinSession;
1820

19-
import pl.edu.icm.unity.oauth.as.OAuthIdpStatisticReporter;
21+
import pl.edu.icm.unity.engine.api.utils.FreemarkerAppHandler;
2022
import pl.edu.icm.unity.oauth.as.OAuthAuthzContext;
23+
import pl.edu.icm.unity.oauth.as.OAuthIdpStatisticReporter;
2124
import pl.edu.icm.unity.types.basic.idpStatistic.IdpStatistic.Status;
2225
import pl.edu.icm.unity.webui.LoginInProgressService.SignInContextSession;
2326
import pl.edu.icm.unity.webui.LoginInProgressService.VaadinContextSession;
@@ -32,11 +35,14 @@ public class OAuthResponseHandler
3235
{
3336
private final OAuthSessionService oauthSessionService;
3437
public final OAuthIdpStatisticReporter statReporter;
38+
private final FreemarkerAppHandler freemarkerHandler;
3539

36-
public OAuthResponseHandler(OAuthSessionService oauthSessionService, OAuthIdpStatisticReporter statReporter)
40+
public OAuthResponseHandler(OAuthSessionService oauthSessionService, OAuthIdpStatisticReporter statReporter,
41+
FreemarkerAppHandler freemarkerHandler)
3742
{
3843
this.oauthSessionService = oauthSessionService;
3944
this.statReporter = statReporter;
45+
this.freemarkerHandler = freemarkerHandler;
4046
}
4147

4248
public void returnOauthResponse(AuthorizationResponse oauthResponse, boolean destroySession) throws EopException
@@ -89,11 +95,12 @@ public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest re
8995
oauthSessionService.cleanupBeforeResponseSent(sessionAttributes);
9096
try
9197
{
92-
String redirectURL = oauthResponse.toURI().toString();
93-
response.sendRedirect(redirectURL);
94-
} catch (SerializeException e)
95-
{
96-
throw new IOException("Error: can not serialize error response", e);
98+
Map<String, String> data = new HashMap<>();
99+
data.put("redirectURL", oauthResponse.toURI().toString());
100+
101+
response.setContentType("application/xhtml+xml; charset=utf-8");
102+
PrintWriter writer = response.getWriter();
103+
freemarkerHandler.printGenericPage(writer, "oauthFinish.ftl", data);
97104
} finally
98105
{
99106
oauthSessionService.cleanupAfterResponseSent(sessionAttributes, destroySession);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<html>
4+
<head>
5+
<title></title>
6+
<meta http-equiv = "refresh" content = "0; url = ${redirectURL?xhtml}" />
7+
</head>
8+
</html>

0 commit comments

Comments
 (0)