Skip to content

Commit a503aa2

Browse files
committed
💥 splitting internal and external representations of login credentials
Signed-off-by: dseurotech <[email protected]>
1 parent a37a6f5 commit a503aa2

File tree

85 files changed

+631
-1489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+631
-1489
lines changed

commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@
3939
import org.eclipse.kapua.locator.KapuaLocator;
4040
import org.eclipse.kapua.model.id.KapuaId;
4141
import org.eclipse.kapua.model.query.KapuaQuery;
42-
import org.eclipse.kapua.service.account.AccountFactory;
4342
import org.eclipse.kapua.service.account.AccountListResult;
4443
import org.eclipse.kapua.service.account.AccountService;
4544
import org.eclipse.kapua.service.endpoint.EndpointInfo;
46-
import org.eclipse.kapua.service.endpoint.EndpointInfoFactory;
4745
import org.eclipse.kapua.service.endpoint.EndpointInfoListResult;
4846
import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;
4947
import org.eclipse.kapua.service.endpoint.EndpointInfoService;
@@ -68,9 +66,7 @@ public class CORSResponseFilter implements Filter {
6866

6967
private final KapuaLocator locator = KapuaLocator.getInstance();
7068
private final AccountService accountService = locator.getService(AccountService.class);
71-
private final AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
7269
private final EndpointInfoService endpointInfoService = locator.getService(EndpointInfoService.class);
73-
private final EndpointInfoFactory endpointInfoFactory = locator.getFactory(EndpointInfoFactory.class);
7470
private final KapuaRestFiltersSetting kapuaRestFiltersSetting = locator.getComponent(KapuaRestFiltersSetting.class);
7571
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
7672
private ScheduledFuture<?> refreshTask;

commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.eclipse.kapua.KapuaException;
1717
import org.eclipse.kapua.model.KapuaEntity;
18-
import org.eclipse.kapua.model.KapuaEntityFactory;
1918
import org.eclipse.kapua.model.id.KapuaId;
2019
import org.eclipse.kapua.model.query.KapuaListResult;
2120
import org.eclipse.kapua.model.query.KapuaQuery;
@@ -24,16 +23,12 @@
2423

2524
public class UsedEntitiesCounterImpl<
2625
E extends KapuaEntity,
27-
L extends KapuaListResult<E>,
28-
F extends KapuaEntityFactory<E>
29-
> implements UsedEntitiesCounter {
26+
L extends KapuaListResult<E>> implements UsedEntitiesCounter {
3027

31-
private final F factory;
3228
private final KapuaEntityRepository<E, L> entityRepository;
3329

34-
public UsedEntitiesCounterImpl(F factory,
30+
public UsedEntitiesCounterImpl(
3531
KapuaEntityRepository<E, L> entityRepository) {
36-
this.factory = factory;
3732
this.entityRepository = entityRepository;
3833
}
3934

commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@
1212
*******************************************************************************/
1313
package org.eclipse.kapua.commons.event;
1414

15+
import java.util.ArrayList;
16+
import java.util.HashSet;
17+
import java.util.List;
18+
import java.util.Set;
19+
import java.util.concurrent.Executors;
20+
import java.util.concurrent.ScheduledExecutorService;
21+
import java.util.concurrent.ScheduledFuture;
22+
import java.util.concurrent.TimeUnit;
23+
1524
import org.apache.commons.lang3.StringUtils;
1625
import org.eclipse.kapua.KapuaException;
1726
import org.eclipse.kapua.commons.core.ServiceModule;
1827
import org.eclipse.kapua.commons.jpa.JpaTxContext;
19-
import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl;
2028
import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository;
2129
import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl;
2230
import org.eclipse.kapua.event.ServiceEventBus;
@@ -27,15 +35,6 @@
2735
import org.slf4j.Logger;
2836
import org.slf4j.LoggerFactory;
2937

30-
import java.util.ArrayList;
31-
import java.util.HashSet;
32-
import java.util.List;
33-
import java.util.Set;
34-
import java.util.concurrent.Executors;
35-
import java.util.concurrent.ScheduledExecutorService;
36-
import java.util.concurrent.ScheduledFuture;
37-
import java.util.concurrent.TimeUnit;
38-
3938
/**
4039
* Base {@link ServiceModule} implementation to be used by the modules that listen for events.
4140
*
@@ -102,8 +101,8 @@ public void start() throws KapuaException {
102101
houseKeeperJob = new ServiceEventHousekeeper(
103102
new EventStoreServiceImpl(locator.getService(AuthorizationService.class),
104103
locator.getFactory(PermissionFactory.class),
105-
new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()), serviceEventModuleConfiguration.maxInsertAttempts),
106-
new EventStoreFactoryImpl(),
104+
new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()),
105+
serviceEventModuleConfiguration.maxInsertAttempts),
107106
new EventStoreRecordImplJpaRepository(serviceEventModuleConfiguration.getKapuaJpaRepositoryConfiguration())
108107
),
109108
serviceEventModuleConfiguration.getEntityManagerFactory(),

commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
*******************************************************************************/
1313
package org.eclipse.kapua.commons.service.event.store.internal;
1414

15+
import javax.inject.Inject;
16+
1517
import org.eclipse.kapua.KapuaException;
1618
import org.eclipse.kapua.commons.model.domains.Domains;
17-
import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory;
1819
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord;
1920
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator;
2021
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult;
@@ -30,8 +31,6 @@
3031
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
3132
import org.eclipse.kapua.storage.TxManager;
3233

33-
import javax.inject.Inject;
34-
3534
/**
3635
* {@link EventStoreService} implementation.
3736
*
@@ -43,20 +42,17 @@ public class EventStoreServiceImpl
4342
private final AuthorizationService authorizationService;
4443
private final PermissionFactory permissionFactory;
4544
private final TxManager txManager;
46-
private final EventStoreFactory entityFactory;
4745
private final EventStoreRecordRepository repository;
4846

4947
@Inject
5048
public EventStoreServiceImpl(
5149
AuthorizationService authorizationService,
5250
PermissionFactory permissionFactory,
5351
TxManager txManager,
54-
EventStoreFactory entityFactory,
5552
EventStoreRecordRepository repository) {
5653
this.authorizationService = authorizationService;
5754
this.permissionFactory = permissionFactory;
5855
this.txManager = txManager;
59-
this.entityFactory = entityFactory;
6056
this.repository = repository;
6157
}
6258

console/core/src/main/java/org/eclipse/kapua/app/console/core/filter/KapuaWebFilter.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
*******************************************************************************/
1313
package org.eclipse.kapua.app.console.core.filter;
1414

15+
import java.io.IOException;
16+
import java.util.Date;
17+
18+
import javax.servlet.FilterChain;
19+
import javax.servlet.ServletException;
20+
import javax.servlet.ServletRequest;
21+
import javax.servlet.ServletResponse;
22+
1523
import org.apache.shiro.SecurityUtils;
1624
import org.apache.shiro.authc.AuthenticationException;
1725
import org.apache.shiro.subject.Subject;
@@ -21,18 +29,11 @@
2129
import org.eclipse.kapua.commons.security.KapuaSession;
2230
import org.eclipse.kapua.locator.KapuaLocator;
2331
import org.eclipse.kapua.service.authentication.AuthenticationService;
24-
import org.eclipse.kapua.service.authentication.CredentialsFactory;
32+
import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl;
2533
import org.eclipse.kapua.service.authentication.token.AccessToken;
2634
import org.slf4j.Logger;
2735
import org.slf4j.LoggerFactory;
2836

29-
import javax.servlet.FilterChain;
30-
import javax.servlet.ServletException;
31-
import javax.servlet.ServletRequest;
32-
import javax.servlet.ServletResponse;
33-
import java.io.IOException;
34-
import java.util.Date;
35-
3637
/**
3738
* {@link ShiroFilter} override.
3839
* <p>
@@ -45,7 +46,6 @@ public class KapuaWebFilter extends ShiroFilter {
4546
private static final Logger LOG = LoggerFactory.getLogger(KapuaWebFilter.class);
4647

4748
private final AuthenticationService authenticationService = KapuaLocator.getInstance().getService(AuthenticationService.class);
48-
private final CredentialsFactory credentialsFactory = KapuaLocator.getInstance().getFactory(CredentialsFactory.class);
4949

5050
@Override
5151
protected void executeChain(ServletRequest request, ServletResponse response, FilterChain origChain)
@@ -85,8 +85,10 @@ protected KapuaSession getSession() {
8585
/**
8686
* Check the {@link AccessToken#getExpiresOn()} and refreshes it on behalf of the user.
8787
*
88-
* @param accessToken The {@link AccessToken} to check and refresh if needed.
89-
* @throws KapuaException If one of the checks fails or refreshing the token fails.
88+
* @param accessToken
89+
* The {@link AccessToken} to check and refresh if needed.
90+
* @throws KapuaException
91+
* If one of the checks fails or refreshing the token fails.
9092
* @since 2.0.0
9193
*/
9294
protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) throws KapuaException {
@@ -97,7 +99,8 @@ protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) thro
9799
Date now = new Date();
98100

99101
if (now.after(accessToken.getExpiresOn()) && now.before(accessToken.getRefreshExpiresOn())) {
100-
LOG.info("Refreshing AccessToken for user {} of scope {} expired on {} - token: {}", accessToken.getUserId(), accessToken.getScopeId(), accessToken.getExpiresOn(), accessToken.getTokenId());
102+
LOG.info("Refreshing AccessToken for user {} of scope {} expired on {} - token: {}", accessToken.getUserId(), accessToken.getScopeId(), accessToken.getExpiresOn(),
103+
accessToken.getTokenId());
101104

102105
// Remove logout the user to perform a new login with the refreshed token.
103106
SecurityUtils.getSubject().logout();
@@ -106,7 +109,7 @@ protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) thro
106109
AccessToken refreshAccessToken = authenticationService.refreshAccessToken(accessToken.getTokenId(), accessToken.getRefreshToken());
107110

108111
// Authenticate with the refreshed AccessToken
109-
authenticationService.authenticate(credentialsFactory.newAccessTokenCredentials(refreshAccessToken.getTokenId()));
112+
authenticationService.authenticate(new AccessTokenCredentialsImpl(refreshAccessToken.getTokenId()));
110113
} else if (now.after(accessToken.getRefreshExpiresOn())) {
111114
throw new AuthenticationException("AccessToken.refreshToken is expired!");
112115
}

console/core/src/main/java/org/eclipse/kapua/app/console/core/server/GwtAuthorizationServiceImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*******************************************************************************/
1313
package org.eclipse.kapua.app.console.core.server;
1414

15+
import java.util.concurrent.Callable;
16+
17+
import javax.servlet.http.HttpServletRequest;
18+
import javax.servlet.http.HttpSession;
19+
1520
import org.apache.shiro.SecurityUtils;
1621
import org.apache.shiro.session.Session;
1722
import org.apache.shiro.subject.Subject;
@@ -43,7 +48,6 @@
4348
import org.eclipse.kapua.service.account.Account;
4449
import org.eclipse.kapua.service.account.AccountService;
4550
import org.eclipse.kapua.service.authentication.AuthenticationService;
46-
import org.eclipse.kapua.service.authentication.CredentialsFactory;
4751
import org.eclipse.kapua.service.authentication.JwtCredentials;
4852
import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials;
4953
import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationErrorCodes;
@@ -70,10 +74,6 @@
7074
import org.slf4j.Logger;
7175
import org.slf4j.LoggerFactory;
7276

73-
import javax.servlet.http.HttpServletRequest;
74-
import javax.servlet.http.HttpSession;
75-
import java.util.concurrent.Callable;
76-
7777
public class GwtAuthorizationServiceImpl extends KapuaRemoteServiceServlet implements GwtAuthorizationService {
7878

7979
private static final long serialVersionUID = -3919578632016541047L;
@@ -87,7 +87,6 @@ public class GwtAuthorizationServiceImpl extends KapuaRemoteServiceServlet imple
8787
private static final AccountService ACCOUNT_SERVICE = LOCATOR.getService(AccountService.class);
8888

8989
private static final AuthenticationService AUTHENTICATION_SERVICE = LOCATOR.getService(AuthenticationService.class);
90-
private static final CredentialsFactory CREDENTIALS_FACTORY = LOCATOR.getFactory(CredentialsFactory.class);
9190

9291
private static final AccessInfoService ACCESS_INFO_SERVICE = LOCATOR.getService(AccessInfoService.class);
9392
private static final AccessPermissionService ACCESS_PERMISSION_SERVICE = LOCATOR.getService(AccessPermissionService.class);
@@ -114,7 +113,7 @@ public GwtSession login(GwtLoginCredential gwtLoginCredentials, boolean trustReq
114113
ArgumentValidator.notEmptyOrNull(gwtLoginCredentials.getPassword(), "loginCredentials.password");
115114

116115
// Parse Credentials
117-
UsernamePasswordCredentials usernamePasswordCredentials = CREDENTIALS_FACTORY.newUsernamePasswordCredentials(gwtLoginCredentials.getUsername(), gwtLoginCredentials.getPassword());
116+
UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(gwtLoginCredentials.getUsername(), gwtLoginCredentials.getPassword());
118117
usernamePasswordCredentials.setAuthenticationCode(gwtLoginCredentials.getAuthenticationCode());
119118
usernamePasswordCredentials.setTrustKey(gwtLoginCredentials.getTrustKey());
120119
usernamePasswordCredentials.setTrustMe(trustReq);
@@ -145,7 +144,7 @@ public GwtSession login(GwtJwtCredential gwtAccessTokenCredentials, GwtJwtIdToke
145144
ArgumentValidator.notEmptyOrNull(gwtJwtIdToken.getIdToken(), "jwtIdToken.idToken");
146145

147146
// Parse Credentials
148-
JwtCredentials jwtCredentials = CREDENTIALS_FACTORY.newJwtCredentials(gwtAccessTokenCredentials.getAccessToken(), gwtJwtIdToken.getIdToken());
147+
JwtCredentials jwtCredentials = new JwtCredentials(gwtAccessTokenCredentials.getAccessToken(), gwtJwtIdToken.getIdToken());
149148

150149
// Cleanup any previous session
151150
cleanupSession();

console/core/src/main/java/org/eclipse/kapua/app/console/core/shared/service/GwtAuthorizationService.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
*******************************************************************************/
1313
package org.eclipse.kapua.app.console.core.shared.service;
1414

15-
import com.google.gwt.user.client.rpc.RemoteService;
16-
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
1715
import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtJwtCredential;
1816
import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtJwtIdToken;
1917
import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtLoginCredential;
2018
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException;
2119
import org.eclipse.kapua.app.console.module.api.shared.model.session.GwtSession;
2220

21+
import com.google.gwt.user.client.rpc.RemoteService;
22+
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
23+
2324
/**
2425
* The client side stub for the RPC service.
2526
*/
@@ -29,21 +30,25 @@ public interface GwtAuthorizationService extends RemoteService {
2930
/**
3031
* Logins a session based on the given credentials. If credentials are correct a session is established and returned
3132
*
32-
* @param gwtLoginCredentials The credentials to authenticate
33+
* @param gwtLoginCredentials
34+
* The credentials to authenticate
3335
* @return The session info established.
34-
* @throws GwtKapuaException If credentials are not valid.
36+
* @throws GwtKapuaException
37+
* If credentials are not valid.
3538
* @since 1.0.0
3639
*/
3740
public GwtSession login(GwtLoginCredential gwtLoginCredentials, boolean trustReq) throws GwtKapuaException;
3841

3942
/**
40-
* Logins a session based on the given access token. If the access token is correct a session is established and returned.
41-
* An id token is also passed for identity information about the user.
43+
* Logins a session based on the given access token. If the access token is correct a session is established and returned. An id token is also passed for identity information about the user.
4244
*
43-
* @param gwtAccessTokenCredentials The access token to authenticate.
44-
* @param gwtJwtIdToken The id token which identifies the user.
45+
* @param gwtAccessTokenCredentials
46+
* The access token to authenticate.
47+
* @param gwtJwtIdToken
48+
* The id token which identifies the user.
4549
* @return The session info established.
46-
* @throws GwtKapuaException If the access token is not valid.
50+
* @throws GwtKapuaException
51+
* If the access token is not valid.
4752
* @since 1.0.0
4853
*/
4954
public GwtSession login(GwtJwtCredential gwtAccessTokenCredentials, GwtJwtIdToken gwtJwtIdToken) throws GwtKapuaException;
@@ -52,7 +57,8 @@ public interface GwtAuthorizationService extends RemoteService {
5257
* Return the currently authenticated user or null if no session has been established.
5358
*
5459
* @return The current active session or null if no session is active.
55-
* @throws GwtKapuaException FIXME: document this
60+
* @throws GwtKapuaException
61+
* FIXME: document this
5662
* @since 1.0.0
5763
*/
5864
public GwtSession getCurrentSession()
@@ -61,7 +67,8 @@ public GwtSession getCurrentSession()
6167
/**
6268
* Destroy the current active session.
6369
*
64-
* @throws GwtKapuaException FIXME: document this
70+
* @throws GwtKapuaException
71+
* FIXME: document this
6572
* @since 1.0.0
6673
*/
6774
public void logout()

console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,19 @@
7070
import org.eclipse.kapua.service.KapuaService;
7171
import org.eclipse.kapua.service.account.Account;
7272
import org.eclipse.kapua.service.account.AccountCreator;
73-
import org.eclipse.kapua.service.account.AccountFactory;
7473
import org.eclipse.kapua.service.account.AccountService;
7574
import org.eclipse.kapua.service.authorization.AuthorizationService;
7675
import org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException;
7776
import org.eclipse.kapua.service.authorization.permission.Permission;
7877
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
7978
import org.eclipse.kapua.service.authorization.role.RoleCreator;
80-
import org.eclipse.kapua.service.authorization.role.RoleFactory;
8179
import org.eclipse.kapua.service.authorization.role.RoleService;
8280
import org.eclipse.kapua.service.config.KapuaConfigurableService;
8381
import org.eclipse.kapua.service.endpoint.EndpointInfo;
84-
import org.eclipse.kapua.service.endpoint.EndpointInfoFactory;
8582
import org.eclipse.kapua.service.endpoint.EndpointInfoListResult;
8683
import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;
8784
import org.eclipse.kapua.service.endpoint.EndpointInfoService;
8885
import org.eclipse.kapua.service.user.User;
89-
import org.eclipse.kapua.service.user.UserFactory;
9086
import org.eclipse.kapua.service.user.UserListResult;
9187
import org.eclipse.kapua.service.user.UserQuery;
9288
import org.eclipse.kapua.service.user.UserService;
@@ -112,19 +108,15 @@ public class GwtAccountServiceImpl extends KapuaRemoteServiceServlet implements
112108
private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
113109

114110
private static final AccountService ACCOUNT_SERVICE = LOCATOR.getService(AccountService.class);
115-
private static final AccountFactory ACCOUNT_FACTORY = LOCATOR.getFactory(AccountFactory.class);
116111

117112
private static final EndpointInfoService ENDPOINT_INFO_SERVICE = LOCATOR.getService(EndpointInfoService.class);
118-
private static final EndpointInfoFactory ENDPOINT_INFO_FACTORY = LOCATOR.getFactory(EndpointInfoFactory.class);
119113
private static final AuthorizationService AUTHORIZATION_SERVICE = LOCATOR.getService(AuthorizationService.class);
120114

121115
private static final PermissionFactory PERMISSION_FACTORY = LOCATOR.getFactory(PermissionFactory.class);
122116

123117
private static final RoleService ROLE_SERVICE = LOCATOR.getService(RoleService.class);
124-
private static final RoleFactory ROLE_FACTORY = LOCATOR.getFactory(RoleFactory.class);
125118

126119
private static final UserService USER_SERVICE = LOCATOR.getService(UserService.class);
127-
private static final UserFactory USER_FACTORY = LOCATOR.getFactory(UserFactory.class);
128120

129121
@Override
130122
public GwtAccount create(GwtXSRFToken xsrfToken, GwtAccountCreator gwtAccountCreator)

0 commit comments

Comments
 (0)