SimpUser exposes Principal
Closes gh-25191
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.Principal;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -310,6 +311,12 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Principal getPrincipal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSessions() {
|
||||
if (this.sessionLookup != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -33,6 +34,15 @@ public interface SimpUser {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Return the user associated with the session, if available. Typically, the
|
||||
* user information is available unless the user is connected to a different
|
||||
* server in a multi-server user registry scenario.
|
||||
* @since 5.3
|
||||
*/
|
||||
@Nullable
|
||||
Principal getPrincipal();
|
||||
|
||||
/**
|
||||
* Whether the user has any sessions.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -41,6 +44,12 @@ public class TestSimpUser implements SimpUser {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Principal getPrincipal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SimpSession> getSessions() {
|
||||
return new HashSet<>(this.sessions.values());
|
||||
|
||||
Reference in New Issue
Block a user