ODLPrincipal extends Principal 62/101162/1
authorPeter Puškár <ppuskar@frinx.io>
Tue, 17 May 2022 12:08:37 +0000 (14:08 +0200)
committerRobert Varga <nite@hq.sk>
Sat, 28 May 2022 18:23:17 +0000 (18:23 +0000)
JAX-RS SecurityContext returns ODLPrincipal when method getPrincipal() is called on SecurityContext.
Method getPrincipal() is returning object of type Principal.
Now we currently cannot cast this object to ODLPrincipal as ClassCastException is thrown,
that makes this completely unusable when using SecurityContext.
Principal.getName() is not providing enough information as it just returns toString() by default.

Signed-off-by: Peter Puškár <ppuskar@frinx.io>
Change-Id: Id17d3b6859732a61de9be48a7b46775c13de6f27
(cherry picked from commit 671e909aed32e3522139e98c0a73e850e0717a7b)

aaa-shiro/api/src/main/java/org/opendaylight/aaa/api/shiro/principal/ODLPrincipal.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/principal/ODLPrincipalImpl.java

index b816bff6a7e524c948b40231bd699e987b93fc67..1db25529f5106e1c66691f932357aeb8d902d847 100644 (file)
@@ -8,12 +8,13 @@
 
 package org.opendaylight.aaa.api.shiro.principal;
 
+import java.security.Principal;
 import java.util.Set;
 
 /**
  * Principal for authentication.
  */
-public interface ODLPrincipal {
+public interface ODLPrincipal extends Principal {
 
     /**
      * Extract username that is making the request.
index 7a3c9b75273013be36b88a03ba98ce17c1354565..239befd762a0486f7a05e165897719a3e5b8968d 100644 (file)
@@ -86,4 +86,9 @@ public final class ODLPrincipalImpl implements ODLPrincipal {
     public Set<String> getRoles() {
         return this.roles;
     }
+
+    @Override
+    public String getName() {
+        return getUserId();
+    }
 }