mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
fix redirects on protected routes for anonymous user
This commit is contained in:
@@ -68,7 +68,7 @@ class App extends Component<Props> {
|
||||
content = <Loading />;
|
||||
} else if (error) {
|
||||
content = <ErrorPage title={t("app.error.title")} subtitle={t("app.error.subtitle")} error={error} />;
|
||||
} else {
|
||||
} else if (me) {
|
||||
content = <Main authenticated={authenticated} links={links} />;
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -26,9 +26,9 @@ import { connect } from "react-redux";
|
||||
import { WithTranslation, withTranslation } from "react-i18next";
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
import { getLogoutFailure, isAuthenticated, isLogoutPending, isRedirecting, logout } from "../modules/auth";
|
||||
import { getLogoutFailure, isLogoutPending, isRedirecting, logout } from "../modules/auth";
|
||||
import { ErrorPage, Loading } from "@scm-manager/ui-components";
|
||||
import { getLogoutLink } from "../modules/indexResource";
|
||||
import { getLoginLink, getLogoutLink } from "../modules/indexResource";
|
||||
|
||||
type Props = WithTranslation & {
|
||||
authenticated: boolean;
|
||||
@@ -61,7 +61,7 @@ class Logout extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: any) => {
|
||||
const authenticated = isAuthenticated(state);
|
||||
const authenticated = state.auth.me && !getLoginLink(state);
|
||||
const loading = isLogoutPending(state);
|
||||
const redirecting = isRedirecting(state);
|
||||
const error = getLogoutFailure(state);
|
||||
|
||||
@@ -32,8 +32,8 @@ import java.util.List;
|
||||
|
||||
public class AuthenticationRequestDto {
|
||||
|
||||
@FormParam("grant_type")
|
||||
@JsonProperty("grant_type")
|
||||
@FormParam("grantType")
|
||||
@JsonProperty("grantType")
|
||||
private String grantType;
|
||||
|
||||
@FormParam("username")
|
||||
@@ -69,7 +69,7 @@ public class AuthenticationRequestDto {
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
// password is currently the only valid grant_type
|
||||
// password is currently the only valid grantType
|
||||
return "password".equals(grantType) && !Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class IndexDtoGenerator extends HalAppenderMapper {
|
||||
builder.single(link("loginInfo", loginInfoUrl));
|
||||
}
|
||||
|
||||
if (SecurityUtils.getSubject().isAuthenticated() && !Authentications.isAuthenticatedSubjectAnonymous() || isAnonymousAccess()) {
|
||||
if (shouldAppendSubjectRelatedLinks()) {
|
||||
builder.single(link("me", resourceLinks.me().self()));
|
||||
|
||||
if (Authentications.isAuthenticatedSubjectAnonymous()) {
|
||||
@@ -122,7 +122,10 @@ public class IndexDtoGenerator extends HalAppenderMapper {
|
||||
return new IndexDto(builder.build(), embeddedBuilder.build(), scmContextProvider.getVersion());
|
||||
}
|
||||
|
||||
private boolean isAnonymousAccess() {
|
||||
return Authentications.isAuthenticatedSubjectAnonymous() && configuration.getAnonymousMode() == AnonymousMode.FULL;
|
||||
private boolean shouldAppendSubjectRelatedLinks() {
|
||||
return (SecurityUtils.getSubject().isAuthenticated()
|
||||
&& !Authentications.isAuthenticatedSubjectAnonymous())
|
||||
|| (Authentications.isAuthenticatedSubjectAnonymous()
|
||||
&& configuration.getAnonymousMode() == AnonymousMode.FULL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user