forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LPS-67348 Avoid deprecated method #122
Open
csierra
wants to merge
5
commits into
stian-sigvartsen:master
Choose a base branch
from
csierra:pr-461
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+293
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10e127b
LPS-67348 New exception for Liferay user creation problems with Googl…
stian-sigvartsen e0adb25
LPS-67348 Respect strangers policy when logging in using Google SSO
stian-sigvartsen 06aa980
LPS-67348 Render account creation error to user in popup window
stian-sigvartsen c4d6b67
LPS-67348 Capture context in the exception
9af3bde
LPS-67348 Avoid deprecated method
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...n/authentication/google/web/internal/portlet/action/GoogleLoginErrorMVCRenderCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
*/ | ||
|
||
package com.liferay.login.authentication.google.web.internal.portlet.action; | ||
|
||
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand; | ||
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderConstants; | ||
import com.liferay.portal.kernel.security.auth.PrincipalException; | ||
import com.liferay.portal.kernel.service.UserLocalService; | ||
import com.liferay.portal.kernel.theme.ThemeDisplay; | ||
import com.liferay.portal.kernel.util.Portal; | ||
import com.liferay.portal.kernel.util.PortletKeys; | ||
import com.liferay.portal.kernel.util.PrefsPropsUtil; | ||
import com.liferay.portal.kernel.util.WebKeys; | ||
|
||
import javax.portlet.PortletException; | ||
import javax.portlet.RenderRequest; | ||
import javax.portlet.RenderResponse; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* @author Stian Sigvartsen | ||
*/ | ||
@Component( | ||
immediate = true, | ||
property = { | ||
"javax.portlet.name=" + PortletKeys.FAST_LOGIN, | ||
"javax.portlet.name=" + PortletKeys.LOGIN, | ||
"mvc.command.name=/login/google_login_error" | ||
}, | ||
service = MVCRenderCommand.class | ||
) | ||
public class GoogleLoginErrorMVCRenderCommand implements MVCRenderCommand { | ||
|
||
@Override | ||
public String render( | ||
RenderRequest renderRequest, RenderResponse renderResponse) | ||
throws PortletException { | ||
|
||
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute( | ||
WebKeys.THEME_DISPLAY); | ||
|
||
boolean googleAuthEnabled = PrefsPropsUtil.getBoolean( | ||
themeDisplay.getCompanyId(), "google-auth-enabled", true); | ||
|
||
if (!googleAuthEnabled) { | ||
throw new PortletException( | ||
new PrincipalException.MustBeEnabled( | ||
themeDisplay.getCompanyId(), | ||
GoogleLoginAction.class.getName())); | ||
} | ||
|
||
HttpServletRequest httpServletRequest = _portal.getHttpServletRequest( | ||
renderRequest); | ||
|
||
HttpServletResponse httpServletResponse = | ||
_portal.getHttpServletResponse(renderResponse); | ||
|
||
try { | ||
RequestDispatcher requestDispatcher = | ||
_servletContext.getRequestDispatcher("/error.jsp"); | ||
|
||
requestDispatcher.forward(httpServletRequest, httpServletResponse); | ||
} | ||
catch (Exception e) { | ||
throw new PortletException("Unable to include error.jsp", e); | ||
} | ||
|
||
return MVCRenderConstants.MVC_PATH_VALUE_SKIP_DISPATCH; | ||
} | ||
|
||
@Reference | ||
private Portal _portal; | ||
|
||
@Reference( | ||
target = "(osgi.web.symbolicname=com.liferay.login.authentication.google.web)" | ||
) | ||
private ServletContext _servletContext; | ||
|
||
@Reference | ||
private UserLocalService _userLocalService; | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...pps/login/login-authentication-google-web/src/main/resources/META-INF/resources/error.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<%-- | ||
/** | ||
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
*/ | ||
--%> | ||
|
||
<%@ include file="/init.jsp" %> | ||
|
||
<div class="sheet sheet-lg"> | ||
<div class="sheet-header"> | ||
<div class="autofit-padded-no-gutters-x autofit-row"> | ||
<div class="autofit-col autofit-col-expand"> | ||
<h2 class="sheet-title"> | ||
<liferay-ui:message key="failed-to-sign-in-using-this-google-account" /> | ||
</h2> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="sheet-text"> | ||
<c:if test="<%= SessionErrors.contains(request, UserEmailAddressException.MustNotUseCompanyMx.class) %>"> | ||
<div class="alert alert-danger"> | ||
<liferay-ui:message key="this-google-account-cannot-be-used-to-register-a-new-user-because-its-email-domain-is-reserved" /> | ||
</div> | ||
</c:if> | ||
|
||
<c:if test="<%= SessionErrors.contains(request, StrangersNotAllowedException.class) %>"> | ||
<div class="alert alert-danger"> | ||
<liferay-ui:message key="only-known-users-are-allowed-to-sign-in-using-google" /> | ||
</div> | ||
</c:if> | ||
</div> | ||
|
||
<div class="sheet-footer"> | ||
<aui:button-row> | ||
<aui:button onClick="window.close();" value="close" /> | ||
</aui:button-row> | ||
</div> | ||
</div> |
26 changes: 26 additions & 0 deletions
26
...apps/login/login-authentication-google-web/src/main/resources/META-INF/resources/init.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<%-- | ||
/** | ||
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
*/ | ||
--%> | ||
|
||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
|
||
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ | ||
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> | ||
|
||
<%@ page import="com.liferay.portal.kernel.exception.UserEmailAddressException" %><%@ | ||
page import="com.liferay.portal.kernel.servlet.SessionErrors" %><%@ | ||
page import="com.liferay.portal.security.sso.google.exception.StrangersNotAllowedException" %> | ||
|
||
<portlet:defineObjects /> |
5 changes: 4 additions & 1 deletion
5
...apps/login/login-authentication-google-web/src/main/resources/content/Language.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
google=Google | ||
google=Google | ||
failed-to-sign-in-using-this-google-account=Failed to sign in using this Google account | ||
only-known-users-are-allowed-to-sign-in-using-google=Only known users are allowed to sign in using Google. | ||
this-google-account-cannot-be-used-to-register-a-new-user-because-its-email-domain-is-reserved=This google account cannot be used to register a new user because its email domain is reserved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...n/java/com/liferay/portal/security/sso/google/exception/StrangersNotAllowedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
*/ | ||
|
||
package com.liferay.portal.security.sso.google.exception; | ||
|
||
import com.liferay.portal.kernel.exception.PortalException; | ||
|
||
/** | ||
* @author Stian Sigvartsen | ||
*/ | ||
public class StrangersNotAllowedException extends PortalException { | ||
|
||
public StrangersNotAllowedException(long companyId) { | ||
super(String.format("Company %s does not allow strangers", companyId)); | ||
|
||
this.companyId = companyId; | ||
} | ||
|
||
public final long companyId; | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...oogle-api/src/main/resources/com/liferay/portal/security/sso/google/exception/packageinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version 1.0.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting this exception...
But it looks like we only support Portlet 2 still?
https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/service/impl/PortletLocalServiceImpl.java#L2508
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csierra If you agree I am going to leave this commit out because it is only available in the portlet 3.0 API. So we can backport easier. See @topolik 's comment on another use of portlet 3.0 in similar OpenId Connect code: brianchandotcom@24df85d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure... go ahead