|
24 | 24 | import eu.openanalytics.containerproxy.model.runtime.Proxy; |
25 | 25 | import eu.openanalytics.containerproxy.model.spec.ContainerSpec; |
26 | 26 | import eu.openanalytics.containerproxy.model.spec.ProxySpec; |
| 27 | +import eu.openanalytics.containerproxy.service.UserService; |
27 | 28 | import org.keycloak.KeycloakPrincipal; |
| 29 | +import org.springframework.security.core.Authentication; |
28 | 30 | import org.springframework.security.core.userdetails.User; |
29 | 31 | import org.springframework.security.ldap.userdetails.LdapUserDetails; |
30 | 32 | import org.springframework.security.saml.SAMLCredential; |
31 | 33 |
|
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.List; |
| 36 | + |
32 | 37 | public class SpecExpressionContext { |
33 | 38 |
|
34 | | - private ContainerSpec containerSpec; |
35 | | - private ProxySpec proxySpec; |
36 | | - private Proxy proxy; |
37 | | - private OpenIDAuthenticationBackend.CustomNameOidcUser oicdUser; |
38 | | - private KeycloakPrincipal keycloakUser; |
39 | | - private SAMLCredential samlCredential; |
40 | | - private LdapUserDetails ldapUser; |
| 39 | + private ContainerSpec containerSpec; |
| 40 | + private ProxySpec proxySpec; |
| 41 | + private Proxy proxy; |
| 42 | + private OpenIDAuthenticationBackend.CustomNameOidcUser oicdUser; |
| 43 | + private KeycloakPrincipal keycloakUser; |
| 44 | + private SAMLCredential samlCredential; |
| 45 | + private LdapUserDetails ldapUser; |
| 46 | + private List<String> groups; |
| 47 | + |
| 48 | + public ContainerSpec getContainerSpec() { |
| 49 | + return containerSpec; |
| 50 | + } |
| 51 | + |
| 52 | + public ProxySpec getProxySpec() { |
| 53 | + return proxySpec; |
| 54 | + } |
41 | 55 |
|
42 | | - public ContainerSpec getContainerSpec() { |
43 | | - return containerSpec; |
44 | | - } |
| 56 | + public Proxy getProxy() { |
| 57 | + return proxy; |
| 58 | + } |
45 | 59 |
|
46 | | - public ProxySpec getProxySpec() { |
47 | | - return proxySpec; |
48 | | - } |
| 60 | + public OpenIDAuthenticationBackend.CustomNameOidcUser getOidcUser() { |
| 61 | + return oicdUser; |
| 62 | + } |
49 | 63 |
|
50 | | - public Proxy getProxy() { |
51 | | - return proxy; |
52 | | - } |
| 64 | + public KeycloakPrincipal getKeycloakUser() { |
| 65 | + return keycloakUser; |
| 66 | + } |
53 | 67 |
|
54 | | - public OpenIDAuthenticationBackend.CustomNameOidcUser getOidcUser() { |
55 | | - return oicdUser; |
56 | | - } |
| 68 | + public SAMLCredential getSamlCredential() { |
| 69 | + return samlCredential; |
| 70 | + } |
57 | 71 |
|
58 | | - public KeycloakPrincipal getKeycloakUser() { |
59 | | - return keycloakUser; |
60 | | - } |
| 72 | + public LdapUserDetails getLdapUser() { |
| 73 | + return ldapUser; |
| 74 | + } |
61 | 75 |
|
62 | | - public SAMLCredential getSamlCredential() { |
63 | | - return samlCredential; |
64 | | - } |
| 76 | + public List<String> getGroups() { |
| 77 | + return groups; |
| 78 | + } |
65 | 79 |
|
66 | | - public LdapUserDetails getLdapUser() { |
67 | | - return ldapUser; |
68 | | - } |
| 80 | + public static SpecExpressionContext create(Object... objects) { |
| 81 | + SpecExpressionContext ctx = new SpecExpressionContext(); |
| 82 | + for (Object o : objects) { |
| 83 | + if (o instanceof ContainerSpec) { |
| 84 | + ctx.containerSpec = (ContainerSpec) o; |
| 85 | + } else if (o instanceof ProxySpec) { |
| 86 | + ctx.proxySpec = (ProxySpec) o; |
| 87 | + } else if (o instanceof Proxy) { |
| 88 | + ctx.proxy = (Proxy) o; |
| 89 | + } else if (o instanceof OpenIDAuthenticationBackend.CustomNameOidcUser) { |
| 90 | + ctx.oicdUser = (OpenIDAuthenticationBackend.CustomNameOidcUser) o; |
| 91 | + } else if (o instanceof KeycloakPrincipal) { |
| 92 | + ctx.keycloakUser = (KeycloakPrincipal) o; |
| 93 | + } else if (o instanceof SAMLCredential) { |
| 94 | + ctx.samlCredential = (SAMLCredential) o; |
| 95 | + } else if (o instanceof LdapUserDetails) { |
| 96 | + ctx.ldapUser = (LdapUserDetails) o; |
| 97 | + } |
| 98 | + if (o instanceof Authentication) { |
| 99 | + ctx.groups = Arrays.asList(UserService.getGroups((Authentication) o)); |
| 100 | + } |
| 101 | + } |
| 102 | + return ctx; |
| 103 | + } |
69 | 104 |
|
70 | | - public static SpecExpressionContext create(Object...objects) { |
71 | | - SpecExpressionContext ctx = new SpecExpressionContext(); |
72 | | - for (Object o: objects) { |
73 | | - if (o instanceof ContainerSpec) { |
74 | | - ctx.containerSpec = (ContainerSpec) o; |
75 | | - } else if (o instanceof ProxySpec) { |
76 | | - ctx.proxySpec = (ProxySpec) o; |
77 | | - } else if (o instanceof Proxy) { |
78 | | - ctx.proxy = (Proxy) o; |
79 | | - } else if (o instanceof OpenIDAuthenticationBackend.CustomNameOidcUser) { |
80 | | - ctx.oicdUser = (OpenIDAuthenticationBackend.CustomNameOidcUser) o; |
81 | | - } else if (o instanceof KeycloakPrincipal) { |
82 | | - ctx.keycloakUser = (KeycloakPrincipal) o; |
83 | | - } else if (o instanceof SAMLCredential) { |
84 | | - ctx.samlCredential = (SAMLCredential) o; |
85 | | - } else if (o instanceof LdapUserDetails) { |
86 | | - ctx.ldapUser = (LdapUserDetails) o; |
87 | | - } |
88 | | - } |
89 | | - return ctx; |
90 | | - } |
91 | 105 | } |
0 commit comments