Skip to content

Commit 2804022

Browse files
committed
Polish Login UI
1 parent 02476c2 commit 2804022

File tree

3 files changed

+7
-42
lines changed

3 files changed

+7
-42
lines changed

core/src/main/java/org/springframework/security/core/authority/AuthorityUtils.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.HashSet;
2323
import java.util.List;
2424
import java.util.Set;
25-
import java.util.stream.Stream;
2625

2726
import org.springframework.security.core.GrantedAuthority;
2827
import org.springframework.util.Assert;
@@ -69,42 +68,6 @@ public static Set<String> authorityListToSet(Collection<? extends GrantedAuthori
6968
return set;
7069
}
7170

72-
/**
73-
* Return a {@link Stream} containing only the authorities of the given type;
74-
* {@code "ROLE"}, {@code "SCOPE"}, or {@code "FACTOR"}.
75-
* @param type the authority type; {@code "ROLE"}, {@code "SCOPE"}, or
76-
* {@code "FACTOR"}
77-
* @param authorities the list of authorities
78-
* @return a {@link Stream} containing the authorities of the given type
79-
* @since 7.0
80-
*/
81-
public static Stream<GrantedAuthority> authoritiesOfType(String type, Collection<GrantedAuthority> authorities) {
82-
return authorities.stream().filter((a) -> a.getAuthority().startsWith(type + "_"));
83-
}
84-
85-
/**
86-
* Return the simple name of a {@link GrantedAuthority}, which is its name, less any
87-
* common prefix; that is, {@code ROLE_}, {@code SCOPE_}, or {@code FACTOR_}.
88-
* <p>
89-
* For example, if the authority is {@code ROLE_USER}, then the simple name is
90-
* {@code user}.
91-
* <p>
92-
* If the authority is {@code FACTOR_PASSWORD}, then the simple name is
93-
* {@code password}.
94-
* @param authority the granted authority
95-
* @return the simple name of the authority
96-
* @since 7.0
97-
*/
98-
public static String getSimpleName(GrantedAuthority authority) {
99-
String name = authority.getAuthority();
100-
for (String prefix : KNOWN_PREFIXES) {
101-
if (name.startsWith(prefix)) {
102-
return name.substring(prefix.length());
103-
}
104-
}
105-
return name;
106-
}
107-
10871
/**
10972
* Converts authorities into a List of GrantedAuthority objects.
11073
* @param authorities the authorities to convert

web/src/main/java/org/springframework/security/web/authentication/LoginUrlAuthenticationEntryPoint.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.springframework.core.log.LogMessage;
3434
import org.springframework.security.core.AuthenticationException;
3535
import org.springframework.security.core.GrantedAuthority;
36-
import org.springframework.security.core.authority.AuthorityUtils;
3736
import org.springframework.security.web.AuthenticationEntryPoint;
3837
import org.springframework.security.web.DefaultRedirectStrategy;
3938
import org.springframework.security.web.PortMapper;
@@ -75,6 +74,8 @@ public class LoginUrlAuthenticationEntryPoint implements AuthenticationEntryPoin
7574

7675
private static final Log logger = LogFactory.getLog(LoginUrlAuthenticationEntryPoint.class);
7776

77+
private static final String FACTOR_PREFIX = "FACTOR_";
78+
7879
private PortMapper portMapper = new PortMapperImpl();
7980

8081
private String loginFormUrl;
@@ -122,9 +123,9 @@ protected String determineUrlToUseForThisRequest(HttpServletRequest request, Htt
122123
if (CollectionUtils.isEmpty(authorities)) {
123124
return getLoginFormUrl();
124125
}
125-
Collection<String> factors = AuthorityUtils.authoritiesOfType("FACTOR", authorities)
126-
.map(AuthorityUtils::getSimpleName)
127-
.map((a) -> a.toLowerCase(Locale.ROOT))
126+
Collection<String> factors = authorities.stream()
127+
.filter((a) -> a.getAuthority().startsWith(FACTOR_PREFIX))
128+
.map((a) -> a.getAuthority().substring(FACTOR_PREFIX.length()).toLowerCase(Locale.ROOT))
128129
.toList();
129130
return UriComponentsBuilder.fromUriString(getLoginFormUrl()).queryParam("factor", factors).toUriString();
130131
}

web/src/main/java/org/springframework/security/web/authentication/ui/DefaultLoginPageGeneratingFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ private void initAuthFilter(UsernamePasswordAuthenticationFilter authFilter) {
125125

126126
/**
127127
* Use this {@link SecurityContextHolderStrategy} to retrieve authenticated users.
128-
* <p>Uses {@link SecurityContextHolder#getContextHolderStrategy()} by default.
128+
* <p>
129+
* Uses {@link SecurityContextHolder#getContextHolderStrategy()} by default.
129130
* @param securityContextHolderStrategy the strategy to use
130131
* @since 7.0
131132
*/

0 commit comments

Comments
 (0)