Skip to content

Package: GenericOpenIDService

GenericOpenIDService

nameinstructionbranchcomplexitylinemethod
GenericOpenIDService()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
GenericOpenIDService(OpenIDSetting, GenericOpenIDSetting)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAuthUri()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getLogoutUri()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getOpenIdConfPath()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getTokenUri()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getUserInfoUri()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
lambda$getAuthUri$0()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getLogoutUri$3()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getTokenUri$1()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$getUserInfoUri$2()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc and others.
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Red Hat Inc - initial API and implementation
12: * Eurotech
13: *******************************************************************************/
14: package org.eclipse.kapua.plugin.sso.openid.provider.generic;
15:
16: import com.google.common.base.Strings;
17: import org.eclipse.kapua.plugin.sso.openid.exception.OpenIDException;
18: import org.eclipse.kapua.plugin.sso.openid.exception.OpenIDIllegalArgumentException;
19: import org.eclipse.kapua.plugin.sso.openid.exception.uri.OpenIDIllegalUriException;
20: import org.eclipse.kapua.plugin.sso.openid.provider.AbstractOpenIDService;
21: import org.eclipse.kapua.plugin.sso.openid.provider.OpenIDUtils;
22: import org.eclipse.kapua.plugin.sso.openid.provider.generic.setting.GenericOpenIDSetting;
23: import org.eclipse.kapua.plugin.sso.openid.provider.generic.setting.GenericOpenIDSettingKeys;
24: import org.eclipse.kapua.plugin.sso.openid.provider.setting.OpenIDSetting;
25:
26: import java.net.URI;
27: import java.util.Optional;
28:
29: /**
30: * The generic OpenID service class.
31: */
32: public class GenericOpenIDService extends AbstractOpenIDService {
33:
34: private static final String AUTH_WELL_KNOWN_KEY = "authorization_endpoint";
35: private static final String LOGOUT_WELL_KNOWN_KEY = "end_session_endpoint";
36: private static final String USERINFO_WELL_KNOWN_KEY = "user_info_endpoint";
37: private static final String TOKEN_WELL_KNOWN_KEY = "token_endpoint";
38:
39: private final GenericOpenIDSetting genericSettings;
40:
41: public GenericOpenIDService() {
42: this(OpenIDSetting.getInstance(), GenericOpenIDSetting.getInstance());
43: }
44:
45: public GenericOpenIDService(final OpenIDSetting ssoSettings, final GenericOpenIDSetting genericSettings) {
46: super(ssoSettings);
47: this.genericSettings = genericSettings;
48: }
49:
50: @Override
51: protected String getAuthUri() throws OpenIDException {
52: try {
53: final Optional<URI> uri = OpenIDUtils.getConfigUri(AUTH_WELL_KNOWN_KEY, getOpenIdConfPath());
54: return uri.orElseThrow(() -> new OpenIDIllegalUriException(AUTH_WELL_KNOWN_KEY, null)).toString();
55: } catch (OpenIDException se) {
56: String authUri = genericSettings.getString(GenericOpenIDSettingKeys.SSO_OPENID_SERVER_ENDPOINT_AUTH);
57:• if (Strings.isNullOrEmpty(authUri)) {
58: throw se;
59: }
60: return authUri;
61: }
62: }
63:
64: @Override
65: protected String getTokenUri() throws OpenIDException {
66: try {
67: final Optional<URI> uri = OpenIDUtils.getConfigUri(TOKEN_WELL_KNOWN_KEY, getOpenIdConfPath());
68: return uri.orElseThrow(() -> new OpenIDIllegalUriException(TOKEN_WELL_KNOWN_KEY, null)).toString();
69: } catch (OpenIDException se) {
70: String tokenUri = genericSettings.getString(GenericOpenIDSettingKeys.SSO_OPENID_SERVER_ENDPOINT_TOKEN);
71:• if (Strings.isNullOrEmpty(tokenUri)) {
72: throw se;
73: }
74: return tokenUri;
75: }
76: }
77:
78: @Override
79: protected String getUserInfoUri() throws OpenIDException {
80: try {
81: final Optional<URI> uri = OpenIDUtils.getConfigUri(USERINFO_WELL_KNOWN_KEY, getOpenIdConfPath());
82: return uri.orElseThrow(() -> new OpenIDIllegalUriException(USERINFO_WELL_KNOWN_KEY, null)).toString();
83: } catch (OpenIDException se) {
84: String tokenUri = genericSettings.getString(GenericOpenIDSettingKeys.SSO_OPENID_SERVER_ENDPOINT_USERINFO);
85:• if (Strings.isNullOrEmpty(tokenUri)) {
86: throw se;
87: }
88: return tokenUri;
89: }
90: }
91:
92: @Override
93: protected String getLogoutUri() throws OpenIDException {
94: try {
95: final Optional<URI> uri = OpenIDUtils.getConfigUri(LOGOUT_WELL_KNOWN_KEY, getOpenIdConfPath());
96: return uri.orElseThrow(() -> new OpenIDIllegalUriException(LOGOUT_WELL_KNOWN_KEY, null)).toString();
97: } catch (OpenIDException se) {
98: String logoutUri = genericSettings.getString(GenericOpenIDSettingKeys.SSO_OPENID_SERVER_ENDPOINT_LOGOUT);
99:• if (Strings.isNullOrEmpty(logoutUri)) {
100: throw se;
101: }
102: return logoutUri;
103: }
104: }
105:
106: /**
107: * Get the OpenID configuration path.
108: *
109: * @return a String representing the OpenID configuration URL.
110: * @throws OpenIDIllegalArgumentException if it cannot retrieve the OpenID configuration path
111: */
112: private String getOpenIdConfPath() throws OpenIDIllegalArgumentException {
113: String issuerUri = genericSettings.getString(GenericOpenIDSettingKeys.SSO_OPENID_JWT_ISSUER_ALLOWED);
114:• if (Strings.isNullOrEmpty(issuerUri)) {
115: throw new OpenIDIllegalUriException(GenericOpenIDSettingKeys.SSO_OPENID_JWT_ISSUER_ALLOWED.key(), issuerUri);
116: }
117: return OpenIDUtils.getOpenIdConfPath(issuerUri);
118: }
119: }