fix redirects on protected routes for anonymous user

This commit is contained in:
Eduard Heimbuch
2020-08-04 09:39:37 +02:00
parent 4c9e96f7e2
commit c8a111f78e
4 changed files with 13 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}