diff --git a/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java b/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java index 903c784dac4..e510d42317d 100644 --- a/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java +++ b/commons-rest/filters/src/main/java/org/eclipse/kapua/commons/rest/filters/CORSResponseFilter.java @@ -39,11 +39,9 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaQuery; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.endpoint.EndpointInfo; -import org.eclipse.kapua.service.endpoint.EndpointInfoFactory; import org.eclipse.kapua.service.endpoint.EndpointInfoListResult; import org.eclipse.kapua.service.endpoint.EndpointInfoQuery; import org.eclipse.kapua.service.endpoint.EndpointInfoService; @@ -68,9 +66,7 @@ public class CORSResponseFilter implements Filter { private final KapuaLocator locator = KapuaLocator.getInstance(); private final AccountService accountService = locator.getService(AccountService.class); - private final AccountFactory accountFactory = locator.getFactory(AccountFactory.class); private final EndpointInfoService endpointInfoService = locator.getService(EndpointInfoService.class); - private final EndpointInfoFactory endpointInfoFactory = locator.getFactory(EndpointInfoFactory.class); private final KapuaRestFiltersSetting kapuaRestFiltersSetting = locator.getComponent(KapuaRestFiltersSetting.class); private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); private ScheduledFuture refreshTask; diff --git a/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java index 2f964e6cc6f..ef4870e1905 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/configuration/UsedEntitiesCounterImpl.java @@ -28,12 +28,10 @@ public class UsedEntitiesCounterImpl< F extends KapuaEntityFactory > implements UsedEntitiesCounter { - private final F factory; private final KapuaEntityRepository entityRepository; - public UsedEntitiesCounterImpl(F factory, + public UsedEntitiesCounterImpl( KapuaEntityRepository entityRepository) { - this.factory = factory; this.entityRepository = entityRepository; } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java index d043594a9bf..718dd069fdd 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventModule.java @@ -12,11 +12,19 @@ *******************************************************************************/ package org.eclipse.kapua.commons.event; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.core.ServiceModule; import org.eclipse.kapua.commons.jpa.JpaTxContext; -import org.eclipse.kapua.commons.service.event.store.internal.EventStoreFactoryImpl; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreRecordImplJpaRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.event.ServiceEventBus; @@ -27,15 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - /** * Base {@link ServiceModule} implementation to be used by the modules that listen for events. * @@ -102,8 +101,8 @@ public void start() throws KapuaException { houseKeeperJob = new ServiceEventHousekeeper( new EventStoreServiceImpl(locator.getService(AuthorizationService.class), locator.getFactory(PermissionFactory.class), - new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()), serviceEventModuleConfiguration.maxInsertAttempts), - new EventStoreFactoryImpl(), + new TxManagerImpl(() -> new JpaTxContext(serviceEventModuleConfiguration.getEntityManagerFactory().getJpaEntityManagerFactory()), + serviceEventModuleConfiguration.maxInsertAttempts), new EventStoreRecordImplJpaRepository(serviceEventModuleConfiguration.getKapuaJpaRepositoryConfiguration()) ), serviceEventModuleConfiguration.getEntityManagerFactory(), diff --git a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java index f4a1fa61807..3d2e6088a32 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/service/event/store/internal/EventStoreServiceImpl.java @@ -12,9 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.commons.service.event.store.internal; +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecord; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult; @@ -30,8 +31,6 @@ import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Inject; - /** * {@link EventStoreService} implementation. * @@ -43,7 +42,6 @@ public class EventStoreServiceImpl private final AuthorizationService authorizationService; private final PermissionFactory permissionFactory; private final TxManager txManager; - private final EventStoreFactory entityFactory; private final EventStoreRecordRepository repository; @Inject @@ -51,12 +49,10 @@ public EventStoreServiceImpl( AuthorizationService authorizationService, PermissionFactory permissionFactory, TxManager txManager, - EventStoreFactory entityFactory, EventStoreRecordRepository repository) { this.authorizationService = authorizationService; this.permissionFactory = permissionFactory; this.txManager = txManager; - this.entityFactory = entityFactory; this.repository = repository; } diff --git a/console/core/src/main/java/org/eclipse/kapua/app/console/core/filter/KapuaWebFilter.java b/console/core/src/main/java/org/eclipse/kapua/app/console/core/filter/KapuaWebFilter.java index 906f39f31b4..5bca4f5f791 100644 --- a/console/core/src/main/java/org/eclipse/kapua/app/console/core/filter/KapuaWebFilter.java +++ b/console/core/src/main/java/org/eclipse/kapua/app/console/core/filter/KapuaWebFilter.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.core.filter; +import java.io.IOException; +import java.util.Date; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.subject.Subject; @@ -21,18 +29,11 @@ import org.eclipse.kapua.commons.security.KapuaSession; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; +import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; import org.eclipse.kapua.service.authentication.token.AccessToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import java.io.IOException; -import java.util.Date; - /** * {@link ShiroFilter} override. *

@@ -45,7 +46,6 @@ public class KapuaWebFilter extends ShiroFilter { private static final Logger LOG = LoggerFactory.getLogger(KapuaWebFilter.class); private final AuthenticationService authenticationService = KapuaLocator.getInstance().getService(AuthenticationService.class); - private final CredentialsFactory credentialsFactory = KapuaLocator.getInstance().getFactory(CredentialsFactory.class); @Override protected void executeChain(ServletRequest request, ServletResponse response, FilterChain origChain) @@ -85,8 +85,10 @@ protected KapuaSession getSession() { /** * Check the {@link AccessToken#getExpiresOn()} and refreshes it on behalf of the user. * - * @param accessToken The {@link AccessToken} to check and refresh if needed. - * @throws KapuaException If one of the checks fails or refreshing the token fails. + * @param accessToken + * The {@link AccessToken} to check and refresh if needed. + * @throws KapuaException + * If one of the checks fails or refreshing the token fails. * @since 2.0.0 */ protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) throws KapuaException { @@ -97,7 +99,8 @@ protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) thro Date now = new Date(); if (now.after(accessToken.getExpiresOn()) && now.before(accessToken.getRefreshExpiresOn())) { - LOG.info("Refreshing AccessToken for user {} of scope {} expired on {} - token: {}", accessToken.getUserId(), accessToken.getScopeId(), accessToken.getExpiresOn(), accessToken.getTokenId()); + LOG.info("Refreshing AccessToken for user {} of scope {} expired on {} - token: {}", accessToken.getUserId(), accessToken.getScopeId(), accessToken.getExpiresOn(), + accessToken.getTokenId()); // Remove logout the user to perform a new login with the refreshed token. SecurityUtils.getSubject().logout(); @@ -106,7 +109,7 @@ protected void checkAndRefreshAccessTokenIfExpired(AccessToken accessToken) thro AccessToken refreshAccessToken = authenticationService.refreshAccessToken(accessToken.getTokenId(), accessToken.getRefreshToken()); // Authenticate with the refreshed AccessToken - authenticationService.authenticate(credentialsFactory.newAccessTokenCredentials(refreshAccessToken.getTokenId())); + authenticationService.authenticate(new AccessTokenCredentialsImpl(refreshAccessToken.getTokenId())); } else if (now.after(accessToken.getRefreshExpiresOn())) { throw new AuthenticationException("AccessToken.refreshToken is expired!"); } diff --git a/console/core/src/main/java/org/eclipse/kapua/app/console/core/server/GwtAuthorizationServiceImpl.java b/console/core/src/main/java/org/eclipse/kapua/app/console/core/server/GwtAuthorizationServiceImpl.java index 5fa08ddf2ba..6272d6f8d4c 100644 --- a/console/core/src/main/java/org/eclipse/kapua/app/console/core/server/GwtAuthorizationServiceImpl.java +++ b/console/core/src/main/java/org/eclipse/kapua/app/console/core/server/GwtAuthorizationServiceImpl.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.core.server; +import java.util.concurrent.Callable; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; @@ -43,7 +48,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.JwtCredentials; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationErrorCodes; @@ -70,10 +74,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import java.util.concurrent.Callable; - public class GwtAuthorizationServiceImpl extends KapuaRemoteServiceServlet implements GwtAuthorizationService { private static final long serialVersionUID = -3919578632016541047L; @@ -87,7 +87,6 @@ public class GwtAuthorizationServiceImpl extends KapuaRemoteServiceServlet imple private static final AccountService ACCOUNT_SERVICE = LOCATOR.getService(AccountService.class); private static final AuthenticationService AUTHENTICATION_SERVICE = LOCATOR.getService(AuthenticationService.class); - private static final CredentialsFactory CREDENTIALS_FACTORY = LOCATOR.getFactory(CredentialsFactory.class); private static final AccessInfoService ACCESS_INFO_SERVICE = LOCATOR.getService(AccessInfoService.class); private static final AccessPermissionService ACCESS_PERMISSION_SERVICE = LOCATOR.getService(AccessPermissionService.class); @@ -114,7 +113,7 @@ public GwtSession login(GwtLoginCredential gwtLoginCredentials, boolean trustReq ArgumentValidator.notEmptyOrNull(gwtLoginCredentials.getPassword(), "loginCredentials.password"); // Parse Credentials - UsernamePasswordCredentials usernamePasswordCredentials = CREDENTIALS_FACTORY.newUsernamePasswordCredentials(gwtLoginCredentials.getUsername(), gwtLoginCredentials.getPassword()); + UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(gwtLoginCredentials.getUsername(), gwtLoginCredentials.getPassword()); usernamePasswordCredentials.setAuthenticationCode(gwtLoginCredentials.getAuthenticationCode()); usernamePasswordCredentials.setTrustKey(gwtLoginCredentials.getTrustKey()); usernamePasswordCredentials.setTrustMe(trustReq); @@ -145,7 +144,7 @@ public GwtSession login(GwtJwtCredential gwtAccessTokenCredentials, GwtJwtIdToke ArgumentValidator.notEmptyOrNull(gwtJwtIdToken.getIdToken(), "jwtIdToken.idToken"); // Parse Credentials - JwtCredentials jwtCredentials = CREDENTIALS_FACTORY.newJwtCredentials(gwtAccessTokenCredentials.getAccessToken(), gwtJwtIdToken.getIdToken()); + JwtCredentials jwtCredentials = new JwtCredentials(gwtAccessTokenCredentials.getAccessToken(), gwtJwtIdToken.getIdToken()); // Cleanup any previous session cleanupSession(); diff --git a/console/core/src/main/java/org/eclipse/kapua/app/console/core/shared/service/GwtAuthorizationService.java b/console/core/src/main/java/org/eclipse/kapua/app/console/core/shared/service/GwtAuthorizationService.java index efff85f084d..3fce2532927 100644 --- a/console/core/src/main/java/org/eclipse/kapua/app/console/core/shared/service/GwtAuthorizationService.java +++ b/console/core/src/main/java/org/eclipse/kapua/app/console/core/shared/service/GwtAuthorizationService.java @@ -12,14 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.app.console.core.shared.service; -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtJwtCredential; import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtJwtIdToken; import org.eclipse.kapua.app.console.core.shared.model.authentication.GwtLoginCredential; import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException; import org.eclipse.kapua.app.console.module.api.shared.model.session.GwtSession; +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + /** * The client side stub for the RPC service. */ @@ -29,21 +30,25 @@ public interface GwtAuthorizationService extends RemoteService { /** * Logins a session based on the given credentials. If credentials are correct a session is established and returned * - * @param gwtLoginCredentials The credentials to authenticate + * @param gwtLoginCredentials + * The credentials to authenticate * @return The session info established. - * @throws GwtKapuaException If credentials are not valid. + * @throws GwtKapuaException + * If credentials are not valid. * @since 1.0.0 */ public GwtSession login(GwtLoginCredential gwtLoginCredentials, boolean trustReq) throws GwtKapuaException; /** - * 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. + * 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. * - * @param gwtAccessTokenCredentials The access token to authenticate. - * @param gwtJwtIdToken The id token which identifies the user. + * @param gwtAccessTokenCredentials + * The access token to authenticate. + * @param gwtJwtIdToken + * The id token which identifies the user. * @return The session info established. - * @throws GwtKapuaException If the access token is not valid. + * @throws GwtKapuaException + * If the access token is not valid. * @since 1.0.0 */ public GwtSession login(GwtJwtCredential gwtAccessTokenCredentials, GwtJwtIdToken gwtJwtIdToken) throws GwtKapuaException; @@ -52,7 +57,8 @@ public interface GwtAuthorizationService extends RemoteService { * Return the currently authenticated user or null if no session has been established. * * @return The current active session or null if no session is active. - * @throws GwtKapuaException FIXME: document this + * @throws GwtKapuaException + * FIXME: document this * @since 1.0.0 */ public GwtSession getCurrentSession() @@ -61,7 +67,8 @@ public GwtSession getCurrentSession() /** * Destroy the current active session. * - * @throws GwtKapuaException FIXME: document this + * @throws GwtKapuaException + * FIXME: document this * @since 1.0.0 */ public void logout() diff --git a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java index 4a8d97492cb..09168220937 100644 --- a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java +++ b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/server/GwtAccountServiceImpl.java @@ -70,23 +70,19 @@ import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authorization.AuthorizationService; import org.eclipse.kapua.service.authorization.exception.SubjectUnauthorizedException; import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.authorization.role.RoleCreator; -import org.eclipse.kapua.service.authorization.role.RoleFactory; import org.eclipse.kapua.service.authorization.role.RoleService; import org.eclipse.kapua.service.config.KapuaConfigurableService; import org.eclipse.kapua.service.endpoint.EndpointInfo; -import org.eclipse.kapua.service.endpoint.EndpointInfoFactory; import org.eclipse.kapua.service.endpoint.EndpointInfoListResult; import org.eclipse.kapua.service.endpoint.EndpointInfoQuery; import org.eclipse.kapua.service.endpoint.EndpointInfoService; import org.eclipse.kapua.service.user.User; -import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserListResult; import org.eclipse.kapua.service.user.UserQuery; import org.eclipse.kapua.service.user.UserService; @@ -112,19 +108,15 @@ public class GwtAccountServiceImpl extends KapuaRemoteServiceServlet implements private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); private static final AccountService ACCOUNT_SERVICE = LOCATOR.getService(AccountService.class); - private static final AccountFactory ACCOUNT_FACTORY = LOCATOR.getFactory(AccountFactory.class); private static final EndpointInfoService ENDPOINT_INFO_SERVICE = LOCATOR.getService(EndpointInfoService.class); - private static final EndpointInfoFactory ENDPOINT_INFO_FACTORY = LOCATOR.getFactory(EndpointInfoFactory.class); private static final AuthorizationService AUTHORIZATION_SERVICE = LOCATOR.getService(AuthorizationService.class); private static final PermissionFactory PERMISSION_FACTORY = LOCATOR.getFactory(PermissionFactory.class); private static final RoleService ROLE_SERVICE = LOCATOR.getService(RoleService.class); - private static final RoleFactory ROLE_FACTORY = LOCATOR.getFactory(RoleFactory.class); private static final UserService USER_SERVICE = LOCATOR.getService(UserService.class); - private static final UserFactory USER_FACTORY = LOCATOR.getFactory(UserFactory.class); @Override public GwtAccount create(GwtXSRFToken xsrfToken, GwtAccountCreator gwtAccountCreator) diff --git a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java index 666c0b4ef43..b0761ef13c2 100644 --- a/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java +++ b/console/module/account/src/main/java/org/eclipse/kapua/app/console/module/account/shared/util/GwtKapuaAccountModelConverter.java @@ -15,14 +15,12 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.kapua.app.console.module.account.shared.model.GwtAccountQuery; import org.eclipse.kapua.app.console.module.api.shared.util.GwtKapuaCommonsModelConverter; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.query.FieldSortCriteria; import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate.Operator; import org.eclipse.kapua.service.account.AccountAttributes; -import org.eclipse.kapua.service.account.AccountFactory; import com.extjs.gxt.ui.client.Style.SortDir; import com.extjs.gxt.ui.client.data.PagingLoadConfig; @@ -33,9 +31,6 @@ private GwtKapuaAccountModelConverter() { } public static KapuaQuery convertAccountQuery(PagingLoadConfig loadConfig, GwtAccountQuery gwtAccountQuery) { - KapuaLocator locator = KapuaLocator.getInstance(); - AccountFactory factory = locator.getFactory(AccountFactory.class); - KapuaQuery query = new KapuaQuery(GwtKapuaCommonsModelConverter.convertKapuaId(gwtAccountQuery.getScopeId())); AndPredicate predicate = query.andPredicate(); diff --git a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java index 7c113cb50e4..1e43a1c90d6 100644 --- a/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java +++ b/console/module/authentication/src/main/java/org/eclipse/kapua/app/console/module/authentication/server/GwtCredentialServiceImpl.java @@ -37,11 +37,9 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.query.KapuaQuery; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; -import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.shiro.utils.AuthenticationUtils; @@ -66,9 +64,6 @@ public class GwtCredentialServiceImpl extends KapuaRemoteServiceServlet implemen private static final AuthenticationService AUTHENTICATION_SERVICE = LOCATOR.getService(AuthenticationService.class); private static final CredentialService CREDENTIAL_SERVICE = LOCATOR.getService(CredentialService.class); - private static final CredentialFactory CREDENTIAL_FACTORY = LOCATOR.getFactory(CredentialFactory.class); - - private static final CredentialsFactory CREDENTIALS_FACTORY = LOCATOR.getFactory(CredentialsFactory.class); private static final UserService USER_SERVICE = LOCATOR.getService(UserService.class); @@ -207,7 +202,7 @@ public User call() throws Exception { } username = user.getName(); final String finalUsername = username; - UsernamePasswordCredentials loginCredentials = CREDENTIALS_FACTORY.newUsernamePasswordCredentials(finalUsername, oldPassword); + UsernamePasswordCredentials loginCredentials = new UsernamePasswordCredentials(finalUsername, oldPassword); loginCredentials.setAuthenticationCode(mfaCode); AUTHENTICATION_SERVICE.verifyCredentials(loginCredentials); diff --git a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java index 4d9ace768a2..ddad4bae88c 100644 --- a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java +++ b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/jaxb/JobEngineJAXBContextProvider.java @@ -40,7 +40,6 @@ import org.eclipse.kapua.job.engine.JobStartOptions; import org.eclipse.kapua.job.engine.commons.model.JobStepPropertiesOverrides; import org.eclipse.kapua.job.engine.commons.model.JobTargetSublist; -import org.eclipse.kapua.service.authentication.AuthenticationXmlRegistry; import org.eclipse.kapua.service.authentication.token.AccessToken; import org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration; import org.eclipse.kapua.service.device.management.asset.DeviceAssets; @@ -129,7 +128,6 @@ public JAXBContext getJAXBContext() throws KapuaException { JobStoppingExceptionInfo.class, // Authentication - AuthenticationXmlRegistry.class, AccessToken.class, // Device Management Keystore diff --git a/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java b/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java index 1adb387029e..dbe3ef150c4 100644 --- a/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java +++ b/qa/common/src/main/java/org/eclipse/kapua/qa/common/SimulatedDeviceSteps.java @@ -27,6 +27,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.stream.Collectors; +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.kura.simulator.GatewayConfiguration; import org.eclipse.kapua.kura.simulator.MqttAsyncTransport; @@ -36,7 +38,7 @@ import org.eclipse.kapua.kura.simulator.app.command.SimpleCommandApplication; import org.eclipse.kapua.kura.simulator.app.deploy.SimpleDeployApplication; import org.eclipse.kapua.locator.KapuaLocator; -import org.eclipse.kapua.service.authentication.CredentialsFactory; +import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.device.management.bundle.DeviceBundle; import org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService; import org.eclipse.kapua.service.device.management.bundle.DeviceBundles; @@ -61,8 +63,6 @@ import com.google.inject.Singleton; -import javax.inject.Inject; - import io.cucumber.java.After; import io.cucumber.java.Before; import io.cucumber.java.Scenario; @@ -122,7 +122,7 @@ public void setNodeUri(String nodeUri) { @Given("My credentials are username {string} and password {string}") public void setUsernamePasswordCredentials(String username, String password) { - session.setCredentials(KapuaLocator.getInstance().getFactory(CredentialsFactory.class).newUsernamePasswordCredentials(username, password)); + session.setCredentials(new UsernamePasswordCredentials(username, password)); } @When("I start the simulator") diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenAuthenticationRealmTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenAuthenticationRealmTest.java index 64164480fd4..931f586f52f 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenAuthenticationRealmTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenAuthenticationRealmTest.java @@ -23,7 +23,6 @@ import org.junit.experimental.categories.Category; import org.mockito.Mockito; - @Category(JUnitTests.class) public class AccessTokenAuthenticationRealmTest { diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenCredentialsMatcherTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenCredentialsMatcherTest.java index 81e54abca29..eca2d45fdee 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenCredentialsMatcherTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/AccessTokenCredentialsMatcherTest.java @@ -23,7 +23,6 @@ import org.junit.experimental.categories.Category; import org.mockito.Mockito; - @Category(JUnitTests.class) public class AccessTokenCredentialsMatcherTest { diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/EventStoreServiceImplTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/EventStoreServiceImplTest.java index 095fa1948a2..5ca301f0bb1 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/EventStoreServiceImplTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/EventStoreServiceImplTest.java @@ -15,7 +15,6 @@ import java.math.BigInteger; import org.eclipse.kapua.commons.model.id.KapuaEid; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; @@ -38,7 +37,6 @@ public void createTest() { Mockito.mock(AuthorizationService.class), Mockito.mock(PermissionFactory.class), Mockito.mock(TxManager.class), - Mockito.mock(EventStoreFactory.class), Mockito.mock(EventStoreRecordRepository.class)); EventStoreRecordCreator[] creator = { null, new EventStoreRecordCreator(new KapuaEid(BigInteger.ONE)) }; UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException(); diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/JwtAuthenticatingRealmTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/JwtAuthenticatingRealmTest.java index 83c2de6eb9c..ce7e4b8d018 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/JwtAuthenticatingRealmTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/JwtAuthenticatingRealmTest.java @@ -15,6 +15,7 @@ import org.apache.shiro.authc.AuthenticationToken; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.qa.markers.junit.JUnitTests; +import org.eclipse.kapua.service.authentication.JwtCredentials; import org.eclipse.kapua.service.authentication.shiro.JwtCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.realm.JwtAuthenticatingRealm; import org.junit.Assert; @@ -23,7 +24,6 @@ import org.junit.experimental.categories.Category; import org.mockito.Mockito; - @Category(JUnitTests.class) public class JwtAuthenticatingRealmTest { @@ -50,8 +50,8 @@ public void destroyNullJwtProcessorTest() throws Exception { @Test public void supportsTrueTest() { - JwtCredentialsImpl authenticationToken = new JwtCredentialsImpl("jwt", "token id"); - Assert.assertTrue("True expected.", jwtAuthenticatingRealm.supports(authenticationToken)); + JwtCredentials authenticationToken = new JwtCredentials("jwt", "token id"); + Assert.assertTrue("True expected.", jwtAuthenticatingRealm.supports(new JwtCredentialsImpl(authenticationToken))); } @Test diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/service/datastoreJunit/AbstractMessageStoreServiceTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/service/datastoreJunit/AbstractMessageStoreServiceTest.java index cc7b58c2f9e..194094a2710 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/service/datastoreJunit/AbstractMessageStoreServiceTest.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/service/datastoreJunit/AbstractMessageStoreServiceTest.java @@ -12,7 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.integration.service.datastoreJunit; -import com.google.common.base.MoreObjects; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Random; + import org.apache.commons.lang.RandomStringUtils; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.jpa.JdbcConnectionUrlResolvers; @@ -25,17 +29,14 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; +import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.junit.After; import org.junit.Before; import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Random; +import com.google.common.base.MoreObjects; @Category(JUnitTests.class) public abstract class AbstractMessageStoreServiceTest { @@ -69,8 +70,7 @@ public void setUp() throws SQLException { String password = "kapua-password"; AuthenticationService authenticationService = locator.getService(AuthenticationService.class); - CredentialsFactory credentialsFactory = locator.getFactory(CredentialsFactory.class); - authenticationService.login(credentialsFactory.newUsernamePasswordCredentials(username, password)); + authenticationService.login(new UsernamePasswordCredentials(username, password)); // Get current user Id adminUserId = KapuaSecurityUtils.getSession().getUserId(); adminScopeId = KapuaSecurityUtils.getSession().getScopeId(); @@ -106,9 +106,12 @@ public void tearDown() { /** * Generates a random {@link String} from the given parameters * - * @param chars length of the generated {@link String} - * @param letters whether or not use chars - * @param numbers whether or not use numbers + * @param chars + * length of the generated {@link String} + * @param letters + * whether or not use chars + * @param numbers + * whether or not use numbers * @return the generated {@link String} */ private static String generateRandomString(int chars, boolean letters, boolean numbers) { diff --git a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/auth/KapuaTokenAuthenticationFilter.java b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/auth/KapuaTokenAuthenticationFilter.java index 59dfe9951e8..908c07ebb96 100644 --- a/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/auth/KapuaTokenAuthenticationFilter.java +++ b/rest-api/core/src/main/java/org/eclipse/kapua/app/api/core/auth/KapuaTokenAuthenticationFilter.java @@ -12,36 +12,31 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.core.auth; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.web.filter.authc.AuthenticatingFilter; import org.apache.shiro.web.util.WebUtils; import org.eclipse.kapua.KapuaRuntimeException; -import org.eclipse.kapua.locator.KapuaLocator; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; -import org.eclipse.kapua.service.authentication.CredentialsFactory; +import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.exceptions.ExpiredAccessTokenException; import org.eclipse.kapua.service.authentication.shiro.exceptions.InvalidatedAccessTokenException; import org.eclipse.kapua.service.authentication.shiro.exceptions.MalformedAccessTokenException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - public class KapuaTokenAuthenticationFilter extends AuthenticatingFilter { private static final String OPTIONS = "OPTIONS"; private static final String AUTHORIZATION_HEADER = "Authorization"; private static final String BEARER = "Bearer"; - private final CredentialsFactory credentialsFactory; private final Logger logger = LoggerFactory.getLogger(this.getClass()); public KapuaTokenAuthenticationFilter() { - KapuaLocator locator = KapuaLocator.getInstance(); - this.credentialsFactory = locator.getFactory(CredentialsFactory.class); } @Override @@ -71,13 +66,13 @@ protected AuthenticationToken createToken(ServletRequest request, ServletRespons tokenId = httpRequest.getHeader(AUTHORIZATION_HEADER).replace(BEARER + " ", ""); } // Build AccessToken for Shiro Auth - AccessTokenCredentials accessTokenCredentials = credentialsFactory.newAccessTokenCredentials(tokenId); + AccessTokenCredentialsImpl accessTokenCredentials = new AccessTokenCredentialsImpl(tokenId); // Return token return (AuthenticationToken) accessTokenCredentials; } protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, - ServletRequest request, ServletResponse response) { + ServletRequest request, ServletResponse response) { HttpServletResponse httpResponse = WebUtils.toHttp(response); httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); //now I set a dummy header to propagate the error message to the CORSResponseFilter Class, that eventually will send this error message if CORS filter passes @@ -91,7 +86,6 @@ protected boolean onAccessDenied(ServletRequest request, ServletResponse respons return true; } - //with this method we choose what exceptions we want to hide in the response and what we want to show as an error message private String handleAuthException(AuthenticationException ae) { String errorMessageInResponse = "An error occurred during the authentication process with the provided access token"; diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java index 259dfe1b6e8..7965fe07ad7 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessInfos.java @@ -36,7 +36,6 @@ import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoAttributes; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; -import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoListResult; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.user.User; @@ -51,8 +50,6 @@ public class AccessInfos extends AbstractKapuaResource { @Inject public AccessInfoService accessInfoService; - @Inject - public AccessInfoFactory accessInfoFactory; /** * Gets the {@link AccessInfo} list in the scope. diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java index ea7109219d2..70bbddb320f 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessPermissions.java @@ -39,7 +39,6 @@ import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator; -import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; @@ -55,8 +54,6 @@ public class AccessPermissions extends AbstractKapuaResource { @Inject public AccessPermissionService accessPermissionService; - @Inject - public AccessPermissionFactory accessPermissionFactory; /** * Gets the {@link AccessPermission} list in the scope. diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java index ea8bb283b27..a0b771b1a63 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/AccessRoles.java @@ -37,7 +37,6 @@ import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; import org.eclipse.kapua.service.authorization.access.AccessRoleCreator; -import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; import org.eclipse.kapua.service.authorization.access.AccessRoleService; @@ -46,8 +45,6 @@ public class AccessRoles extends AbstractKapuaResource { @Inject public AccessRoleService accessRoleService; - @Inject - public AccessRoleFactory accessRoleFactory; /** * Gets the {@link AccessRole} list in the scope. diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java index e230fbd3a42..b1caad4293e 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/Accounts.java @@ -40,7 +40,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountAttributes; import org.eclipse.kapua.service.account.AccountCreator; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; import org.eclipse.kapua.service.account.AccountService; @@ -51,8 +50,6 @@ public class Accounts extends AbstractKapuaResource { @Inject public AccountService accountService; - @Inject - public AccountFactory accountFactory; /** * Gets the {@link Account} list in the scope. diff --git a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java index 8dc981d1d05..148da4bd501 100644 --- a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java +++ b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/RestApiJAXBContextProvider.java @@ -87,7 +87,6 @@ import org.eclipse.kapua.service.account.xml.AccountXmlRegistry; import org.eclipse.kapua.service.authentication.ApiKeyCredentials; import org.eclipse.kapua.service.authentication.AuthenticationCredentials; -import org.eclipse.kapua.service.authentication.AuthenticationXmlRegistry; import org.eclipse.kapua.service.authentication.JwtCredentials; import org.eclipse.kapua.service.authentication.RefreshTokenCredentials; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; @@ -572,7 +571,6 @@ public JAXBContext getJAXBContext() throws KapuaException { // Authentication AuthenticationCredentials.class, - AuthenticationXmlRegistry.class, AccessToken.class, LoginInfo.class, ApiKeyCredentials.class, diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java index 60b6481a0fa..db3cc3f009f 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java @@ -32,7 +32,6 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.commons.jpa.NamedCacheFactory; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.commons.service.internal.cache.NamedEntityCache; @@ -76,10 +75,8 @@ public Domain accountDomain() { @Provides @Singleton AccountRelativeFinder accountRelativeFinder( - AccountFactory accountFactory, AccountService accountService) { return new AccountRelativeFinderImpl( - accountFactory, accountService); } @@ -88,7 +85,6 @@ ServiceModule accountServiceModule(AccountService accountService, AuthorizationService authorizationService, PermissionFactory permissionFactory, KapuaJpaTxManagerFactory txManagerFactory, - EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAccountSetting kapuaAccountSetting, @@ -102,7 +98,6 @@ ServiceModule accountServiceModule(AccountService accountService, authorizationService, permissionFactory, txManagerFactory.create("kapua-account"), - eventStoreFactory, eventStoreRecordRepository ), txManagerFactory.create("kapua-account"), @@ -115,7 +110,6 @@ ServiceModule accountServiceModule(AccountService accountService, @Provides @Singleton AccountService accountService(AccountRepository accountRepository, - AccountFactory accountFactory, PermissionFactory permissionFactory, AuthorizationService authorizationService, @Named("AccountServiceConfigurationManager") ServiceConfigurationManager serviceConfigurationManager, @@ -136,7 +130,6 @@ AccountService accountService(AccountRepository accountRepository, @Singleton @Named("AccountServiceConfigurationManager") ServiceConfigurationManager accountServiceConfigurationManager( - AccountFactory factory, RootUserTester rootUserTester, AccountRelativeFinder accountRelativeFinder, AccountRepository accountRepository, @@ -154,7 +147,6 @@ ServiceConfigurationManager accountServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - factory, accountRepository), xmlUtil )); diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java index ce0c2c4bf2e..bf2b2fa6651 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountRelativeFinderImpl.java @@ -30,18 +30,15 @@ import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.account.Account; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; import org.eclipse.kapua.service.account.AccountService; public class AccountRelativeFinderImpl implements AccountRelativeFinder, KapuaService { - private final AccountFactory accountFactory; private final AccountService accountService; @Inject - public AccountRelativeFinderImpl(AccountFactory accountFactory, AccountService accountService) { - this.accountFactory = accountFactory; + public AccountRelativeFinderImpl(AccountService accountService) { this.accountService = accountService; } diff --git a/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java b/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java index d9b73746c0c..c22da48583d 100755 --- a/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java +++ b/service/account/test-steps/src/main/java/org/eclipse/kapua/service/account/steps/AccountServiceSteps.java @@ -45,7 +45,6 @@ import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountAttributes; import org.eclipse.kapua.service.account.AccountCreator; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountListResult; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.account.Organization; @@ -81,7 +80,6 @@ public class AccountServiceSteps extends TestBase { // Account creator object used for creating new accounts. private AccountService accountService; - private AccountFactory accountFactory; // Default constructor @Inject @@ -92,7 +90,6 @@ public AccountServiceSteps(StepData stepData) { @After(value = "@setup") public void setServices() { locator = KapuaLocator.getInstance(); - accountFactory = locator.getFactory(AccountFactory.class); accountService = locator.getService(AccountService.class); } diff --git a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java index 8abb771e865..8acf7c83545 100644 --- a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java +++ b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java @@ -125,7 +125,6 @@ protected void configure() { Mockito.mock(RootUserTester.class), Mockito.mock(AccountRelativeFinder.class), new UsedEntitiesCounterImpl( - accountFactory, accountRepository), new XmlUtil(new TestJAXBContextProvider()) ), diff --git a/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationServiceBackEndCall.java b/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationServiceBackEndCall.java index 967fe211b87..52ce8c26b7f 100644 --- a/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationServiceBackEndCall.java +++ b/service/authentication/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationServiceBackEndCall.java @@ -36,7 +36,6 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaEntity; -import org.eclipse.kapua.model.id.KapuaIdFactory; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.authentication.Authenticator; @@ -67,8 +66,6 @@ public class AuthenticationServiceBackEndCall { private AuthenticationService authenticationService; private AccountService accountService; private DeviceConnectionService deviceConnectionService; - private CredentialsFactory credentialFactory; - private KapuaIdFactory kapuaIdFactory; private UserService userService; @Inject @@ -79,15 +76,14 @@ public AuthenticationServiceBackEndCall() { authenticationService = locator.getService(AuthenticationService.class); accountService = locator.getService(AccountService.class); deviceConnectionService = locator.getService(DeviceConnectionService.class); - credentialFactory = locator.getFactory(CredentialsFactory.class); - kapuaIdFactory = locator.getFactory(KapuaIdFactory.class); userService = locator.getService(UserService.class); authenticationMetric = locator.getComponent(AuthMetric.class); } public AuthResponse brokerConnect(AuthRequest authRequest) { try { - logger.info("Login for clientId {} - user: {} - password: {} - client certificates: {}", authRequest.getClientId(), authRequest.getUsername(), Strings.isNullOrEmpty(authRequest.getPassword()) ? "no" : "yes", authRequest.getCertificates() != null ? "yes" : "no"); + logger.info("Login for clientId {} - user: {} - password: {} - client certificates: {}", authRequest.getClientId(), authRequest.getUsername(), + Strings.isNullOrEmpty(authRequest.getPassword()) ? "no" : "yes", authRequest.getCertificates() != null ? "yes" : "no"); ThreadContext.unbindSubject(); String deviceConnectionAuthType = extractAuthTypeFromAuthRequest(authRequest); LoginCredentials authenticationCredentials = buildLoginCredentialsFromAuthType(authRequest, deviceConnectionAuthType); @@ -249,7 +245,8 @@ private void updateError(AuthResponse authResponse, @NotNull Exception exception /** * Extracts the {@link DeviceConnection#getAuthenticationType()} to be used for this connect attempt from the {@link AuthRequest}. * - * @param authRequest The {@link AuthRequest} from which to extract data. + * @param authRequest + * The {@link AuthRequest} from which to extract data. * @return The resolved {@link DeviceConnection#getAuthenticationType()}. * @throws KapuaException * @since 2.0.0 @@ -271,8 +268,10 @@ private String extractAuthTypeFromAuthRequest(AuthRequest authRequest) throws Ka /** * Builds the {@link LoginCredentials} to be used from the resolved {@link DeviceConnection#getAuthenticationType()}. * - * @param authRequest The {@link AuthRequest} with the {@link LoginCredentials} values. - * @param deviceConnectionAuthType The resolved {@link DeviceConnection#getAuthenticationType()}. + * @param authRequest + * The {@link AuthRequest} with the {@link LoginCredentials} values. + * @param deviceConnectionAuthType + * The resolved {@link DeviceConnection#getAuthenticationType()}. * @return The {@link LoginCredentials} for the given {@link DeviceConnection#getAuthenticationType()}. * @throws KapuaException * @since 2.0.0 diff --git a/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/DeviceAuthenticationModule.java b/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/DeviceAuthenticationModule.java index eb5d917b57f..af6f5e92931 100644 --- a/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/DeviceAuthenticationModule.java +++ b/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/DeviceAuthenticationModule.java @@ -12,12 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.authentication; -import com.google.inject.multibindings.ProvidesIntoMap; -import com.google.inject.multibindings.StringMapKey; import org.eclipse.kapua.commons.core.AbstractKapuaModule; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.device.authentication.api.DeviceConnectionCredentialAdapter; +import com.google.inject.multibindings.ProvidesIntoMap; +import com.google.inject.multibindings.StringMapKey; + /** * kapua-device-authentication {@link AbstractKapuaModule}. * @@ -31,7 +31,7 @@ protected void configureModule() { @ProvidesIntoMap @StringMapKey("USER_PASS") - public DeviceConnectionCredentialAdapter userPassDeviceConnectionAuthHandler(CredentialsFactory credentialFactory) { - return new UserPassDeviceConnectionCredentialAdapter(credentialFactory); + public DeviceConnectionCredentialAdapter userPassDeviceConnectionAuthHandler() { + return new UserPassDeviceConnectionCredentialAdapter(); } } diff --git a/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/UserPassDeviceConnectionCredentialAdapter.java b/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/UserPassDeviceConnectionCredentialAdapter.java index 3297c6857a7..abaafcdd7cc 100644 --- a/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/UserPassDeviceConnectionCredentialAdapter.java +++ b/service/device/authentication/src/main/java/org/eclipse/kapua/service/device/authentication/UserPassDeviceConnectionCredentialAdapter.java @@ -13,13 +13,10 @@ package org.eclipse.kapua.service.device.authentication; import org.eclipse.kapua.client.security.bean.AuthRequest; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.LoginCredentials; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.device.authentication.api.DeviceConnectionCredentialAdapter; -import javax.inject.Inject; - /** * {@link UsernamePasswordCredentials} {@link DeviceConnectionCredentialAdapter} * @@ -27,16 +24,9 @@ */ public class UserPassDeviceConnectionCredentialAdapter implements DeviceConnectionCredentialAdapter { - private CredentialsFactory credentialsFactory; - - @Inject - public UserPassDeviceConnectionCredentialAdapter(CredentialsFactory credentialsFactory) { - this.credentialsFactory = credentialsFactory; - } - @Override public LoginCredentials mapToCredential(AuthRequest authRequest) { - return credentialsFactory.newUsernamePasswordCredentials( + return new UsernamePasswordCredentials( authRequest.getUsername(), authRequest.getPassword()); } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java index 7709e703544..6019ae5b196 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java @@ -12,12 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.connection.listener.internal; -import com.google.inject.Module; -import com.google.inject.multibindings.ProvidesIntoSet; +import javax.inject.Named; + import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.ServiceModule; import org.eclipse.kapua.commons.event.ServiceEventHouseKeeperFactoryImpl; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.event.ServiceEventBus; @@ -29,7 +28,8 @@ import org.eclipse.kapua.service.device.registry.KapuaDeviceRegistrySettings; import org.eclipse.kapua.storage.TxManager; -import javax.inject.Named; +import com.google.inject.Module; +import com.google.inject.multibindings.ProvidesIntoSet; /** * {@code kapua-account-internal} {@link Module} implementation. @@ -45,14 +45,13 @@ protected void configureModule() { @ProvidesIntoSet protected ServiceModule deviceConnectionEventListenerServiceModule(DeviceConnectionEventListenerService deviceConnectionEventListenerService, - AuthorizationService authorizationService, - PermissionFactory permissionFactory, - KapuaDeviceRegistrySettings kapuaDeviceRegistrySettings, - @Named("DeviceRegistryTransactionManager") TxManager txManager, - EventStoreFactory eventStoreFactory, - EventStoreRecordRepository eventStoreRecordRepository, - ServiceEventBus serviceEventBus, - @Named("eventsModuleName") String eventModuleName + AuthorizationService authorizationService, + PermissionFactory permissionFactory, + KapuaDeviceRegistrySettings kapuaDeviceRegistrySettings, + @Named("DeviceRegistryTransactionManager") TxManager txManager, + EventStoreRecordRepository eventStoreRecordRepository, + ServiceEventBus serviceEventBus, + @Named("eventsModuleName") String eventModuleName ) throws ServiceEventBusException { String address = kapuaDeviceRegistrySettings.getString(KapuaDeviceRegistrySettingKeys.DEVICE_EVENT_ADDRESS); @@ -64,7 +63,6 @@ protected ServiceModule deviceConnectionEventListenerServiceModule(DeviceConnect authorizationService, permissionFactory, txManager, - eventStoreFactory, eventStoreRecordRepository ), txManager, diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java index 2dab06adbf7..18df2e7fd0a 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java @@ -33,7 +33,6 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration; import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.commons.util.xml.XmlUtil; @@ -133,7 +132,6 @@ ServiceModule deviceRegistryModule(DeviceConnectionService deviceConnectionServi AuthorizationService authorizationService, PermissionFactory permissionFactory, KapuaJpaTxManagerFactory txManagerFactory, - EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaDeviceRegistrySettings kapuaDeviceRegistrySettings, @@ -149,7 +147,6 @@ ServiceModule deviceRegistryModule(DeviceConnectionService deviceConnectionServi authorizationService, permissionFactory, jpaTxManagerFactory.create("kapua-device"), - eventStoreFactory, eventStoreRecordRepository ), jpaTxManagerFactory.create("kapua-device"), @@ -225,7 +222,6 @@ protected TxManager deviceRegistryTxManager(KapuaJpaTxManagerFactory jpaTxManage @Singleton @Named("DeviceRegistryServiceConfigurationManager") protected ServiceConfigurationManager deviceRegistryServiceConfigurationManager( - DeviceFactory factory, RootUserTester rootUserTester, AccountRelativeFinder accountRelativeFinder, DeviceRepository deviceRepository, @@ -243,7 +239,6 @@ protected ServiceConfigurationManager deviceRegistryServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - factory, deviceRepository), xmlUtil )); diff --git a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclCreator.java b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclCreator.java index 7f1e460c6e1..6e14ad473af 100644 --- a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclCreator.java +++ b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclCreator.java @@ -30,20 +30,16 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; -import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; -import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.permission.Permission; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.user.User; import org.eclipse.kapua.service.user.UserCreator; -import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,31 +59,23 @@ public class AclCreator { * Credential service. */ private CredentialService credentialService; - private CredentialFactory credentialFactory; private PermissionFactory permissionFactory; /** * User service. */ private UserService userService; - private UserFactory userFactory; /** * Accessinfo service. */ private AccessInfoService accessInfoService; - private AccessInfoFactory accessInfoFactory; /** * Account service. */ private AccountService accountService; - /** - * Account factory. - */ - private AccountFactory accountFactory; - /** * Constructor with all support services. */ @@ -95,16 +83,12 @@ public AclCreator() { KapuaLocator locator = KapuaLocator.getInstance(); accountService = locator.getService(AccountService.class); - accountFactory = locator.getFactory(AccountFactory.class); userService = locator.getService(UserService.class); - userFactory = locator.getFactory(UserFactory.class); accessInfoService = locator.getService(AccessInfoService.class); - accessInfoFactory = locator.getFactory(AccessInfoFactory.class); credentialService = locator.getService(CredentialService.class); - credentialFactory = locator.getFactory(CredentialFactory.class); permissionFactory = locator.getFactory(PermissionFactory.class); } diff --git a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclSteps.java b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclSteps.java index bbd2237eebb..0d90a4245ea 100644 --- a/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclSteps.java +++ b/service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/AclSteps.java @@ -13,14 +13,21 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.registry.steps; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; -import org.eclipse.kapua.qa.common.TestBase; import org.eclipse.kapua.qa.common.StepData; +import org.eclipse.kapua.qa.common.TestBase; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.LoginCredentials; +import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.user.User; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallback; @@ -43,13 +50,6 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; -import javax.inject.Inject; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * Steps for testing Access Control List functionality on Broker service. */ @@ -87,7 +87,6 @@ public class AclSteps extends TestBase { private static Map listenerMqttMessage; private static AuthenticationService authenticationService; - private static CredentialsFactory credentialsFactory; /** * Helper for creating Accoutn, User and other artifacts needed in tests. */ @@ -98,11 +97,10 @@ public AclSteps(StepData stepData) { super(stepData); } - @After(value="@setup") + @After(value = "@setup") public void setServices() { locator = KapuaLocator.getInstance(); authenticationService = locator.getService(AuthenticationService.class); - credentialsFactory = locator.getFactory(CredentialsFactory.class); mqttDevice = new MqttDevice(); clientMqttMessage = new HashMap<>(); @@ -111,7 +109,7 @@ public void setServices() { aclCreator = new AclCreator(); } - @Before(value="@env_docker or @env_docker_base or @env_none", order=10) + @Before(value = "@env_docker or @env_docker_base or @env_none", order = 10) public void beforeScenarioNone(Scenario scenario) { updateScenario(scenario); } @@ -128,7 +126,7 @@ public void startMqttDevice() throws KapuaException { waitInMillis(BROKER_START_WAIT_MILLIS); // Login with system user String passwd = SYS_PASSWORD; - LoginCredentials credentials = credentialsFactory.newUsernamePasswordCredentials(SYS_USERNAME, passwd); + LoginCredentials credentials = new UsernamePasswordCredentials(SYS_USERNAME, passwd); authenticationService.login(credentials); } @@ -173,8 +171,8 @@ public void connectionLost(Throwable cause) { logger.info("Connection lost!", cause); } }); - List mqttClientList = (List)stepData.get("Paho_" + deviceGroup); - if (mqttClientList==null) { + List mqttClientList = (List) stepData.get("Paho_" + deviceGroup); + if (mqttClientList == null) { mqttClientList = new ArrayList<>(); stepData.put("Paho_" + deviceGroup, mqttClientList); } @@ -184,8 +182,8 @@ public void connectionLost(Throwable cause) { @Then("Clients from group {string} are connected") public void checkClientConnected(String deviceGroup) throws Exception { - List mqttDeviceList = (List)stepData.get("Paho_" + deviceGroup); - if (mqttDeviceList!=null) { + List mqttDeviceList = (List) stepData.get("Paho_" + deviceGroup); + if (mqttDeviceList != null) { mqttDeviceList.forEach(mqttDevice -> Assert.assertTrue("Client " + mqttDevice.getClientId() + " should be connected!", mqttDevice.isConnected())); } } @@ -213,8 +211,7 @@ private boolean brokerReceivesStringOnTopicInternal(String payload, String topic String message = listenerMqttMessage.get(topic); if (timeout) { Assert.assertEquals(payload, message); - } - else { + } else { result = payload.equals(message); } } else { @@ -252,8 +249,7 @@ private boolean iReceiveStringOnTopicInternal(String clientId, String payload, S String message = messages.get(topic); if (timeout) { Assert.assertEquals(payload, message); - } - else { + } else { result = payload.equals(message); } } else { @@ -313,7 +309,7 @@ public void createDataManageAccountAndUser() throws Exception { @And("other broker account and user are created") public void createOtherBrokerAccountAndUser() throws Exception { - Account account = aclCreator.createAccount("domino","Domino Corp.", "lisa@domino.org"); + Account account = aclCreator.createAccount("domino", "Domino Corp.", "lisa@domino.org"); User user = aclCreator.createUser(account, "domina"); aclCreator.attachUserCredentials(account, user); aclCreator.attachBrokerPermissions(account, user); @@ -334,7 +330,8 @@ public void exceptionIsNotThrown() { /** * Simple wait implementation. * - * @param millis milli seconds + * @param millis + * milli seconds */ private void waitInMillis(long millis) { try { diff --git a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java index f3438a2b069..dbf7c02885e 100644 --- a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java +++ b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java @@ -41,7 +41,6 @@ import org.eclipse.kapua.qa.common.MockedLocator; import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.mfa.MfaAuthenticator; import org.eclipse.kapua.service.authentication.shiro.mfa.MfaAuthenticatorImpl; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSetting; @@ -126,9 +125,7 @@ protected void configure() { } catch (KapuaException e) { // skip } - final CredentialsFactory credentialsFactory = Mockito.mock(CredentialsFactory.class); bind(AuthorizationService.class).toInstance(mockedAuthorization); - bind(CredentialsFactory.class).toInstance(credentialsFactory); bind(KapuaJpaRepositoryConfiguration.class).toInstance(new KapuaJpaRepositoryConfiguration()); bind(AccountRelativeFinder.class).toInstance(Mockito.mock(AccountRelativeFinder.class)); bind(AccountFactory.class).toInstance(Mockito.mock(AccountFactory.class)); @@ -147,7 +144,7 @@ protected void configure() { bind(DeviceRegistryCacheFactory.class).toInstance(deviceRegistryCacheFactory); final Map availableDeviceConnectionAdapters = new HashMap<>(); - availableDeviceConnectionAdapters.put("USER_PASS", new UserPassDeviceConnectionCredentialAdapter(credentialsFactory)); + availableDeviceConnectionAdapters.put("USER_PASS", new UserPassDeviceConnectionCredentialAdapter()); bind(ServiceConfigurationManager.class) .annotatedWith(Names.named("DeviceConnectionServiceConfigurationManager")) .toInstance(Mockito.mock(ServiceConfigurationManager.class)); diff --git a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobModule.java b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobModule.java index a61a8418276..cdad5542407 100644 --- a/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobModule.java +++ b/service/job/internal/src/main/java/org/eclipse/kapua/service/job/internal/JobModule.java @@ -109,7 +109,6 @@ public ServiceConfigurationManager jobServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - factory, jobRepository ), xmlUtil)); diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AccessTokenCredentials.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AccessTokenCredentials.java deleted file mode 100644 index 1dd067387c9..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AccessTokenCredentials.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication; - -import org.eclipse.kapua.service.authentication.token.AccessToken; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -/** - * {@link AccessToken} {@link AuthenticationCredentials} definition. - * - * @since 1.0.0 - */ -@XmlRootElement(name = "accessTokenCredentials") -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AuthenticationXmlRegistry.class, factoryMethod = "newAccessTokenCredentials") -public interface AccessTokenCredentials extends SessionCredentials { - - /** - * Gets the session JWT to authenticate. - * - * @return The session JWT to authenticate. - * @since 1.0.0 - */ - String getTokenId(); - - /** - * Sets the session JWT to authenticate. - * - * @param tokenId The session JWT to authenticate. - * @since 1.0.0 - */ - void setTokenId(String tokenId); -} diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/ApiKeyCredentials.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/ApiKeyCredentials.java index f521a7f81a2..12184fa00c0 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/ApiKeyCredentials.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/ApiKeyCredentials.java @@ -25,23 +25,47 @@ */ @XmlRootElement(name = "apiKeyCredentials") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AuthenticationXmlRegistry.class, factoryMethod = "newApiKeyCredentials") -public interface ApiKeyCredentials extends LoginCredentials { +@XmlType +public class ApiKeyCredentials implements LoginCredentials { + + private static final long serialVersionUID = -5920944517814926028L; + + private String apiKey; + + public ApiKeyCredentials() { + } /** - * Gets the Api Key to authenticate. + * Constructor. + * + * @param apiKey + * The Api Key. + * @since 1.0.0 + */ + public ApiKeyCredentials(String apiKey) { + setApiKey(apiKey); + } + + /** + * /** Gets the Api Key to authenticate. * * @return The Api Key to authenticate. * @since 1.0.0 */ @XmlElement(name = "apiKey") - String getApiKey(); + public String getApiKey() { + return apiKey; + } /** * Sets the Api Key to authenticate. * - * @param apiKey The Api Key to authenticate. + * @param apiKey + * The Api Key to authenticate. * @since 1.0.0 */ - void setApiKey(String apiKey); + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + } diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationXmlRegistry.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationXmlRegistry.java deleted file mode 100644 index fca84cc0544..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/AuthenticationXmlRegistry.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - * Red Hat Inc - *******************************************************************************/ -package org.eclipse.kapua.service.authentication; - -import org.eclipse.kapua.locator.KapuaLocator; - -public class AuthenticationXmlRegistry { - - private final CredentialsFactory credentialsFactory = KapuaLocator.getInstance().getFactory(CredentialsFactory.class); - - /** - * Creates a new {@link UsernamePasswordCredentials} instance - * - * @return - */ - public UsernamePasswordCredentials newUsernamePasswordCredentials() { - return credentialsFactory.newUsernamePasswordCredentials(); - } - - /** - * Creates a new {@link ApiKeyCredentials} instance - * - * @return - */ - public ApiKeyCredentials newApiKeyCredentials() { - return credentialsFactory.newApiKeyCredentials(null); - } - - /** - * Creates a new {@link JwtCredentials} instance - * - * @return - */ - public JwtCredentials newJwtCredentials() { - return credentialsFactory.newJwtCredentials(null, null); - } - - /** - * Creates a new {@link AccessTokenCredentials} instance - * - * @return - */ - public AccessTokenCredentials newAccessTokenCredentials() { - return credentialsFactory.newAccessTokenCredentials(null); - } - - /** - * Creates a new {@link RefreshTokenCredentials} instance - * - * @return - */ - public RefreshTokenCredentials newRefreshTokenCredentials() { - return credentialsFactory.newRefreshTokenCredentials(null, null); - } -} diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/CredentialsFactory.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/CredentialsFactory.java deleted file mode 100644 index 3066c769102..00000000000 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/CredentialsFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - * Red Hat Inc - *******************************************************************************/ -package org.eclipse.kapua.service.authentication; - -import org.eclipse.kapua.model.KapuaObjectFactory; - -/** - * {@link CredentialsFactory} factory definition. - */ -public interface CredentialsFactory extends KapuaObjectFactory { - - /** - * Creates a new {@link UsernamePasswordCredentials} instance based on provided username and password - * - * @param username the name of the user - * @param password the password of the user - * @return the new credentials - */ - UsernamePasswordCredentials newUsernamePasswordCredentials(String username, String password); - - /** - * Creates a new {@link UsernamePasswordCredentials} instance based on username and password with no preset values - * - * @return the new, empty credentials instance - */ - default UsernamePasswordCredentials newUsernamePasswordCredentials() { - return newUsernamePasswordCredentials(null, null); - } - - /** - * Creates a new {@link ApiKeyCredentials} instance based on provided api key - * - * @param apiKey - * @return - */ - ApiKeyCredentials newApiKeyCredentials(String apiKey); - - /** - * Creates a new {@link JwtCredentials} instance based on provided Json Web Token - * - * @param jwt - * @param idToken the OpenID Connect idToken, used for the logout - * @return - */ - JwtCredentials newJwtCredentials(String jwt, String idToken); - - /** - * Creates a new {@link AccessTokenCredentials} instance based on provided tokenId - * - * @param tokenId - * @return - */ - AccessTokenCredentials newAccessTokenCredentials(String tokenId); - - /** - * Creates a new {@link RefreshTokenCredentials} instance based on provided tokenId and refresh token - * - * @param tokenId - * @return - */ - RefreshTokenCredentials newRefreshTokenCredentials(String tokenId, String refreshToken); - -} diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/JwtCredentials.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/JwtCredentials.java index 74b69fe3288..bcec8296265 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/JwtCredentials.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/JwtCredentials.java @@ -25,8 +25,30 @@ */ @XmlRootElement(name = "jwtCredentials") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AuthenticationXmlRegistry.class, factoryMethod = "newJwtCredentials") -public interface JwtCredentials extends LoginCredentials { +@XmlType +public class JwtCredentials implements LoginCredentials { + + private static final long serialVersionUID = -5920944517814926028L; + + private String accessToken; + private String idToken; + + public JwtCredentials() { + } + + /** + * Constructor. + * + * @param accessToken + * The credential access token + * @param idToken + * The credential id token. + * @since 1.4.0 + */ + public JwtCredentials(String accessToken, String idToken) { + setAccessToken(accessToken); + setIdToken(idToken); + } /** * Gets the OpenID Connect accessToken. @@ -35,15 +57,20 @@ public interface JwtCredentials extends LoginCredentials { * @since 1.3.0 */ @XmlElement(name = "accessToken") - String getAccessToken(); + public String getAccessToken() { + return accessToken; + } /** * Set the OpenID Connect accessToken. * - * @param accessToken The OpenID Connect accessToken. + * @param accessToken + * The OpenID Connect accessToken. * @since 1.3.0 */ - void setAccessToken(String accessToken); + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } /** * Gets the OpenID Connect idToken. @@ -52,13 +79,19 @@ public interface JwtCredentials extends LoginCredentials { * @since 1.3.0 */ @XmlElement(name = "idToken") - String getIdToken(); + public String getIdToken() { + return idToken; + } /** * Set the OpenID Connect idToken. * - * @param idToken The OpenID Connect idToken. + * @param idToken + * The OpenID Connect idToken. * @since 1.3.0 */ - void setIdToken(String idToken); + public void setIdToken(String idToken) { + this.idToken = idToken; + } + } diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/RefreshTokenCredentials.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/RefreshTokenCredentials.java index 0db0d1f127b..53dfd32076f 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/RefreshTokenCredentials.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/RefreshTokenCredentials.java @@ -12,14 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication; -import org.eclipse.kapua.service.authentication.token.AccessToken; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.eclipse.kapua.service.authentication.token.AccessToken; + /** * {@link AccessToken#getRefreshToken()} {@link LoginCredentials} definition. * @@ -27,8 +27,28 @@ */ @XmlRootElement(name = "refreshTokenCredentials") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AuthenticationXmlRegistry.class, factoryMethod = "newRefreshTokenCredentials") -public interface RefreshTokenCredentials extends LoginCredentials { +@XmlType +public class RefreshTokenCredentials implements LoginCredentials { + + private String tokenId; + private String refreshToken; + + public RefreshTokenCredentials() { + } + + /** + * Constructor. + * + * @param tokenId + * The {@link AccessToken#getTokenId()} + * @param refreshToken + * TThe {@link AccessToken#getRefreshToken()} + * @since 1.0.0 + */ + public RefreshTokenCredentials(String tokenId, String refreshToken) { + this.tokenId = tokenId; + this.refreshToken = refreshToken; + } /** * Gets the {@link AccessToken#getTokenId()} to authenticate. @@ -37,15 +57,20 @@ public interface RefreshTokenCredentials extends LoginCredentials { * @since 1.0.0 */ @XmlElement(name = "tokenId") - String getTokenId(); + public String getTokenId() { + return tokenId; + } /** * Set the {@link AccessToken#getTokenId()} to authenticate. * - * @param tokenId The {@link AccessToken#getTokenId()} to authenticate. + * @param tokenId + * The {@link AccessToken#getTokenId()} to authenticate. * @since 1.0.0 */ - void setTokenId(String tokenId); + public void setTokenId(String tokenId) { + this.tokenId = tokenId; + } /** * Gets the AccessToken#getRefreshToken()} to authenticate. @@ -54,13 +79,19 @@ public interface RefreshTokenCredentials extends LoginCredentials { * @since 1.0.0 */ @XmlElement(name = "refreshToken") - String getRefreshToken(); + public String getRefreshToken() { + return refreshToken; + } /** * Set the {@link AccessToken#getRefreshToken()} to authenticate. * - * @param refreshToken The AccessToken#getRefreshToken()} to authenticate. + * @param refreshToken + * The AccessToken#getRefreshToken()} to authenticate. * @since 1.0.0 */ - void setRefreshToken(String refreshToken); + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + } diff --git a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/UsernamePasswordCredentials.java b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/UsernamePasswordCredentials.java index 425f706e3fd..4b126b0de7b 100644 --- a/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/UsernamePasswordCredentials.java +++ b/service/security/authentication/api/src/main/java/org/eclipse/kapua/service/authentication/UsernamePasswordCredentials.java @@ -24,8 +24,24 @@ */ @XmlRootElement(name = "usernamePasswordCredentials") @XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(factoryClass = AuthenticationXmlRegistry.class, factoryMethod = "newUsernamePasswordCredentials") -public interface UsernamePasswordCredentials extends LoginCredentials { +@XmlType +public class UsernamePasswordCredentials implements LoginCredentials { + + private static final long serialVersionUID = -7549848672967689716L; + + private String username; + private String password; + private String authenticationCode; + private String trustKey; + private boolean trustMe; + + public UsernamePasswordCredentials() { + } + + public UsernamePasswordCredentials(String username, String password) { + this.username = username; + this.password = password; + } /** * Gets the username. @@ -33,15 +49,20 @@ public interface UsernamePasswordCredentials extends LoginCredentials { * @return The username. * @since 1.0.0 */ - String getUsername(); + public String getUsername() { + return username; + } /** * Sets the username. * - * @param username The username. + * @param username + * The username. * @since 1.0.0 */ - void setUsername(String username); + public void setUsername(String username) { + this.username = username; + } /** * Gets the password. @@ -49,15 +70,20 @@ public interface UsernamePasswordCredentials extends LoginCredentials { * @return The password. * @since 1.0.0 */ - String getPassword(); + public String getPassword() { + return password; + } /** * Sets the password. * - * @param password The password. + * @param password + * The password. * @since 1.0.0 */ - void setPassword(String password); + public void setPassword(String password) { + this.password = password; + } /** * Gets the MFA authentication code. @@ -65,15 +91,20 @@ public interface UsernamePasswordCredentials extends LoginCredentials { * @return The MFA authentication code. * @since 1.3.0 */ - String getAuthenticationCode(); + public String getAuthenticationCode() { + return authenticationCode; + } /** * Sets the MFA authentication code. * - * @param authenticationCode The MFA authentication code. + * @param authenticationCode + * The MFA authentication code. * @since 1.3.0 */ - void setAuthenticationCode(String authenticationCode); + public void setAuthenticationCode(String authenticationCode) { + this.authenticationCode = authenticationCode; + } /** * Gets the trust key. @@ -81,15 +112,20 @@ public interface UsernamePasswordCredentials extends LoginCredentials { * @return The trust key. * @since 1.3.0 */ - String getTrustKey(); + public String getTrustKey() { + return trustKey; + } /** * Sets the trust key. * - * @param trustKey The trust key. + * @param trustKey + * The trust key. * @since 1.3.0 */ - void setTrustKey(String trustKey); + public void setTrustKey(String trustKey) { + this.trustKey = trustKey; + } /** * Gets whether create a trust key or not. @@ -97,13 +133,19 @@ public interface UsernamePasswordCredentials extends LoginCredentials { * @return {@code true} if to be created, {@code false} otherwise * @since 2.0.0 */ - boolean getTrustMe(); + public boolean getTrustMe() { + return trustMe; + } /** * Sets whether create a trust key or not. * - * @param trustMe {@code true} if to be created, {@code false} if not. + * @param trustMe + * {@code true} if to be created, {@code false} if not. * @since 2.0.0 */ - void setTrustMe(boolean trustMe); + public void setTrustMe(boolean trustMe) { + this.trustMe = trustMe; + } + } diff --git a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationModule.java b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationModule.java index 4c86304e3c0..0e895636403 100644 --- a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationModule.java +++ b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationModule.java @@ -12,12 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.security.registration.simple; -import com.google.inject.multibindings.ProvidesIntoSet; +import javax.inject.Singleton; + import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; import org.eclipse.kapua.security.registration.RegistrationProcessorProvider; import org.eclipse.kapua.security.registration.simple.setting.SimpleSetting; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialService; @@ -25,12 +25,12 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.registry.DeviceRegistryService; -import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserService; -import javax.inject.Singleton; +import com.google.inject.multibindings.ProvidesIntoSet; public class SimpleRegistrationModule extends AbstractKapuaModule { + @Override protected void configureModule() { bind(SimpleSetting.class).in(Singleton.class); @@ -41,12 +41,10 @@ protected void configureModule() { RegistrationProcessorProvider simpleRegistrationProcessorProvider( SimpleSetting simpleSetting, AccountService accountService, - AccountFactory accountFactory, CredentialService credentialService, CredentialFactory credentialFactory, DeviceRegistryService deviceRegistryService, UserService userService, - UserFactory userFactory, AccessInfoService accessInfoService, AccessInfoFactory accessInfoFactory, PermissionFactory permissionFactory, @@ -54,12 +52,10 @@ RegistrationProcessorProvider simpleRegistrationProcessorProvider( DatabaseCheckUpdate databaseCheckUpdate) { return new SimpleRegistrationProcessorProvider(simpleSetting, accountService, - accountFactory, credentialService, credentialFactory, deviceRegistryService, userService, - userFactory, accessInfoService, accessInfoFactory, permissionFactory); diff --git a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessor.java b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessor.java index 74ac751b478..6da9b56e498 100644 --- a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessor.java +++ b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessor.java @@ -34,7 +34,6 @@ import org.eclipse.kapua.security.registration.simple.setting.SimpleSettingKeys; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.account.AccountCreator; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; import org.eclipse.kapua.service.authentication.credential.CredentialService; @@ -137,7 +136,6 @@ private static SimpleRegistrationProcessor.Settings applySimpleSettings(KapuaId } private final AccountService accountService; - private final AccountFactory accountFactory; private final CredentialService credentialService; @@ -157,7 +155,6 @@ private static SimpleRegistrationProcessor.Settings applySimpleSettings(KapuaId * Create a new simple registration processor * * @param accountService - * @param accountFactory * @param credentialService * @param deviceRegistryService * @param userService @@ -171,7 +168,6 @@ private static SimpleRegistrationProcessor.Settings applySimpleSettings(KapuaId */ public SimpleRegistrationProcessor( AccountService accountService, - AccountFactory accountFactory, CredentialService credentialService, DeviceRegistryService deviceRegistryService, UserService userService, @@ -181,7 +177,6 @@ public SimpleRegistrationProcessor( String claimName, Settings settings) { this.accountService = accountService; - this.accountFactory = accountFactory; this.credentialService = credentialService; this.deviceRegistryService = deviceRegistryService; this.userService = userService; diff --git a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessorProvider.java b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessorProvider.java index e1a225d1398..41764a165b3 100644 --- a/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessorProvider.java +++ b/service/security/registration/simple/src/main/java/org/eclipse/kapua/security/registration/simple/SimpleRegistrationProcessorProvider.java @@ -22,7 +22,6 @@ import org.eclipse.kapua.security.registration.RegistrationProcessorProvider; import org.eclipse.kapua.security.registration.simple.SimpleRegistrationProcessor.Settings; import org.eclipse.kapua.security.registration.simple.setting.SimpleSetting; -import org.eclipse.kapua.service.account.AccountFactory; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialService; @@ -30,19 +29,16 @@ import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.registry.DeviceRegistryService; -import org.eclipse.kapua.service.user.UserFactory; import org.eclipse.kapua.service.user.UserService; public class SimpleRegistrationProcessorProvider implements RegistrationProcessorProvider { private final SimpleSetting simpleSetting; private final AccountService accountService; - private final AccountFactory accountFactory; private final CredentialService credentialService; private final CredentialFactory credentialFactory; private final DeviceRegistryService deviceRegistryService; private final UserService userService; - private final UserFactory userFactory; private final AccessInfoService accessInfoService; private final AccessInfoFactory accessInfoFactory; private final PermissionFactory permissionFactory; @@ -51,23 +47,19 @@ public class SimpleRegistrationProcessorProvider implements RegistrationProcesso public SimpleRegistrationProcessorProvider( SimpleSetting simpleSetting, AccountService accountService, - AccountFactory accountFactory, CredentialService credentialService, CredentialFactory credentialFactory, DeviceRegistryService deviceRegistryService, UserService userService, - UserFactory userFactory, AccessInfoService accessInfoService, AccessInfoFactory accessInfoFactory, PermissionFactory permissionFactory) { this.simpleSetting = simpleSetting; this.accountService = accountService; - this.accountFactory = accountFactory; this.credentialService = credentialService; this.credentialFactory = credentialFactory; this.deviceRegistryService = deviceRegistryService; this.userService = userService; - this.userFactory = userFactory; this.accessInfoService = accessInfoService; this.accessInfoFactory = accessInfoFactory; this.permissionFactory = permissionFactory; @@ -79,7 +71,6 @@ public Set createAll() { return result .map(settings -> new SimpleRegistrationProcessor( accountService, - accountFactory, credentialService, deviceRegistryService, userService, diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImpl.java index ed85c4b0091..4e62beabd39 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImpl.java @@ -12,20 +12,21 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; +import java.util.Optional; import javax.validation.constraints.NotNull; -import java.util.Optional; + +import org.eclipse.kapua.service.authentication.SessionCredentials; +import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; /** - * {@link AccessTokenCredentials} implementation. + * {@link AccessTokenCredentialsImpl} implementation. *

* This implements also {@link KapuaAuthenticationToken} to allow usage in Apache Shiro. * * @since 1.0.0 */ -public class AccessTokenCredentialsImpl implements AccessTokenCredentials, KapuaAuthenticationToken { +public class AccessTokenCredentialsImpl implements KapuaAuthenticationToken, SessionCredentials { private static final long serialVersionUID = -7549848672967689716L; @@ -34,41 +35,42 @@ public class AccessTokenCredentialsImpl implements AccessTokenCredentials, Kapua /** * Constructor. * - * @param tokenId The credential JWT + * @param tokenId + * The credential JWT * @since 1.0.0 */ public AccessTokenCredentialsImpl(@NotNull String tokenId) { - setTokenId(tokenId); + this.tokenId = tokenId; } /** * Clone constructor. * - * @param accessTokenCredentials The {@link AccessTokenCredentials} to clone. + * @param accessTokenCredentials + * The {@link AccessTokenCredentialsImpl} to clone. * @since 1.5.0 */ - public AccessTokenCredentialsImpl(@NotNull AccessTokenCredentials accessTokenCredentials) { - setTokenId(accessTokenCredentials.getTokenId()); + public AccessTokenCredentialsImpl(@NotNull AccessTokenCredentialsImpl accessTokenCredentials) { + this.tokenId = accessTokenCredentials.getTokenId(); } - @Override public String getTokenId() { return tokenId; } - @Override - public void setTokenId(String tokenId) { + public AccessTokenCredentialsImpl setTokenId(String tokenId) { this.tokenId = tokenId; + return this; } @Override public Object getPrincipal() { - return getTokenId(); + return tokenId; } @Override public Object getCredentials() { - return getTokenId(); + return tokenId; } @Override diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImpl.java index 66a37bcc5ad..a54411ac37f 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro; -import org.eclipse.kapua.service.authentication.ApiKeyCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; +import java.util.Optional; import javax.validation.constraints.NotNull; -import java.util.Optional; + +import org.eclipse.kapua.service.authentication.ApiKeyCredentials; +import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; /** * {@link ApiKeyCredentials} implementation. @@ -25,7 +26,7 @@ * * @since 1.0.0 */ -public class ApiKeyCredentialsImpl implements ApiKeyCredentials, KapuaAuthenticationToken { +public class ApiKeyCredentialsImpl implements KapuaAuthenticationToken { private static final long serialVersionUID = -5920944517814926028L; @@ -34,33 +35,29 @@ public class ApiKeyCredentialsImpl implements ApiKeyCredentials, KapuaAuthentica /** * Constructor. * - * @param apiKey The Api Key. + * @param apiKey + * The Api Key. * @since 1.0.0 */ public ApiKeyCredentialsImpl(String apiKey) { - setApiKey(apiKey); + this.apiKey = apiKey; } /** * Clone constructor. * - * @param apiKeyCredentials The {@link ApiKeyCredentials} to clone. + * @param apiKeyCredentials + * The {@link ApiKeyCredentials} to clone. * @since 1.5.0 */ public ApiKeyCredentialsImpl(@NotNull ApiKeyCredentials apiKeyCredentials) { - setApiKey(apiKeyCredentials.getApiKey()); + this.apiKey = apiKeyCredentials.getApiKey(); } - @Override public String getApiKey() { return apiKey; } - @Override - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - @Override public Object getPrincipal() { return getApiKey(); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java index d3202f52d44..9c35f50072e 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java @@ -34,7 +34,6 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration; import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.commons.util.qr.QRCodeBuilder; @@ -48,12 +47,14 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.account.AccountService; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; -import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialRepository; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.credential.cache.CacheMetric; +import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; +import org.eclipse.kapua.service.authentication.credential.handler.shiro.ApiKeyCredentialTypeHandler; +import org.eclipse.kapua.service.authentication.credential.handler.shiro.JwtCredentialTypeHandler; +import org.eclipse.kapua.service.authentication.credential.handler.shiro.PasswordCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionFactory; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionRepository; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionService; @@ -66,12 +67,9 @@ import org.eclipse.kapua.service.authentication.credential.mfa.shiro.ScratchCodeFactoryImpl; import org.eclipse.kapua.service.authentication.credential.mfa.shiro.ScratchCodeImplJpaRepository; import org.eclipse.kapua.service.authentication.credential.mfa.shiro.ScratchCodeServiceImpl; -import org.eclipse.kapua.service.authentication.credential.handler.shiro.ApiKeyCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialFactoryImpl; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialImplJpaRepository; import org.eclipse.kapua.service.authentication.credential.shiro.CredentialServiceImpl; -import org.eclipse.kapua.service.authentication.credential.handler.shiro.JwtCredentialTypeHandler; -import org.eclipse.kapua.service.authentication.credential.handler.shiro.PasswordCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordResetter; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordValidator; import org.eclipse.kapua.service.authentication.credential.shiro.PasswordValidatorImpl; @@ -110,7 +108,6 @@ protected void configureModule() { bind(KapuaAuthenticationSetting.class).in(Singleton.class); bind(AuthenticationService.class).to(AuthenticationServiceShiroImpl.class).in(Singleton.class); bind(CredentialFactory.class).to(CredentialFactoryImpl.class).in(Singleton.class); - bind(CredentialsFactory.class).to(CredentialsFactoryImpl.class).in(Singleton.class); bind(MfaOptionFactory.class).to(MfaOptionFactoryImpl.class).in(Singleton.class); bind(ScratchCodeFactory.class).to(ScratchCodeFactoryImpl.class).in(Singleton.class); bind(AccessTokenFactory.class).to(AccessTokenFactoryImpl.class).in(Singleton.class); @@ -148,7 +145,6 @@ public ServiceModule authenticationServiceModule(AccessTokenService accessTokenS AuthorizationService authorizationService, PermissionFactory permissionFactory, KapuaJpaTxManagerFactory txManagerFactory, - EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAuthenticationSetting kapuaAuthenticationSetting, @@ -163,7 +159,6 @@ public ServiceModule authenticationServiceModule(AccessTokenService accessTokenS authorizationService, permissionFactory, txManagerFactory.create("kapua-authentication"), - eventStoreFactory, eventStoreRecordRepository ), txManagerFactory.create("kapua-authentication"), @@ -375,7 +370,6 @@ public CredentialTypeHandler passwordCredentialTypeHandler( passwordValidator); } - @ProvidesIntoSet public CredentialTypeHandler apiKeyCredentialTypeHandler( AuthenticationUtils authenticationUtils, diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java index 78cfc1a1020..37deea95bf0 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationServiceShiroImpl.java @@ -72,21 +72,17 @@ import org.eclipse.kapua.service.authorization.access.AccessInfo; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; -import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory; import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult; import org.eclipse.kapua.service.authorization.access.AccessPermissionService; import org.eclipse.kapua.service.authorization.access.AccessRole; import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes; -import org.eclipse.kapua.service.authorization.access.AccessRoleFactory; import org.eclipse.kapua.service.authorization.access.AccessRoleListResult; import org.eclipse.kapua.service.authorization.access.AccessRoleService; import org.eclipse.kapua.service.authorization.role.RolePermissionAttributes; -import org.eclipse.kapua.service.authorization.role.RolePermissionFactory; import org.eclipse.kapua.service.authorization.role.RolePermissionListResult; import org.eclipse.kapua.service.authorization.role.RolePermissionService; import org.eclipse.kapua.service.certificate.Certificate; import org.eclipse.kapua.service.certificate.CertificateAttributes; -import org.eclipse.kapua.service.certificate.CertificateFactory; import org.eclipse.kapua.service.certificate.CertificateQuery; import org.eclipse.kapua.service.certificate.CertificateService; import org.eclipse.kapua.service.certificate.CertificateStatus; @@ -125,15 +121,11 @@ public class AuthenticationServiceShiroImpl implements AuthenticationService { private final AccessTokenService accessTokenService; private final AccessTokenFactory accessTokenFactory; private final CertificateService certificateService; - private final CertificateFactory certificateFactory; private final AccessInfoService accessInfoService; private final AccessRoleService accessRoleService; - private final AccessRoleFactory accessRoleFactory; private final RolePermissionService rolePermissionService; - private final RolePermissionFactory rolePermissionFactory; private final AccessPermissionService accessPermissionService; - private final AccessPermissionFactory accessPermissionFactory; private final UserService userService; @@ -149,14 +141,10 @@ public AuthenticationServiceShiroImpl( AccessTokenService accessTokenService, AccessTokenFactory accessTokenFactory, CertificateService certificateService, - CertificateFactory certificateFactory, AccessInfoService accessInfoService, AccessRoleService accessRoleService, - AccessRoleFactory accessRoleFactory, RolePermissionService rolePermissionService, - RolePermissionFactory rolePermissionFactory, AccessPermissionService accessPermissionService, - AccessPermissionFactory accessPermissionFactory, UserService userService, Set credentialsConverters, KapuaAuthenticationSetting kapuaAuthenticationSetting) { @@ -165,14 +153,10 @@ public AuthenticationServiceShiroImpl( this.accessTokenService = accessTokenService; this.accessTokenFactory = accessTokenFactory; this.certificateService = certificateService; - this.certificateFactory = certificateFactory; this.accessInfoService = accessInfoService; this.accessRoleService = accessRoleService; - this.accessRoleFactory = accessRoleFactory; this.rolePermissionService = rolePermissionService; - this.rolePermissionFactory = rolePermissionFactory; this.accessPermissionService = accessPermissionService; - this.accessPermissionFactory = accessPermissionFactory; this.userService = userService; this.credentialsConverters = credentialsConverters; this.kapuaAuthenticationSetting = kapuaAuthenticationSetting; @@ -187,8 +171,7 @@ public AuthenticationServiceShiroImpl( public AccessToken login(LoginCredentials loginCredentials, boolean enableTrust) throws KapuaException { if (loginCredentials instanceof UsernamePasswordCredentials) { - UsernamePasswordCredentialsImpl usernamePasswordCredentials = UsernamePasswordCredentialsImpl.parse((UsernamePasswordCredentials) loginCredentials); - usernamePasswordCredentials.setTrustMe(enableTrust); + ((UsernamePasswordCredentials) loginCredentials).setTrustMe(enableTrust); } return login(loginCredentials); @@ -598,7 +581,7 @@ private AccessToken createAccessToken(KapuaEid scopeId, KapuaEid userId) throws */ private void createTrustKey(AuthenticationToken shiroAuthenticationToken, AccessToken accessToken) throws KapuaException { if (shiroAuthenticationToken instanceof UsernamePasswordCredentials) { - UsernamePasswordCredentialsImpl usernamePasswordCredentials = UsernamePasswordCredentialsImpl.parse((UsernamePasswordCredentials) shiroAuthenticationToken); + UsernamePasswordCredentials usernamePasswordCredentials = (UsernamePasswordCredentials) shiroAuthenticationToken; if (usernamePasswordCredentials.getTrustMe()) { String trustKey = KapuaSecurityUtils.doPrivileged(() -> { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImpl.java deleted file mode 100644 index a7151beee16..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro; - -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; -import org.eclipse.kapua.service.authentication.ApiKeyCredentials; -import org.eclipse.kapua.service.authentication.CredentialsFactory; -import org.eclipse.kapua.service.authentication.JwtCredentials; -import org.eclipse.kapua.service.authentication.RefreshTokenCredentials; -import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; - -import javax.inject.Singleton; - -/** - * {@link CredentialsFactory} factory implementation. - * - * @since 1.0 - * - */ -@Singleton -public class CredentialsFactoryImpl implements CredentialsFactory { - - @Override - public UsernamePasswordCredentials newUsernamePasswordCredentials(String username, String password) { - return new UsernamePasswordCredentialsImpl(username, password); - } - - @Override - public ApiKeyCredentials newApiKeyCredentials(String apiKey) { - return new ApiKeyCredentialsImpl(apiKey); - } - - @Override - public JwtCredentials newJwtCredentials(String accessToken, String idToken) { - return new JwtCredentialsImpl(accessToken, idToken); - } - - @Override - public AccessTokenCredentials newAccessTokenCredentials(String tokenId) { - return new AccessTokenCredentialsImpl(tokenId); - } - - @Override - public RefreshTokenCredentials newRefreshTokenCredentials(String tokenId, String refreshToken) { - return new RefreshTokenCredentialsImpl(tokenId, refreshToken); - } - -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsImpl.java index bfd865e14a3..1463ea12ab9 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsImpl.java @@ -12,11 +12,12 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro; -import org.eclipse.kapua.service.authentication.JwtCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; +import java.util.Optional; import javax.validation.constraints.NotNull; -import java.util.Optional; + +import org.eclipse.kapua.service.authentication.JwtCredentials; +import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; /** * {@link JwtCredentials} implementation. @@ -25,68 +26,43 @@ * * @since 1.0.0 */ -public class JwtCredentialsImpl implements JwtCredentials, KapuaAuthenticationToken { - - private static final long serialVersionUID = -5920944517814926028L; +public class JwtCredentialsImpl implements KapuaAuthenticationToken { private String accessToken; private String idToken; - /** - * Constructor. - * - * @param accessToken The credential access token - * @param idToken The credential id token. - * @since 1.4.0 - */ - public JwtCredentialsImpl(String accessToken, String idToken) { - setAccessToken(accessToken); - setIdToken(idToken); - } - /** * Clone constructor. * - * @param jwtCredentials The {@link JwtCredentials} to clone + * @param jwtCredentials + * The {@link JwtCredentials} to clone * @since 1.5.0 */ public JwtCredentialsImpl(@NotNull JwtCredentials jwtCredentials) { - setAccessToken(jwtCredentials.getAccessToken()); - setIdToken(jwtCredentials.getIdToken()); + this.accessToken = jwtCredentials.getAccessToken(); + this.idToken = jwtCredentials.getIdToken(); } - @Override public String getAccessToken() { return accessToken; } - @Override - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - @Override public String getIdToken() { return idToken; } - @Override - public void setIdToken(String idToken) { - this.idToken = idToken; - } - @Override public Object getPrincipal() { - return getAccessToken(); + return this.accessToken; } @Override public Object getCredentials() { - return getAccessToken(); + return this.accessToken; } @Override public Optional getOpenIdToken() { - return Optional.of(getIdToken()); + return Optional.of(this.idToken); } } diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImpl.java deleted file mode 100644 index 260261dc1cc..00000000000 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro; - -import org.apache.shiro.authc.AuthenticationToken; -import org.eclipse.kapua.service.authentication.RefreshTokenCredentials; -import org.eclipse.kapua.service.authentication.token.AccessToken; - -/** - * {@link RefreshTokenCredentials} implementation. - *

- * This implements also {@link AuthenticationToken} to allow usage in Apache Shiro. - * - * @since 1.0.0 - */ -public class RefreshTokenCredentialsImpl implements RefreshTokenCredentials { - - private String tokenId; - private String refreshToken; - - /** - * Constructor. - * - * @param tokenId The {@link AccessToken#getTokenId()} - * @param refreshToken TThe {@link AccessToken#getRefreshToken()} - * @since 1.0.0 - */ - public RefreshTokenCredentialsImpl(String tokenId, String refreshToken) { - this.tokenId = tokenId; - this.refreshToken = refreshToken; - } - - @Override - public String getTokenId() { - return tokenId; - } - - @Override - public void setTokenId(String tokenId) { - this.tokenId = tokenId; - } - - @Override - public String getRefreshToken() { - return refreshToken; - } - - @Override - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - -} diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImpl.java index 3eec0a604d7..4b507798fa7 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImpl.java @@ -12,13 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro; +import java.util.Optional; + +import javax.validation.constraints.NotNull; + import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.shiro.realm.KapuaAuthenticationToken; -import javax.validation.constraints.NotNull; -import java.util.Optional; - /** * {@link UsernamePasswordCredentials} implementation. *

@@ -26,7 +27,7 @@ * * @since 1.0.0 */ -public class UsernamePasswordCredentialsImpl implements UsernamePasswordCredentials, KapuaAuthenticationToken { +public class UsernamePasswordCredentialsImpl implements KapuaAuthenticationToken { private static final long serialVersionUID = -7549848672967689716L; @@ -34,52 +35,51 @@ public class UsernamePasswordCredentialsImpl implements UsernamePasswordCredenti private String password; private String authenticationCode; private String trustKey; - private boolean trustMe; + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getAuthenticationCode() { + return authenticationCode; + } + + public String getTrustKey() { + return trustKey; + } /** * Constructor. * - * @param username The credential username. - * @param password The credential password. + * @param username + * The credential username. + * @param password + * The credential password. * @since 1.0.0 */ public UsernamePasswordCredentialsImpl(@NotNull String username, @NotNull String password) { - setUsername(username); - setPassword(password); + this.username = username; + this.password = password; + this.authenticationCode = null; + this.trustKey = null; } /** * Clone constructor. * - * @param usernamePasswordCredentials The {@link UsernamePasswordCredentials} to clone. + * @param usernamePasswordCredentials + * The {@link UsernamePasswordCredentials} to clone. * @since 1.5.0 */ public UsernamePasswordCredentialsImpl(@NotNull UsernamePasswordCredentials usernamePasswordCredentials) { - setUsername(usernamePasswordCredentials.getUsername()); - setPassword(usernamePasswordCredentials.getPassword()); - setAuthenticationCode(usernamePasswordCredentials.getAuthenticationCode()); - setTrustKey(usernamePasswordCredentials.getTrustKey()); - setTrustMe(usernamePasswordCredentials.getTrustMe()); - } - - @Override - public String getUsername() { - return username; - } - - @Override - public void setUsername(String username) { - this.username = username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public void setPassword(String password) { - this.password = password; + this.username = usernamePasswordCredentials.getUsername(); + this.password = usernamePasswordCredentials.getPassword(); + this.authenticationCode = usernamePasswordCredentials.getAuthenticationCode(); + this.trustKey = usernamePasswordCredentials.getTrustKey(); } @Override @@ -92,48 +92,17 @@ public Object getCredentials() { return password; } - @Override - public String getAuthenticationCode() { - return authenticationCode; - } - - @Override - public void setAuthenticationCode(String authenticationCode) { - this.authenticationCode = authenticationCode; - } - - @Override - public String getTrustKey() { - return trustKey; - } - - @Override - public void setTrustKey(String trustKey) { - this.trustKey = trustKey; - } - - @Override - public boolean getTrustMe() { - return trustMe; - } - - @Override - public void setTrustMe(boolean trustMe) { - this.trustMe = trustMe; - } - /** * Parses a {@link UsernamePasswordCredentials} into a {@link UsernamePasswordCredentialsImpl}. * - * @param usernamePasswordCredentials The {@link UsernamePasswordCredentials} to parse. + * @param usernamePasswordCredentials + * The {@link UsernamePasswordCredentials} to parse. * @return An instance of {@link UsernamePasswordCredentialsImpl}. * @since 1.5.0 */ public static UsernamePasswordCredentialsImpl parse(@Nullable UsernamePasswordCredentials usernamePasswordCredentials) { return usernamePasswordCredentials != null ? - (usernamePasswordCredentials instanceof UsernamePasswordCredentialsImpl ? - (UsernamePasswordCredentialsImpl) usernamePasswordCredentials : - new UsernamePasswordCredentialsImpl(usernamePasswordCredentials)) + new UsernamePasswordCredentialsImpl(usernamePasswordCredentials) : null; } diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java index 54ad5241ade..a289344f51a 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenAuthenticatingRealm.java @@ -31,7 +31,6 @@ import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.account.Account; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.exceptions.ExpiredAccessTokenException; import org.eclipse.kapua.service.authentication.shiro.exceptions.InvalidatedAccessTokenException; @@ -63,7 +62,7 @@ import org.slf4j.LoggerFactory; /** - * {@link AccessTokenCredentials} based {@link AuthenticatingRealm} implementation. + * {@link AccessTokenCredentialsImpl} based {@link AuthenticatingRealm} implementation. * * @since 1.0.0 */ diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverter.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverter.java index b92e2176c04..97bbfcbdf5d 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverter.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverter.java @@ -12,15 +12,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro.realm; -import com.google.common.base.Strings; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; import org.eclipse.kapua.service.authentication.AuthenticationCredentials; import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationErrorCodes; import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationException; import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; +import com.google.common.base.Strings; + /** - * {@link AccessTokenCredentials} {@link CredentialsConverter} implementation. + * {@link AccessTokenCredentialsImpl} {@link CredentialsConverter} implementation. * * @since 2.0.0 */ @@ -28,7 +28,7 @@ public class AccessTokenCredentialsConverter implements CredentialsConverter { @Override public boolean canProcess(AuthenticationCredentials authenticationCredentials) { - return authenticationCredentials instanceof AccessTokenCredentials; + return authenticationCredentials instanceof AccessTokenCredentialsImpl; } @Override @@ -36,7 +36,7 @@ public KapuaAuthenticationToken convertToShiro(AuthenticationCredentials authent AccessTokenCredentialsImpl accessTokenCredentials = authenticationCredentials instanceof AccessTokenCredentialsImpl ? (AccessTokenCredentialsImpl) authenticationCredentials : - new AccessTokenCredentialsImpl((AccessTokenCredentials) authenticationCredentials); + new AccessTokenCredentialsImpl((AccessTokenCredentialsImpl) authenticationCredentials); if (Strings.isNullOrEmpty(accessTokenCredentials.getTokenId())) { throw new KapuaAuthenticationException(KapuaAuthenticationErrorCodes.INVALID_SESSION_CREDENTIALS); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java index 6ad2172e746..f0483b501ff 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsMatcher.java @@ -19,7 +19,7 @@ import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.query.SortOrder; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; +import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.exceptions.JwtCertificateNotFoundException; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSetting; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSettingKeys; @@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory; /** - * {@link AccessTokenCredentials} {@link CredentialsMatcher} implementation. + * {@link AccessTokenCredentialsImpl} {@link CredentialsMatcher} implementation. * * @since 1.0.0 */ diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtAuthenticatingRealm.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtAuthenticatingRealm.java index 9f5c3ac444c..4904ac67045 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtAuthenticatingRealm.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtAuthenticatingRealm.java @@ -13,7 +13,8 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro.realm; -import com.google.common.base.Strings; +import javax.json.JsonObject; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.ShiroException; import org.apache.shiro.authc.AuthenticationException; @@ -44,7 +45,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.json.JsonObject; +import com.google.common.base.Strings; /** * {@link ApiKeyCredentials} based {@link AuthenticatingRealm} implementation. @@ -193,9 +194,11 @@ public boolean supports(AuthenticationToken authenticationToken) { /** * Extract the subject information * - * @param jwt the token to use + * @param jwt + * the token to use * @return the subject, never returns {@code null} - * @throws ShiroException in case the subject could not be extracted + * @throws ShiroException + * in case the subject could not be extracted * @since 1.0.0 */ private String extractExternalId(String jwt) { @@ -217,7 +220,8 @@ private String extractExternalId(String jwt) { /** * Extract the external username information * - * @param jwt the token to use. + * @param jwt + * the token to use. * @return the external username. * @since 2.0.0 */ @@ -236,7 +240,8 @@ private String extractExternalUsername(String jwt) { /** * Extract the external username * - * @param userInfo the userInfo to use. + * @param userInfo + * the userInfo to use. * @return the external username. * @since 2.0.0 */ @@ -254,12 +259,13 @@ private String extractExternalUsername(JsonObject userInfo) { /** * Tries to resolve {@link User#getExternalUsername()} using the {@link OpenIDService#getUserInfo(String)} resource. * - * @param jwtCredentials The {@link JwtCredentials}. + * @param jwtCredentials + * The {@link JwtCredentials}. * @return The updated user. * @throws KapuaException * @since 2.0.0 */ - private User resolveExternalUsernameWithOpenIdProvider(JwtCredentials jwtCredentials) throws KapuaException { + private User resolveExternalUsernameWithOpenIdProvider(JwtCredentialsImpl jwtCredentials) throws KapuaException { // Ask to the OpenId Provider the user's info JsonObject userInfo = openIDService.getUserInfo(jwtCredentials.getAccessToken()); @@ -287,7 +293,8 @@ private User resolveExternalUsernameWithOpenIdProvider(JwtCredentials jwtCredent /** * Updates the given {@link User}. * - * @param user The user to update. + * @param user + * The user to update. * @return The updated user. * @throws KapuaException * @since 2.0.0 diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsMatcher.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsMatcher.java index 3c6b49daac9..37909351d25 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsMatcher.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsMatcher.java @@ -13,22 +13,21 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro.realm; +import javax.validation.constraints.NotNull; + import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.authc.credential.CredentialsMatcher; +import org.eclipse.kapua.plugin.sso.openid.JwtProcessor; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.shiro.JwtCredentialsImpl; -import org.eclipse.kapua.plugin.sso.openid.JwtProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.validation.constraints.NotNull; - /** * {@link JwtCredentialsMatcher} credential matcher implementation * * @since 1.0 - * */ public class JwtCredentialsMatcher implements CredentialsMatcher { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsMatcher.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsMatcher.java index 8f37cd1d8b8..042073a9b23 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsMatcher.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsMatcher.java @@ -12,6 +12,14 @@ *******************************************************************************/ package org.eclipse.kapua.service.authentication.shiro.realm; +import java.io.UnsupportedEncodingException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.spec.InvalidKeySpecException; + +import javax.crypto.NoSuchPaddingException; + import org.apache.shiro.ShiroException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; @@ -20,7 +28,6 @@ import org.eclipse.kapua.KapuaRuntimeException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.service.authentication.ApiKeyCredentials; -import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.cache.CacheMetric; import org.eclipse.kapua.service.authentication.credential.cache.CachedPasswordMatcher; @@ -29,19 +36,13 @@ import org.eclipse.kapua.service.authentication.credential.handler.shiro.PasswordCredentialTypeHandler; import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionService; import org.eclipse.kapua.service.authentication.shiro.AuthenticationServiceShiroImpl; +import org.eclipse.kapua.service.authentication.shiro.UsernamePasswordCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSetting; import org.eclipse.kapua.service.authentication.shiro.setting.KapuaAuthenticationSettingKeys; import org.eclipse.kapua.service.user.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.crypto.NoSuchPaddingException; -import java.io.UnsupportedEncodingException; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; - /** * {@link ApiKeyCredentials} {@link CredentialsMatcher} implementation. * @@ -77,7 +78,7 @@ public UserPassCredentialsMatcher() { @Override public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) { // Token data - UsernamePasswordCredentials token = (UsernamePasswordCredentials) authenticationToken; + UsernamePasswordCredentialsImpl token = (UsernamePasswordCredentialsImpl) authenticationToken; String tokenUsername = token.getUsername(); String tokenPassword = token.getPassword(); String tokenAuthenticationCode = token.getAuthenticationCode(); diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsModule.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsModule.java index 9d699b9cf8e..614dc608722 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsModule.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsModule.java @@ -20,7 +20,6 @@ import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialRepository; import org.eclipse.kapua.service.authentication.credential.handler.CredentialTypeHandler; @@ -73,7 +72,6 @@ UserCredentialsService userCredentialsService( AuthenticationService authenticationService, AuthorizationService authorizationService, PermissionFactory permissionFactory, - CredentialsFactory credentialsFactory, CredentialFactory credentialFactory, KapuaJpaTxManagerFactory txManagerFactory, UserService userService, @@ -83,7 +81,6 @@ UserCredentialsService userCredentialsService( authenticationService, authorizationService, permissionFactory, - credentialsFactory, credentialFactory, txManagerFactory.create("kapua-authorization"), userService, diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsServiceImpl.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsServiceImpl.java index 468c9bb0b1e..da3d4a581e9 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsServiceImpl.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/user/shiro/UserCredentialsServiceImpl.java @@ -25,7 +25,6 @@ import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialFactory; @@ -53,7 +52,6 @@ public class UserCredentialsServiceImpl implements UserCredentialsService { private final AuthenticationService authenticationService; private final AuthorizationService authorizationService; private final PermissionFactory permissionFactory; - private final CredentialsFactory credentialsFactory; private final CredentialFactory credentialFactory; private final TxManager txManager; private final UserService userService; @@ -63,7 +61,6 @@ public class UserCredentialsServiceImpl implements UserCredentialsService { public UserCredentialsServiceImpl( AuthenticationService authenticationService, AuthorizationService authorizationService, PermissionFactory permissionFactory, - CredentialsFactory credentialsFactory, CredentialFactory credentialFactory, TxManager txManager, UserService userService, @@ -72,7 +69,6 @@ public UserCredentialsServiceImpl( this.authenticationService = authenticationService; this.authorizationService = authorizationService; this.permissionFactory = permissionFactory; - this.credentialsFactory = credentialsFactory; this.credentialFactory = credentialFactory; this.txManager = txManager; this.userService = userService; @@ -90,7 +86,7 @@ public Credential changePassword(KapuaId scopeId, KapuaId userId, PasswordChange final User user = Optional.ofNullable(KapuaSecurityUtils.doPrivileged(() -> userService.find(scopeId, userId)) ).orElseThrow(() -> new KapuaEntityNotFoundException(User.TYPE, userId)); return txManager.execute(tx -> { - final UsernamePasswordCredentials usernamePasswordCredentials = credentialsFactory.newUsernamePasswordCredentials(user.getName(), passwordChangeRequest.getCurrentPassword()); + final UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(user.getName(), passwordChangeRequest.getCurrentPassword()); try { authenticationService.verifyCredentials(usernamePasswordCredentials); } catch (KapuaAuthenticationException e) { diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java index ab46f2fd679..66057938c10 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java @@ -32,7 +32,6 @@ import org.eclipse.kapua.commons.jpa.NamedCacheFactory; import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.commons.service.internal.cache.KapuaCacheManager; @@ -155,7 +154,6 @@ ServiceModule authorizationServiceModule(AccessInfoService accessInfoService, AuthorizationService authorizationService, PermissionFactory permissionFactory, KapuaJpaTxManagerFactory txManagerFactory, - EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAuthorizationSetting kapuaAuthorizationSetting, @@ -172,7 +170,6 @@ ServiceModule authorizationServiceModule(AccessInfoService accessInfoService, authorizationService, permissionFactory, txManagerFactory.create("kapua-authorization"), - eventStoreFactory, eventStoreRecordRepository ), txManagerFactory.create("kapua-authorization"), @@ -265,7 +262,6 @@ RoleService roleService(PermissionFactory permissionFactory, @Singleton @Named("RoleServiceConfigurationManager") public ServiceConfigurationManager roleServiceConfigurationManager( - RoleFactory roleFactory, RootUserTester rootUserTester, AccountRelativeFinder accountRelativeFinder, RoleRepository roleRepository, @@ -283,7 +279,6 @@ public ServiceConfigurationManager roleServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - roleFactory, roleRepository ), xmlUtil)); @@ -338,7 +333,6 @@ public ServiceConfigurationManager groupServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - factory, groupRepository ), xmlUtil)); } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImplTest.java index 04a54937b60..f89959c40aa 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/AccessTokenCredentialsImplTest.java @@ -13,19 +13,16 @@ package org.eclipse.kapua.service.authentication.shiro; import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.model.AccessTokenCredentialsAnotherImpl; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; - @Category(JUnitTests.class) public class AccessTokenCredentialsImplTest { @Test(expected = NullPointerException.class) public void accessTokenCredentialsImplCloneConstructorNullTest() { - new AccessTokenCredentialsImpl((AccessTokenCredentials) null); + new AccessTokenCredentialsImpl((AccessTokenCredentialsImpl) null); } @Test @@ -40,7 +37,7 @@ public void accessTokenCredentialsImplCloneConstructorImplTest() { @Test public void accessTokenCredentialsImplCloneConstructorAnotherTest() { - AccessTokenCredentials first = new AccessTokenCredentialsAnotherImpl("anAccessToken"); + AccessTokenCredentialsImpl first = new AccessTokenCredentialsImpl("anAccessToken"); AccessTokenCredentialsImpl second = new AccessTokenCredentialsImpl(first); @@ -50,7 +47,7 @@ public void accessTokenCredentialsImplCloneConstructorAnotherTest() { @Test public void accessTokenCredentialsImplTokenIdParameterTest() { - String[] tokenIds = {null, "", "!!tokenID-1", "#1(TOKEN.,/token id)9--99", "!$$ 1-2 ID//", "id_tokeN(....)<00>"}; + String[] tokenIds = { null, "", "!!tokenID-1", "#1(TOKEN.,/token id)9--99", "!$$ 1-2 ID//", "id_tokeN(....)<00>" }; for (String tokenId : tokenIds) { AccessTokenCredentialsImpl accessTokenCredentialsImpl = new AccessTokenCredentialsImpl(tokenId); @@ -62,12 +59,14 @@ public void accessTokenCredentialsImplTokenIdParameterTest() { @Test public void setAndGetTokenIdPrincipalAndCredentialsTest() { - String[] newTokenIds = {null, "", "!!NEWtokenID-1", "#1(newTOKEN.,/token id)9--99", "!$$ 1-2new ID//", "id_tokeN NEW ID(....)<00>"}; - AccessTokenCredentialsImpl accessTokenCredentialsImpl = new AccessTokenCredentialsImpl("token id"); + String[] newTokenIds = { null, "", "!!NEWtokenID-1", "#1(newTOKEN.,/token id)9--99", "!$$ 1-2new ID//", "id_tokeN NEW ID(....)<00>" }; + AccessTokenCredentialsImpl accessTokenCredentials = new AccessTokenCredentialsImpl("token id"); for (String newTokenId : newTokenIds) { - accessTokenCredentialsImpl.setTokenId(newTokenId); - Assert.assertEquals("Expected and actual values should be the same.", newTokenId, accessTokenCredentialsImpl.getTokenId()); + accessTokenCredentials.setTokenId(newTokenId); + Assert.assertEquals("Expected and actual values should be the same.", newTokenId, accessTokenCredentials.getTokenId()); + AccessTokenCredentialsImpl accessTokenCredentialsImpl = new AccessTokenCredentialsImpl(accessTokenCredentials); + accessTokenCredentials.setTokenId(newTokenId); Assert.assertEquals("Expected and actual values should be the same.", newTokenId, accessTokenCredentialsImpl.getPrincipal()); Assert.assertEquals("Expected and actual values should be the same.", newTokenId, accessTokenCredentialsImpl.getCredentials()); } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImplTest.java index 46f0293b37b..d2474e8f895 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/ApiKeyCredentialsImplTest.java @@ -14,12 +14,10 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.ApiKeyCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.model.ApiKeyCredentialsAnotherImpl; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; - @Category(JUnitTests.class) public class ApiKeyCredentialsImplTest { @@ -30,17 +28,7 @@ public void apiKeyCredentialsImplCloneConstructorNullTest() { @Test public void apiKeyCredentialsImplCloneConstructorImplTest() { - ApiKeyCredentialsImpl first = new ApiKeyCredentialsImpl("anApiKey"); - - ApiKeyCredentialsImpl second = new ApiKeyCredentialsImpl(first); - - Assert.assertNotEquals("ApiKeyCredentialImpl", first, second); - Assert.assertEquals("ApiKeyCredential.apiKey", first.getApiKey(), second.getApiKey()); - } - - @Test - public void apiKeyCredentialsImplCloneConstructorAnotherTest() { - ApiKeyCredentials first = new ApiKeyCredentialsAnotherImpl("anApiKey"); + ApiKeyCredentials first = new ApiKeyCredentials("anApiKey"); ApiKeyCredentialsImpl second = new ApiKeyCredentialsImpl(first); @@ -50,7 +38,7 @@ public void apiKeyCredentialsImplCloneConstructorAnotherTest() { @Test public void apiKeyCredentialsImplTest() { - String[] apiKeys = {null, "", "!!api key-1", "#1(API KEY.,/api key)9--99", "!$$ 1-2 KEY//", "APIkey(....)<00>"}; + String[] apiKeys = { null, "", "!!api key-1", "#1(API KEY.,/api key)9--99", "!$$ 1-2 KEY//", "APIkey(....)<00>" }; for (String apiKey : apiKeys) { ApiKeyCredentialsImpl apiKeyCredentialsImpl = new ApiKeyCredentialsImpl(apiKey); @@ -62,11 +50,12 @@ public void apiKeyCredentialsImplTest() { @Test public void setAndGetApiKeyPrincipalAndCredentialsTest() { - String[] newApiKeys = {null, "", "!!api key-1NEW", "#1(new API KEY.,/api key)9--99", "!$$ 1-2 newKEY//", "NEwAPIkey(....)<00>"}; - ApiKeyCredentialsImpl apiKeyCredentialsImpl = new ApiKeyCredentialsImpl("apiKey"); + String[] newApiKeys = { null, "", "!!api key-1NEW", "#1(new API KEY.,/api key)9--99", "!$$ 1-2 newKEY//", "NEwAPIkey(....)<00>" }; + ApiKeyCredentials apiKeyCredentials = new ApiKeyCredentials("apiKey"); for (String newApiKey : newApiKeys) { - apiKeyCredentialsImpl.setApiKey(newApiKey); + apiKeyCredentials.setApiKey(newApiKey); + ApiKeyCredentialsImpl apiKeyCredentialsImpl = new ApiKeyCredentialsImpl(apiKeyCredentials); Assert.assertEquals("Expected and actual values should be the same.", newApiKey, apiKeyCredentialsImpl.getApiKey()); Assert.assertEquals("Expected and actual values should be the same.", newApiKey, apiKeyCredentialsImpl.getPrincipal()); Assert.assertEquals("Expected and actual values should be the same.", newApiKey, apiKeyCredentialsImpl.getCredentials()); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryTest.java similarity index 63% rename from service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImplTest.java rename to service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryTest.java index 25c28463c56..9c8ee27c15e 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryImplTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/CredentialsFactoryTest.java @@ -13,40 +13,36 @@ package org.eclipse.kapua.service.authentication.shiro; import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; import org.eclipse.kapua.service.authentication.ApiKeyCredentials; import org.eclipse.kapua.service.authentication.JwtCredentials; import org.eclipse.kapua.service.authentication.RefreshTokenCredentials; - +import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; - @Category(JUnitTests.class) -public class CredentialsFactoryImplTest { +public class CredentialsFactoryTest { - CredentialsFactoryImpl credentialsFactoryImpl; String[] usernames, passwords, apiKeys, idTokens, accessTokens, refreshTokens; @Before public void initialize() { - credentialsFactoryImpl = new CredentialsFactoryImpl(); - usernames = new String[]{null, "", "user_name123!!", "user#999username", "USERNAME_9", "user,,,,name", "... us_er%%67na*(me"}; - passwords = new String[]{null, "", "pass-word0000@!!,,,#", "!@#00PaSSwOrD.", " password ---44<>", "pA_ss0###woE**9()", " pass0wo-rd 12344*&^%"}; - apiKeys = new String[]{null, "", "api_key1122#$%", " aPi)(..,,KEY", "apiKEYYY ./??)_)*", "<> 1111 ", "keyyy&^$$##Z||'", "%%%KEY api-key11"}; - idTokens = new String[]{null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&"}; - accessTokens = new String[]{null, "", " j_w=t110.,<> jwt", "(!!)432j&^w$#3t", "##<>/.JWT ", "__J!#W(-8T ", "jw&* 990t ", "jwt987)_=;''' .", "jwt JWT-123"}; - refreshTokens = new String[]{null, "", " refresh tokenREFRESH 747.,.,,,82(*&%<> ", " token((11@-", "REFresh)__.,TOKen65", "TOKENrefresh543$#%&t oken", "to-ken_++rE=fresh,", "refresh,,,,id3$^&"}; + usernames = new String[] { null, "", "user_name123!!", "user#999username", "USERNAME_9", "user,,,,name", "... us_er%%67na*(me" }; + passwords = new String[] { null, "", "pass-word0000@!!,,,#", "!@#00PaSSwOrD.", " password ---44<>", "pA_ss0###woE**9()", " pass0wo-rd 12344*&^%" }; + apiKeys = new String[] { null, "", "api_key1122#$%", " aPi)(..,,KEY", "apiKEYYY ./??)_)*", "<> 1111 ", "keyyy&^$$##Z||'", "%%%KEY api-key11" }; + idTokens = new String[] { null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&" }; + accessTokens = new String[] { null, "", " j_w=t110.,<> jwt", "(!!)432j&^w$#3t", "##<>/.JWT ", "__J!#W(-8T ", "jw&* 990t ", "jwt987)_=;''' .", "jwt JWT-123" }; + refreshTokens = new String[] { null, "", " refresh tokenREFRESH 747.,.,,,82(*&%<> ", " token((11@-", "REFresh)__.,TOKen65", "TOKENrefresh543$#%&t oken", "to-ken_++rE=fresh,", + "refresh,,,,id3$^&" }; } @Test public void newUsernamePasswordCredentialsTest() { for (String username : usernames) { for (String password : passwords) { - UsernamePasswordCredentials usernamePasswordCredentials = credentialsFactoryImpl.newUsernamePasswordCredentials(username, password); + UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password); Assert.assertEquals("Expected and actual values should be the same.", username, usernamePasswordCredentials.getUsername()); Assert.assertEquals("Expected and actual values should be the same.", password, usernamePasswordCredentials.getPassword()); } @@ -56,7 +52,7 @@ public void newUsernamePasswordCredentialsTest() { @Test public void newApiKeyCredentialsTest() { for (String apiKey : apiKeys) { - ApiKeyCredentials apiKeyCredentials = credentialsFactoryImpl.newApiKeyCredentials(apiKey); + ApiKeyCredentials apiKeyCredentials = new ApiKeyCredentials(apiKey); Assert.assertEquals("Expected and actual values should be the same.", apiKey, apiKeyCredentials.getApiKey()); } } @@ -65,7 +61,7 @@ public void newApiKeyCredentialsTest() { public void newJwtCredentialsTest() { for (String accessToken : accessTokens) { for (String idToken : idTokens) { - JwtCredentials jwtCredentials = credentialsFactoryImpl.newJwtCredentials(accessToken, idToken); + JwtCredentials jwtCredentials = new JwtCredentials(accessToken, idToken); Assert.assertEquals("Expected and actual values should be the same.", accessToken, jwtCredentials.getAccessToken()); Assert.assertEquals("Expected and actual values should be the same.", idToken, jwtCredentials.getIdToken()); } @@ -73,9 +69,9 @@ public void newJwtCredentialsTest() { } @Test - public void newAccessTokenCredentialsTest() { + public void newAccessTokenCredentialsImplTest() { for (String idToken : idTokens) { - AccessTokenCredentials accessTokenCredentials = credentialsFactoryImpl.newAccessTokenCredentials(idToken); + AccessTokenCredentialsImpl accessTokenCredentials = new AccessTokenCredentialsImpl(idToken); Assert.assertEquals("Expected and actual values should be the same.", idToken, accessTokenCredentials.getTokenId()); } } @@ -84,7 +80,7 @@ public void newAccessTokenCredentialsTest() { public void newRefreshTokenCredentialsTest() { for (String idToken : idTokens) { for (String refreshToken : refreshTokens) { - RefreshTokenCredentials refreshTokenCredentials = credentialsFactoryImpl.newRefreshTokenCredentials(idToken, refreshToken); + RefreshTokenCredentials refreshTokenCredentials = new RefreshTokenCredentials(idToken, refreshToken); Assert.assertEquals("Expected and actual values should be the same.", idToken, refreshTokenCredentials.getTokenId()); Assert.assertEquals("Expected and actual values should be the same.", refreshToken, refreshTokenCredentials.getRefreshToken()); } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsTest.java index abb4dc254fe..d17688ae9fb 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/JwtCredentialsTest.java @@ -14,26 +14,24 @@ import org.eclipse.kapua.qa.markers.junit.JUnitTests; import org.eclipse.kapua.service.authentication.JwtCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.model.JwtCredentialsAnotherImpl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; - @Category(JUnitTests.class) public class JwtCredentialsTest { - JwtCredentialsImpl jwtCredentialsImpl; + JwtCredentials jwtCredentials; String[] accessTokens, idsToken, newAccessTokens, newIdsToken; @Before public void initialize() { - jwtCredentialsImpl = new JwtCredentialsImpl("accessToken", "idToken"); - idsToken = new String[]{null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&"}; - accessTokens = new String[]{null, "", " j_w=t110.,<> jwt", "(!!)432j&^w$#3t", "##<>/.JWT ", "__J!#W(-8T ", "jw&* 990t ", "jwt987)_=;''' .", "jwt JWT-123"}; - newAccessTokens = new String[]{null, "", "new_Jwt1122#$%", " JWT)(..,,new", "NEW_jwt ./??)_)*", "<> 1111 ", "jwttt&^$$##Z||'", "%%%KEY NEW-JWT11"}; - newIdsToken = new String[]{null, "", "NEW tokenID0000@!!,,,#", "!@#00tokenID new.", " new id TOK --EN-44<>", "pA_ss0###woE**9()", " tokenID new tokenID 12344*&^%"}; + jwtCredentials = new JwtCredentials("accessToken", "idToken"); + idsToken = new String[] { null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&" }; + accessTokens = new String[] { null, "", " j_w=t110.,<> jwt", "(!!)432j&^w$#3t", "##<>/.JWT ", "__J!#W(-8T ", "jw&* 990t ", "jwt987)_=;''' .", "jwt JWT-123" }; + newAccessTokens = new String[] { null, "", "new_Jwt1122#$%", " JWT)(..,,new", "NEW_jwt ./??)_)*", "<> 1111 ", "jwttt&^$$##Z||'", "%%%KEY NEW-JWT11" }; + newIdsToken = new String[] { null, "", "NEW tokenID0000@!!,,,#", "!@#00tokenID new.", " new id TOK --EN-44<>", "pA_ss0###woE**9()", " tokenID new tokenID 12344*&^%" }; } @Test(expected = NullPointerException.class) @@ -43,7 +41,7 @@ public void jwtCredentialsImplCloneConstructorNullTest() { @Test public void jwtCredentialsImplCloneConstructorImplTest() { - JwtCredentialsImpl first = new JwtCredentialsImpl("aJwt", "anIdToken"); + JwtCredentials first = new JwtCredentials("aJwt", "anIdToken"); JwtCredentialsImpl second = new JwtCredentialsImpl(first); @@ -54,7 +52,7 @@ public void jwtCredentialsImplCloneConstructorImplTest() { @Test public void jwtCredentialsImplCloneConstructorAnotherTest() { - JwtCredentials first = new JwtCredentialsAnotherImpl("aJwt", "anIdToken"); + JwtCredentials first = new JwtCredentials("aJwt", "anIdToken"); JwtCredentialsImpl second = new JwtCredentialsImpl(first); @@ -67,7 +65,7 @@ public void jwtCredentialsImplCloneConstructorAnotherTest() { public void jwtCredentialsImplTest() { for (String accessToken : accessTokens) { for (String idToken : idsToken) { - JwtCredentialsImpl jwtCredentialsImpl = new JwtCredentialsImpl(accessToken, idToken); + JwtCredentialsImpl jwtCredentialsImpl = new JwtCredentialsImpl(new JwtCredentials(accessToken, idToken)); Assert.assertEquals("Expected and actual values should be the same.", accessToken, jwtCredentialsImpl.getAccessToken()); Assert.assertEquals("Expected and actual values should be the same.", idToken, jwtCredentialsImpl.getIdToken()); Assert.assertEquals("Expected and actual values should be the same.", accessToken, jwtCredentialsImpl.getPrincipal()); @@ -79,18 +77,19 @@ public void jwtCredentialsImplTest() { @Test public void setAndGetJwtPrincipalAndCredentialTest() { for (String newAccessToken : newAccessTokens) { - jwtCredentialsImpl.setAccessToken(newAccessToken); - Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, jwtCredentialsImpl.getAccessToken()); - Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, jwtCredentialsImpl.getPrincipal()); - Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, jwtCredentialsImpl.getCredentials()); + jwtCredentials.setAccessToken(newAccessToken); + final JwtCredentialsImpl credentials = new JwtCredentialsImpl(jwtCredentials); + Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, credentials.getAccessToken()); + Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, credentials.getPrincipal()); + Assert.assertEquals("Expected and actual values should be the same.", newAccessToken, credentials.getCredentials()); } } @Test public void setAndGetIdTokenTest() { for (String newIdToken : newIdsToken) { - jwtCredentialsImpl.setIdToken(newIdToken); - Assert.assertEquals("Expected and actual values should be the same.", newIdToken, jwtCredentialsImpl.getIdToken()); + jwtCredentials.setIdToken(newIdToken); + Assert.assertEquals("Expected and actual values should be the same.", newIdToken, jwtCredentials.getIdToken()); } } } diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImplTest.java deleted file mode 100644 index 03f494db645..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsImplTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro; - -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class RefreshTokenCredentialsImplTest { - - String[] idsToken, refreshTokens, newIdsToken, newRefreshTokens; - RefreshTokenCredentialsImpl refreshTokenCredentialsImpl; - - @Before - public void initialize() { - idsToken = new String[]{null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&"}; - refreshTokens = new String[]{null, "", " refresh tokenREFRESH 747.,.,,,82(*&%<> ", " token((11@-", "REFresh)__.,TOKen65", "TOKENrefresh543$#%&t oken", "to-ken_++rE=fresh,", "refresh,,,,id3$^&"}; - newIdsToken = new String[]{null, "", "NEW tokenID0000@!!,,,#", "!@#00tokenID new.", " new id TOK --EN-44<>", "pA_ss0###woE**9()", " tokenID new tokenID 12344*&^%"}; - newRefreshTokens = new String[]{null, "", "new_refresh1122TOKEN#$%", " JWT)(..,,new", "NEW_token .refresh/??)_)*", "<> 1111 ", "jwttt&^$$##Z||'", "%%%KEY NEW-TOKEN1r-e5f&resh"}; - } - - @Test - public void refreshTokenCredentialsImplTest() { - for (String idToken : idsToken) { - for (String refreshToken : refreshTokens) { - refreshTokenCredentialsImpl = new RefreshTokenCredentialsImpl(idToken, refreshToken); - Assert.assertEquals("Expected and actual values should be the same.", idToken, refreshTokenCredentialsImpl.getTokenId()); - Assert.assertEquals("Expected and actual values should be the same.", refreshToken, refreshTokenCredentialsImpl.getRefreshToken()); - } - } - } - - @Test - public void setAndGetTokenIdTest() { - refreshTokenCredentialsImpl = new RefreshTokenCredentialsImpl("token id", "refresh token"); - for (String newIdToken : newIdsToken) { - refreshTokenCredentialsImpl.setTokenId(newIdToken); - Assert.assertEquals("Expected and actual values should be the same.", newIdToken, refreshTokenCredentialsImpl.getTokenId()); - } - } - - @Test - public void setAndGetRefreshTokenTest() { - refreshTokenCredentialsImpl = new RefreshTokenCredentialsImpl("token id", "refresh token"); - for (String newRefreshToken : newRefreshTokens) { - refreshTokenCredentialsImpl.setRefreshToken(newRefreshToken); - Assert.assertEquals("Expected and actual values should be the same.", newRefreshToken, refreshTokenCredentialsImpl.getRefreshToken()); - } - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsTest.java new file mode 100644 index 00000000000..7198413e091 --- /dev/null +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/RefreshTokenCredentialsTest.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.authentication.shiro; + +import org.eclipse.kapua.qa.markers.junit.JUnitTests; +import org.eclipse.kapua.service.authentication.RefreshTokenCredentials; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(JUnitTests.class) +public class RefreshTokenCredentialsTest { + + String[] idsToken, refreshTokens, newIdsToken, newRefreshTokens; + RefreshTokenCredentials refreshTokenCredentials; + + @Before + public void initialize() { + idsToken = new String[] { null, "", " ID tokenID 747.,.,,,82(*&%<> ", " token((11@-", "id)__.,TOKen65", "TOKENid543$#%&t oken", "to-ken_id++=,", "id,,,,id3$^&" }; + refreshTokens = new String[] { null, "", " refresh tokenREFRESH 747.,.,,,82(*&%<> ", " token((11@-", "REFresh)__.,TOKen65", "TOKENrefresh543$#%&t oken", "to-ken_++rE=fresh,", + "refresh,,,,id3$^&" }; + newIdsToken = new String[] { null, "", "NEW tokenID0000@!!,,,#", "!@#00tokenID new.", " new id TOK --EN-44<>", "pA_ss0###woE**9()", " tokenID new tokenID 12344*&^%" }; + newRefreshTokens = new String[] { null, "", "new_refresh1122TOKEN#$%", " JWT)(..,,new", "NEW_token .refresh/??)_)*", "<> 1111 ", "jwttt&^$$##Z||'", "%%%KEY NEW-TOKEN1r-e5f&resh" }; + } + + @Test + public void refreshTokenCredentialsTest() { + for (String idToken : idsToken) { + for (String refreshToken : refreshTokens) { + refreshTokenCredentials = new RefreshTokenCredentials(idToken, refreshToken); + Assert.assertEquals("Expected and actual values should be the same.", idToken, refreshTokenCredentials.getTokenId()); + Assert.assertEquals("Expected and actual values should be the same.", refreshToken, refreshTokenCredentials.getRefreshToken()); + } + } + } + + @Test + public void setAndGetTokenIdTest() { + refreshTokenCredentials = new RefreshTokenCredentials("token id", "refresh token"); + for (String newIdToken : newIdsToken) { + refreshTokenCredentials.setTokenId(newIdToken); + Assert.assertEquals("Expected and actual values should be the same.", newIdToken, refreshTokenCredentials.getTokenId()); + } + } + + @Test + public void setAndGetRefreshTokenTest() { + refreshTokenCredentials = new RefreshTokenCredentials("token id", "refresh token"); + for (String newRefreshToken : newRefreshTokens) { + refreshTokenCredentials.setRefreshToken(newRefreshToken); + Assert.assertEquals("Expected and actual values should be the same.", newRefreshToken, refreshTokenCredentials.getRefreshToken()); + } + } +} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImplTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImplTest.java deleted file mode 100644 index 3726bdf472d..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/UsernamePasswordCredentialsImplTest.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro; - -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.model.UsernamePasswordCredentialsAnotherImpl; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - - -@Category(JUnitTests.class) -public class UsernamePasswordCredentialsImplTest { - - String[] usernames, passwords, newUsernames, newPasswords, trustKeys, authenticationCodes; - UsernamePasswordCredentialsImpl usernamePasswordCredentialsImpl; - - @Before - public void initialize() { - usernames = new String[]{null, "", "user_name123!!", "user#999username", "USERNAME_9", "user,,,,name", "... us_er%%67na*(me"}; - passwords = new String[]{null, "", "pass-word0000@!!,,,#", "!@#00PaSSwOrD.", " password ---44<>", "pA_ss0###woE**9()", " pass0wo-rd 12344*&^%"}; - newUsernames = new String[]{null, "", "NEW---user_name123!!", "user#999username,.,@#NEW", "1111USERNAME_9", " new--^%4user,,,,name", "... us_er%%67na*(me NEW "}; - newPasswords = new String[]{null, "", "pass-word0000@!!,new password,,#", "!@#00PaSSwOrD._@#new", "new password ---44<>", " new#@$pA_ss0###woE**9()", " pass0wo-rd 12344*NEW&^%"}; - trustKeys = new String[]{null, "", "!!trust key-1", "#1(TRUST KEY.,/trust key)9--99", "!$$ 1-2 KEY//", "trust 99key(....)<00>"}; - authenticationCodes = new String[]{null, "", " authentication@#$%Code=t110.,<> code", "(!!)432j&^authenti)(&%cation-Code$#3t", "##<>/.CODE ", "__J!#W(-8T ", "authenticatioN&* 99code0t ", "jwt987)_=;''' .", "jwt CODE-123"}; - usernamePasswordCredentialsImpl = new UsernamePasswordCredentialsImpl("username", "password"); - } - - @Test(expected = NullPointerException.class) - public void usernamePasswordCredentialsImplCloneConstructorNullTest() { - new UsernamePasswordCredentialsImpl(null); - } - - @Test - public void usernamePasswordCredentialsImplCloneConstructorImplTest() { - UsernamePasswordCredentialsImpl first = new UsernamePasswordCredentialsImpl("aUsername", "aPassword"); - first.setTrustKey("aTrustKey"); - first.setAuthenticationCode("aAuthCode"); - - UsernamePasswordCredentialsImpl second = new UsernamePasswordCredentialsImpl(first); - - Assert.assertNotEquals("UsernamePasswordCredentialImpl", first, second); - Assert.assertEquals("UsernamePasswordCredential.username", first.getUsername(), second.getUsername()); - Assert.assertEquals("UsernamePasswordCredential.password", first.getPassword(), second.getPassword()); - Assert.assertEquals("UsernamePasswordCredential.trustKey", first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals("UsernamePasswordCredential.authenticationCode", first.getAuthenticationCode(), second.getAuthenticationCode()); - } - - @Test - public void usernamePasswordCredentialsImplCloneConstructorAnotherTest() { - UsernamePasswordCredentials first = new UsernamePasswordCredentialsAnotherImpl("aUsername", "aPassword"); - first.setTrustKey("aTrustKey"); - first.setAuthenticationCode("aAuthCode"); - - UsernamePasswordCredentialsImpl second = new UsernamePasswordCredentialsImpl(first); - - Assert.assertNotEquals("UsernamePasswordCredentialImpl", first, second); - Assert.assertEquals("UsernamePasswordCredential.username", first.getUsername(), second.getUsername()); - Assert.assertEquals("UsernamePasswordCredential.password", first.getPassword(), second.getPassword()); - Assert.assertEquals("UsernamePasswordCredential.trustKey", first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals("UsernamePasswordCredential.authenticationCode", first.getAuthenticationCode(), second.getAuthenticationCode()); - } - - @Test - public void usernamePasswordCredentialsImplParseNullTest() { - UsernamePasswordCredentialsImpl first = null; - - UsernamePasswordCredentialsImpl second = UsernamePasswordCredentialsImpl.parse(null); - - Assert.assertNull("Parsed UsernamePasswordCredentialsImpl", second); - Assert.assertEquals("UsernamePasswordCredentialImpl", first, second); - } - - @Test - public void usernamePasswordCredentialsImplParseImplTest() { - UsernamePasswordCredentialsImpl first = new UsernamePasswordCredentialsImpl("aUsername", "aPassword"); - first.setTrustKey("aTrustKey"); - first.setAuthenticationCode("aAuthCode"); - - UsernamePasswordCredentialsImpl second = UsernamePasswordCredentialsImpl.parse(first); - - Assert.assertEquals("UsernamePasswordCredentialImpl", first, second); - Assert.assertEquals("UsernamePasswordCredential.username", first.getUsername(), second.getUsername()); - Assert.assertEquals("UsernamePasswordCredential.password", first.getPassword(), second.getPassword()); - Assert.assertEquals("UsernamePasswordCredential.trustKey", first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals("UsernamePasswordCredential.authenticationCode", first.getAuthenticationCode(), second.getAuthenticationCode()); - } - - @Test - public void usernamePasswordCredentiaslImplParseAnotherTest() { - UsernamePasswordCredentials first = new UsernamePasswordCredentialsAnotherImpl("aUsername", "aPassword"); - first.setTrustKey("aTrustKey"); - first.setAuthenticationCode("aAuthCode"); - - UsernamePasswordCredentialsImpl second = UsernamePasswordCredentialsImpl.parse(first); - - Assert.assertNotEquals("UsernamePasswordCredentialImpl", first, second); - Assert.assertEquals("UsernamePasswordCredential.username", first.getUsername(), second.getUsername()); - Assert.assertEquals("UsernamePasswordCredential.password", first.getPassword(), second.getPassword()); - Assert.assertEquals("UsernamePasswordCredential.trustKey", first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals("UsernamePasswordCredential.authenticationCode", first.getAuthenticationCode(), second.getAuthenticationCode()); - } - - @Test - public void usernamePasswordCredentialsImplTest() { - for (String username : usernames) { - for (String password : passwords) { - UsernamePasswordCredentialsImpl usernamePasswordCredentialsImpl = new UsernamePasswordCredentialsImpl(username, password); - Assert.assertEquals("Expected and actual values should be the same.", username, usernamePasswordCredentialsImpl.getUsername()); - Assert.assertEquals("Expected and actual values should be the same.", username, usernamePasswordCredentialsImpl.getPrincipal()); - Assert.assertEquals("Expected and actual values should be the same.", password, usernamePasswordCredentialsImpl.getPassword()); - Assert.assertEquals("Expected and actual values should be the same.", password, usernamePasswordCredentialsImpl.getCredentials()); - Assert.assertNull("Null expected.", usernamePasswordCredentialsImpl.getAuthenticationCode()); - Assert.assertNull("Null expected.", usernamePasswordCredentialsImpl.getTrustKey()); - } - } - } - - @Test - public void setAndGetUsernameAndPrincipalTest() { - for (String newUsername : newUsernames) { - usernamePasswordCredentialsImpl.setUsername(newUsername); - Assert.assertEquals("Expected and actual values should be the same.", newUsername, usernamePasswordCredentialsImpl.getUsername()); - Assert.assertEquals("Expected and actual values should be the same.", newUsername, usernamePasswordCredentialsImpl.getPrincipal()); - } - } - - @Test - public void setAndGetPasswordAndCredentialsTest() { - for (String newPassword : newPasswords) { - usernamePasswordCredentialsImpl.setPassword(newPassword); - Assert.assertEquals("Expected and actual values should be the same.", newPassword, usernamePasswordCredentialsImpl.getPassword()); - Assert.assertEquals("Expected and actual values should be the same.", newPassword, usernamePasswordCredentialsImpl.getCredentials()); - } - } - - @Test - public void setAndGetAuthenticationCodeTest() { - for (String authenticationCode : authenticationCodes) { - usernamePasswordCredentialsImpl.setAuthenticationCode(authenticationCode); - Assert.assertEquals("Expected and actual values should be the same.", authenticationCode, usernamePasswordCredentialsImpl.getAuthenticationCode()); - } - } - - @Test - public void setAndGetTrustKeyTest() { - for (String trustKey : trustKeys) { - usernamePasswordCredentialsImpl.setTrustKey(trustKey); - Assert.assertEquals("Expected and actual values should be the same.", trustKey, usernamePasswordCredentialsImpl.getTrustKey()); - } - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverterTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverterTest.java deleted file mode 100644 index fa8f896a30f..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/AccessTokenCredentialsConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.realm; - -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; -import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationException; -import org.eclipse.kapua.service.authentication.shiro.AccessTokenCredentialsImpl; -import org.eclipse.kapua.service.authentication.shiro.realm.model.AccessTokenCredentialsAnotherImpl; -import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentials; -import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentialsImpl; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Category(JUnitTests.class) -public class AccessTokenCredentialsConverterTest { - - AccessTokenCredentialsConverter instance; - - @Before - public void setUp() { - instance = new AccessTokenCredentialsConverter(); - } - - @Test - public void accessTokenCredentialsImplCanProcessNullTest() { - Assert.assertFalse(instance.canProcess(null)); - } - - @Test - public void accessTokenCredentialsImplCanProcessImplTest() throws KapuaAuthenticationException { - AccessTokenCredentials accessTokenCredentialsImpl = new AccessTokenCredentialsImpl("anAccessToken"); - AccessTokenCredentials accessTokenCredentialsAnother = new AccessTokenCredentialsAnotherImpl("anAccessToken"); - NotProcessableCredentials notProcessableCredentials = new NotProcessableCredentialsImpl(); - - Assert.assertTrue(instance.canProcess(accessTokenCredentialsImpl)); - Assert.assertTrue(instance.canProcess(accessTokenCredentialsAnother)); - Assert.assertFalse(instance.canProcess(notProcessableCredentials)); - } - - @Test - public void accessTokenCredentialsImplMapToShiroImplTest() throws KapuaAuthenticationException { - AccessTokenCredentialsImpl first = new AccessTokenCredentialsImpl("anAccessToken"); - - AccessTokenCredentialsImpl second = (AccessTokenCredentialsImpl) instance.convertToShiro(first); - - Assert.assertEquals(first, second); - Assert.assertEquals(first.getTokenId(), second.getTokenId()); - } - - @Test - public void accessTokenCredentialsImplMapToShiroAnotherTest() throws KapuaAuthenticationException { - AccessTokenCredentials first = new AccessTokenCredentialsAnotherImpl("anAccessToken"); - - AccessTokenCredentialsImpl second = (AccessTokenCredentialsImpl) instance.convertToShiro(first); - - Assert.assertNotNull(second); - Assert.assertNotEquals(first, second); - Assert.assertEquals(first.getTokenId(), second.getTokenId()); - } - - @Test(expected = NullPointerException.class) - public void accessTokenCredentialsImplMapToShiroNullTest() throws KapuaAuthenticationException { - instance.convertToShiro(null); - } - - @Test(expected = KapuaAuthenticationException.class) - public void accessTokenCredentialsImplMapToShiroEmptyTest() throws KapuaAuthenticationException { - AccessTokenCredentialsImpl first = new AccessTokenCredentialsImpl((String) null); - - Assert.assertNotNull(first); - - instance.convertToShiro(first); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/ApiKeyCredentialsConverterTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/ApiKeyCredentialsConverterTest.java index 34f6b79ba55..84eaa63a4ef 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/ApiKeyCredentialsConverterTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/ApiKeyCredentialsConverterTest.java @@ -16,7 +16,6 @@ import org.eclipse.kapua.service.authentication.ApiKeyCredentials; import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationException; import org.eclipse.kapua.service.authentication.shiro.ApiKeyCredentialsImpl; -import org.eclipse.kapua.service.authentication.shiro.realm.model.ApiKeyCredentialsAnotherImpl; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentials; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentialsImpl; import org.junit.Assert; @@ -41,32 +40,20 @@ public void apoKeyCredentialsImplCanProcessNullTest() { @Test public void apoKeyCredentialsImplCanProcessImplTest() throws KapuaAuthenticationException { - ApiKeyCredentials apoKeyCredentialsImpl = new ApiKeyCredentialsImpl("anApiKey"); - ApiKeyCredentials apoKeyCredentialsAnother = new ApiKeyCredentialsAnotherImpl("anApiKey"); + ApiKeyCredentials apoKeyCredentials = new ApiKeyCredentials("anApiKey"); NotProcessableCredentials notProcessableCredentials = new NotProcessableCredentialsImpl(); - Assert.assertTrue(instance.canProcess(apoKeyCredentialsImpl)); - Assert.assertTrue(instance.canProcess(apoKeyCredentialsAnother)); + Assert.assertTrue(instance.canProcess(apoKeyCredentials)); Assert.assertFalse(instance.canProcess(notProcessableCredentials)); } @Test public void apiKeyCredentialsImplMapToShiroImplTest() throws KapuaAuthenticationException { - ApiKeyCredentials first = new ApiKeyCredentialsImpl("anApiKey"); + ApiKeyCredentials first = new ApiKeyCredentials("anApiKey"); ApiKeyCredentialsImpl second = (ApiKeyCredentialsImpl) instance.convertToShiro(first); - Assert.assertEquals(first, second); - Assert.assertEquals(first.getApiKey(), second.getApiKey()); - } - - @Test - public void apiKeyCredentialsImplMapToShiroAnotherTest() throws KapuaAuthenticationException { - ApiKeyCredentials first = new ApiKeyCredentialsAnotherImpl("anApiKey"); - - ApiKeyCredentialsImpl second = (ApiKeyCredentialsImpl) instance.convertToShiro(first); - - Assert.assertNotNull(second); + Assert.assertNotEquals(first, second); Assert.assertNotEquals(first, second); Assert.assertEquals(first.getApiKey(), second.getApiKey()); } @@ -78,7 +65,7 @@ public void apiKeyCredentialsImplMapToShiroNullTest() throws KapuaAuthentication @Test(expected = KapuaAuthenticationException.class) public void apiKeyCredentialsImplMapToShiroEmptyTest() throws KapuaAuthenticationException { - ApiKeyCredentialsImpl first = new ApiKeyCredentialsImpl((String) null); + ApiKeyCredentials first = new ApiKeyCredentials((String) null); Assert.assertNotNull(first); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsConverterTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsConverterTest.java index 78a970280d3..028c684f587 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsConverterTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/JwtCredentialsConverterTest.java @@ -16,7 +16,6 @@ import org.eclipse.kapua.service.authentication.JwtCredentials; import org.eclipse.kapua.service.authentication.exception.KapuaAuthenticationException; import org.eclipse.kapua.service.authentication.shiro.JwtCredentialsImpl; -import org.eclipse.kapua.service.authentication.shiro.realm.model.JwtCredentialsAnotherImpl; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentials; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentialsImpl; import org.junit.Assert; @@ -41,34 +40,21 @@ public void jwtCredentialsImplCanProcessNullTest() { @Test public void jwtCredentialsImplCanProcessImplTest() throws KapuaAuthenticationException { - JwtCredentials jwtCredentialsImpl = new JwtCredentialsImpl("aJwt", "anIdToken"); - JwtCredentials jwtCredentialsAnother = new JwtCredentialsAnotherImpl("aJwt", "anIdToken"); + JwtCredentials jwtCredentialsImpl = new JwtCredentials("aJwt", "anIdToken"); NotProcessableCredentials notProcessableCredentials = new NotProcessableCredentialsImpl(); Assert.assertTrue(instance.canProcess(jwtCredentialsImpl)); - Assert.assertTrue(instance.canProcess(jwtCredentialsAnother)); Assert.assertFalse(instance.canProcess(notProcessableCredentials)); } @Test public void jwtCredentialsImplMapToShiroImplTest() throws KapuaAuthenticationException { - JwtCredentialsImpl first = new JwtCredentialsImpl("aJwt", "anIdToken"); - - JwtCredentialsImpl second = (JwtCredentialsImpl) instance.convertToShiro(first); - - Assert.assertNotNull(second); - Assert.assertEquals(first, second); - Assert.assertEquals(first.getAccessToken(), second.getAccessToken()); - Assert.assertEquals(first.getIdToken(), second.getIdToken()); - } - - @Test - public void jwtCredentialsImplMapToShiroAnotherTest() throws KapuaAuthenticationException { - JwtCredentials first = new JwtCredentialsAnotherImpl("aJwt", "anIdToken"); + JwtCredentials first = new JwtCredentials("aJwt", "anIdToken"); JwtCredentialsImpl second = (JwtCredentialsImpl) instance.convertToShiro(first); Assert.assertNotNull(second); + Assert.assertNotEquals(first, second); Assert.assertEquals(first.getAccessToken(), second.getAccessToken()); Assert.assertEquals(first.getIdToken(), second.getIdToken()); } @@ -80,7 +66,7 @@ public void jwtCredentialsImplMapToShiroNullTest() throws KapuaAuthenticationExc @Test(expected = KapuaAuthenticationException.class) public void jwtCredentialsImplMapToShiroEmptyTest() throws KapuaAuthenticationException { - JwtCredentialsImpl first = new JwtCredentialsImpl(null, null); + JwtCredentials first = new JwtCredentials(null, null); Assert.assertNotNull(first); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsConverterTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsConverterTest.java index 06334966f3a..12d76103397 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsConverterTest.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/UserPassCredentialsConverterTest.java @@ -18,7 +18,6 @@ import org.eclipse.kapua.service.authentication.shiro.UsernamePasswordCredentialsImpl; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentials; import org.eclipse.kapua.service.authentication.shiro.realm.model.NotProcessableCredentialsImpl; -import org.eclipse.kapua.service.authentication.shiro.realm.model.UsernamePasswordCredentialsAnotherImpl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -41,18 +40,16 @@ public void usernamePasswordCredentialsImplCanProcessNullTest() { @Test public void usernamePasswordCredentialsImplCanProcessImplTest() throws KapuaAuthenticationException { - UsernamePasswordCredentials usernamePasswordCredentialsImpl = new UsernamePasswordCredentialsImpl("aUsernamePassword", "anIdToken"); - UsernamePasswordCredentials usernamePasswordCredentialsAnother = new UsernamePasswordCredentialsAnotherImpl("aUsernamePassword", "anIdToken"); + UsernamePasswordCredentials usernamePasswordCredentialsImpl = new UsernamePasswordCredentials("aUsernamePassword", "anIdToken"); NotProcessableCredentials notProcessableCredentials = new NotProcessableCredentialsImpl(); Assert.assertTrue(instance.canProcess(usernamePasswordCredentialsImpl)); - Assert.assertTrue(instance.canProcess(usernamePasswordCredentialsAnother)); Assert.assertFalse(instance.canProcess(notProcessableCredentials)); } @Test public void usernamePasswordCredentialsImplMapToShiroImplTest() throws KapuaAuthenticationException { - UsernamePasswordCredentialsImpl first = new UsernamePasswordCredentialsImpl("aUsername", "aPassword"); + UsernamePasswordCredentials first = new UsernamePasswordCredentials("aUsername", "aPassword"); first.setAuthenticationCode("123456"); first.setTrustKey("aTrustKey"); first.setTrustMe(true); @@ -60,17 +57,15 @@ public void usernamePasswordCredentialsImplMapToShiroImplTest() throws KapuaAuth UsernamePasswordCredentialsImpl second = (UsernamePasswordCredentialsImpl) instance.convertToShiro(first); Assert.assertNotNull(second); - Assert.assertEquals(first, second); + Assert.assertNotEquals(first, second); Assert.assertEquals(first.getUsername(), second.getUsername()); Assert.assertEquals(first.getPassword(), second.getPassword()); - Assert.assertEquals(first.getAuthenticationCode(), second.getAuthenticationCode()); - Assert.assertEquals(first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals(first.getTrustMe(), second.getTrustMe()); + Assert.assertEquals(first.getAuthenticationCode(), first.getAuthenticationCode()); } @Test public void usernamePasswordCredentialsImplMapToShiroAnotherTest() throws KapuaAuthenticationException { - UsernamePasswordCredentials first = new UsernamePasswordCredentialsAnotherImpl("aAccessToken", "anIdToken"); + UsernamePasswordCredentials first = new UsernamePasswordCredentials("aAccessToken", "anIdToken"); first.setAuthenticationCode("123456"); first.setTrustKey("aTrustKey"); first.setTrustMe(true); @@ -81,9 +76,6 @@ public void usernamePasswordCredentialsImplMapToShiroAnotherTest() throws KapuaA Assert.assertNotEquals(first, second); Assert.assertEquals(first.getUsername(), second.getUsername()); Assert.assertEquals(first.getPassword(), second.getPassword()); - Assert.assertEquals(first.getAuthenticationCode(), second.getAuthenticationCode()); - Assert.assertEquals(first.getTrustKey(), second.getTrustKey()); - Assert.assertEquals(first.getTrustMe(), second.getTrustMe()); } @Test(expected = NullPointerException.class) @@ -93,7 +85,7 @@ public void usernamePasswordCredentialsImplMapToShiroNullTest() throws KapuaAuth @Test(expected = KapuaAuthenticationException.class) public void usernamePasswordCredentialsImplMapToShiroEmptyTest() throws KapuaAuthenticationException { - UsernamePasswordCredentialsImpl first = new UsernamePasswordCredentialsImpl(null, null); + UsernamePasswordCredentials first = new UsernamePasswordCredentials(null, null); Assert.assertNotNull(first); diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/AccessTokenCredentialsAnotherImpl.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/AccessTokenCredentialsAnotherImpl.java deleted file mode 100644 index f6e86d102c6..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/AccessTokenCredentialsAnotherImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.realm.model; - -import org.eclipse.kapua.service.authentication.AccessTokenCredentials; - -public class AccessTokenCredentialsAnotherImpl implements AccessTokenCredentials { - private String tokenId; - - public AccessTokenCredentialsAnotherImpl(String tokenId) { - setTokenId(tokenId); - } - - @Override - public String getTokenId() { - return tokenId; - } - - @Override - public void setTokenId(String tokenId) { - this.tokenId = tokenId; - } -} diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/ApiKeyCredentialsAnotherImpl.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/ApiKeyCredentialsAnotherImpl.java deleted file mode 100644 index b8a1eb587c5..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/ApiKeyCredentialsAnotherImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.realm.model; - -import org.eclipse.kapua.service.authentication.ApiKeyCredentials; - -public class ApiKeyCredentialsAnotherImpl implements ApiKeyCredentials { - private String apiKey; - - public ApiKeyCredentialsAnotherImpl(String apiKey) { - setApiKey(apiKey); - } - - @Override - public String getApiKey() { - return apiKey; - } - - @Override - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } -} diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/JwtCredentialsAnotherImpl.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/JwtCredentialsAnotherImpl.java deleted file mode 100644 index 6590e133940..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/JwtCredentialsAnotherImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.realm.model; - -import org.eclipse.kapua.service.authentication.JwtCredentials; - -public class JwtCredentialsAnotherImpl implements JwtCredentials { - private String accessToken; - private String idToken; - - public JwtCredentialsAnotherImpl(String accessToken, String idToken) { - setAccessToken(accessToken); - setIdToken(idToken); - } - - @Override - public String getAccessToken() { - return accessToken; - } - - @Override - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - @Override - public String getIdToken() { - return idToken; - } - - @Override - public void setIdToken(String idToken) { - this.idToken = idToken; - } -} diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/UsernamePasswordCredentialsAnotherImpl.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/UsernamePasswordCredentialsAnotherImpl.java deleted file mode 100644 index edccceb3e4f..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/realm/model/UsernamePasswordCredentialsAnotherImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.realm.model; - -import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; - -public class UsernamePasswordCredentialsAnotherImpl implements UsernamePasswordCredentials { - - private String username; - private String password; - private String authenticationCode; - private String trustKey; - private boolean trustMe; - - public UsernamePasswordCredentialsAnotherImpl(String username, String password) { - setUsername(username); - setPassword(password); - } - - @Override - public String getUsername() { - return username; - } - - @Override - public void setUsername(String username) { - this.username = username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public void setPassword(String password) { - this.password = password; - } - - @Override - public String getAuthenticationCode() { - return authenticationCode; - } - - @Override - public void setAuthenticationCode(String authenticationCode) { - this.authenticationCode = authenticationCode; - } - - @Override - public String getTrustKey() { - return trustKey; - } - - @Override - public void setTrustKey(String trustKey) { - this.trustKey = trustKey; - } - - @Override - public boolean getTrustMe() { - return trustMe; - } - - @Override - public void setTrustMe(boolean trustMe) { - this.trustMe = trustMe; - } -} diff --git a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagModule.java b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagModule.java index 55abc51bb9b..73de0d6d158 100644 --- a/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagModule.java +++ b/service/tag/internal/src/main/java/org/eclipse/kapua/service/tag/internal/TagModule.java @@ -72,7 +72,6 @@ public Domain tagDomain() { @Singleton @Named("TagServiceConfigurationManager") ServiceConfigurationManager tagServiceConfigurationManager( - TagFactory factory, RootUserTester rootUserTester, AccountRelativeFinder accountRelativeFinder, TagRepository tagRepository, @@ -89,7 +88,6 @@ ServiceConfigurationManager tagServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - factory, tagRepository ), xmlUtil)); diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java index dff254c3bf4..54f1c35f146 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java @@ -33,7 +33,6 @@ import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory; import org.eclipse.kapua.commons.jpa.NamedCacheFactory; import org.eclipse.kapua.commons.model.domains.Domains; -import org.eclipse.kapua.commons.service.event.store.api.EventStoreFactory; import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository; import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl; import org.eclipse.kapua.commons.util.xml.XmlUtil; @@ -98,7 +97,6 @@ public ServiceModule userServiceModule(UserService userService, AuthorizationService authorizationService, PermissionFactory permissionFactory, KapuaJpaTxManagerFactory txManagerFactory, - EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaUserSetting kapuaUserSetting, @@ -112,7 +110,6 @@ public ServiceModule userServiceModule(UserService userService, authorizationService, permissionFactory, txManagerFactory.create("kapua-user"), - eventStoreFactory, eventStoreRecordRepository ), txManagerFactory.create("kapua-user"), @@ -125,7 +122,6 @@ public ServiceModule userServiceModule(UserService userService, @Singleton @Named("UserServiceConfigurationManager") ServiceConfigurationManager userServiceConfigurationManager( - UserFactory userFactory, RootUserTester rootUserTester, AccountRelativeFinder accountRelativeFinder, UserRepository userRepository, @@ -142,7 +138,6 @@ ServiceConfigurationManager userServiceConfigurationManager( rootUserTester, accountRelativeFinder, new UsedEntitiesCounterImpl( - userFactory, userRepository ), xmlUtil)); diff --git a/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java b/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java index 8642d2869e8..91d67259946 100644 --- a/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java +++ b/service/user/test-steps/src/main/java/org/eclipse/kapua/service/user/steps/UserServiceSteps.java @@ -46,12 +46,11 @@ import org.eclipse.kapua.qa.common.cucumber.CucUser; import org.eclipse.kapua.service.account.Account; import org.eclipse.kapua.service.authentication.AuthenticationService; -import org.eclipse.kapua.service.authentication.CredentialsFactory; import org.eclipse.kapua.service.authentication.LoginCredentials; +import org.eclipse.kapua.service.authentication.UsernamePasswordCredentials; import org.eclipse.kapua.service.authentication.credential.Credential; import org.eclipse.kapua.service.authentication.credential.CredentialAttributes; import org.eclipse.kapua.service.authentication.credential.CredentialCreator; -import org.eclipse.kapua.service.authentication.credential.CredentialFactory; import org.eclipse.kapua.service.authentication.credential.CredentialListResult; import org.eclipse.kapua.service.authentication.credential.CredentialService; import org.eclipse.kapua.service.authentication.credential.CredentialStatus; @@ -61,7 +60,6 @@ import org.eclipse.kapua.service.authentication.credential.mfa.MfaOptionService; import org.eclipse.kapua.service.authentication.credential.mfa.shiro.MfaOptionFactoryImpl; import org.eclipse.kapua.service.authorization.access.AccessInfoCreator; -import org.eclipse.kapua.service.authorization.access.AccessInfoFactory; import org.eclipse.kapua.service.authorization.access.AccessInfoService; import org.eclipse.kapua.service.authorization.access.AccessPermission; import org.eclipse.kapua.service.authorization.access.AccessPermissionAttributes; @@ -121,11 +119,8 @@ public class UserServiceSteps extends TestBase { */ private AccessInfoService accessInfoService; private AuthenticationService authenticationService; - private AccessInfoFactory accessInfoFactory; private PermissionFactory permissionFactory; private CredentialService credentialService; - private CredentialFactory credentialFactory; - private CredentialsFactory credentialsFactory; private AccessPermissionService accessPermissionService; @Inject @@ -145,10 +140,7 @@ public void setServices() { authenticationService = locator.getService(AuthenticationService.class); credentialService = locator.getService(CredentialService.class); accessInfoService = locator.getService(AccessInfoService.class); - accessInfoFactory = locator.getFactory(AccessInfoFactory.class); permissionFactory = locator.getFactory(PermissionFactory.class); - credentialFactory = locator.getFactory(CredentialFactory.class); - credentialsFactory = locator.getFactory(CredentialsFactory.class); accessPermissionService = locator.getService(AccessPermissionService.class); } @@ -576,7 +568,7 @@ public void givenGenericUser(List userList) throws Exception { @When("I login as user with name {string} and password {string}") public void loginUser(String userName, String password) throws Exception { - LoginCredentials credentials = credentialsFactory.newUsernamePasswordCredentials(userName, password); + LoginCredentials credentials = new UsernamePasswordCredentials(userName, password); authenticationService.logout(); primeException(); try { @@ -589,7 +581,7 @@ public void loginUser(String userName, String password) throws Exception { @When("I try to login as user with name {string} with wrong password {int} times") public void loginUserNTimes(String userName, int n) throws Exception { String password = "wrongPassword"; - LoginCredentials credentials = credentialsFactory.newUsernamePasswordCredentials(userName, password); + LoginCredentials credentials = new UsernamePasswordCredentials(userName, password); authenticationService.logout(); for (int i = 0; i < n; i++) { primeException(); diff --git a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java index c16e75879a1..cf43eb91ea3 100644 --- a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java +++ b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java @@ -122,7 +122,6 @@ protected void configure() { Mockito.mock(RootUserTester.class), accountRelativeFinder, new UsedEntitiesCounterImpl( - userFactory, userRepository), new XmlUtil(new TestJAXBContextProvider()) ); diff --git a/transport/mqtt/src/main/java/org/eclipse/kapua/transport/mqtt/MqttFacade.java b/transport/mqtt/src/main/java/org/eclipse/kapua/transport/mqtt/MqttFacade.java index a0c8780d408..595bd88a37c 100644 --- a/transport/mqtt/src/main/java/org/eclipse/kapua/transport/mqtt/MqttFacade.java +++ b/transport/mqtt/src/main/java/org/eclipse/kapua/transport/mqtt/MqttFacade.java @@ -12,6 +12,11 @@ *******************************************************************************/ package org.eclipse.kapua.transport.mqtt; +import java.util.ArrayList; +import java.util.List; + +import javax.validation.constraints.NotNull; + import org.checkerframework.checker.nullness.qual.Nullable; import org.eclipse.kapua.transport.TransportFacade; import org.eclipse.kapua.transport.exception.TransportClientGetException; @@ -27,10 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; - /** * Implementation of {@link TransportFacade} API for MQTT transport facade. * @@ -55,7 +56,8 @@ public class MqttFacade implements TransportFacade * - * @param mqttMessage The request to send. - * @param responses The container in which load responses received from the device - * @param timeout The timeout of waiting the response from the device. - * If {@code null} request will be fired without waiting for the response. - * If mqttMessage has no response message set, timeout will be ignore even if set. - * @throws TransportSendException if sending the request produces any error. + * @param mqttMessage + * The request to send. + * @param responses + * The container in which load responses received from the device + * @param timeout + * The timeout of waiting the response from the device. If {@code null} request will be fired without waiting for the response. If mqttMessage has no response message set, timeout will be + * ignore even if set. + * @throws TransportSendException + * if sending the request produces any error. * @see MqttMessage#getResponseTopic() * @since 1.0.0 */ @@ -162,8 +167,10 @@ public void close() { /** * Publish the given {@link MqttMessage} using the {@link MqttClient}. * - * @param mqttMessage The {@link MqttMessage} to publish. - * @throws TransportSendException if error occurs while publishing the given {@link MqttMessage} + * @param mqttMessage + * The {@link MqttMessage} to publish. + * @throws TransportSendException + * if error occurs while publishing the given {@link MqttMessage} * @since 1.1.0 */ private void publishMessage(@NotNull MqttMessage mqttMessage) throws TransportSendException { @@ -177,11 +184,15 @@ private void publishMessage(@NotNull MqttMessage mqttMessage) throws TransportSe /** * Subscribe to response topic and adds the response messages to the given {@code responses} container. * - * @param responseTopic The {@link MqttTopic} to subscribe to receive the response. - * @param responses The container of the received responses + * @param responseTopic + * The {@link MqttTopic} to subscribe to receive the response. + * @param responses + * The container of the received responses * @return The {@link MqttResponseCallback} which handles the received responses. - * @throws MqttClientCallbackSetException if {@link MqttClient#setCallback(MqttResponseCallback)} fails. - * @throws MqttClientSubscribeException if the {@link MqttClient#subscribe(MqttTopic)} fails. + * @throws MqttClientCallbackSetException + * if {@link MqttClient#setCallback(MqttResponseCallback)} fails. + * @throws MqttClientSubscribeException + * if the {@link MqttClient#subscribe(MqttTopic)} fails. * @since 1.1.0 */ private MqttResponseCallback subscribeToResponse(MqttTopic responseTopic, List responses) throws MqttClientCallbackSetException, MqttClientSubscribeException { @@ -195,8 +206,10 @@ private MqttResponseCallback subscribeToResponse(MqttTopic responseTopic, List