/** * Creates a new Credential based on the information provided in CredentialCreator * parameter. * * @param scopeId * The {@link ScopeId} in which to create the {@link Credential} * @param credentialCreator * Provides the information for the new Credential to be created. * @return The newly created Credential object. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialCreate", value = "Create a Credential", notes = "Creates a new Credential based on the information provided in CredentialCreator parameter.", response = Credential.class) @POST @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Credential create( @ApiParam(value = "The ScopeId in which to create the Credential", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "Provides the information for the new Credential to be created", required = true) CredentialCreator credentialCreator) throws Exception { credentialCreator.setScopeId(scopeId); return credentialService.create(credentialCreator); }
/** * Updates the Credential based on the information provided in the Credential parameter. * * @param credential * The modified Credential whose attributed need to be updated. * @return The updated credential. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialUpdate", value = "Update an Credential", notes = "Updates a new Credential based on the information provided in the Credential parameter.", response = Credential.class) @PUT @Path("{credentialId}") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Credential update( @ApiParam(value = "The ScopeId of the requested Credential.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The id of the requested Credential", required = true) @PathParam("credentialId") EntityId credentialId, @ApiParam(value = "The modified Credential whose attributed need to be updated", required = true) Credential credential) throws Exception { credential.setScopeId(scopeId); credential.setId(credentialId); return credentialService.update(credential); }
/** * Counts the results with the given {@link CredentialQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query * The {@link CredentialQuery} to use to filter results. * @return The count of all the result matching the given {@link CredentialQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialCount", value = "Counts the Credentials", notes = "Counts the Credentials with the given CredentialQuery parameter returning the number of matching Credentials", response = CountResult.class) @POST @Path("_count") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CountResult count( @ApiParam(value = "The ScopeId in which to count results", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The CredentialQuery to use to filter count results", required = true) CredentialQuery query) throws Exception { query.setScopeId(scopeId); return new CountResult(credentialService.count(query)); }
credential = KapuaSecurityUtils.doPrivileged(() -> credentialService.findByApiKey(tokenApiKey)); } catch (AuthenticationException ae) { throw ae; credentialServiceConfig = KapuaSecurityUtils.doPrivileged(() -> credentialService.getConfigValues(account.getId())); boolean lockoutPolicyEnabled = (boolean) credentialServiceConfig.get("lockoutPolicy.enabled"); if (lockoutPolicyEnabled) {
try { credential = KapuaSecurityUtils.doPrivileged(() -> { CredentialListResult credentialList = credentialService.findByUserId(user.getScopeId(), user.getId()); credentialServiceConfig = KapuaSecurityUtils.doPrivileged(() -> credentialService.getConfigValues(account.getId())); boolean lockoutPolicyEnabled = (boolean) credentialServiceConfig.get("lockoutPolicy.enabled"); if (lockoutPolicyEnabled) {
/** * Deletes the Credential specified by the "credentialId" path parameter. * * @param credentialId * The id of the Credential to be deleted. * @return HTTP 200 if operation has completed successfully. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialDelete", value = "Delete a Credential", notes = "Deletes the Credential specified by the \"credentialId\" path parameter.") @DELETE @Path("{credentialId}") public Response deleteCredential( @ApiParam(value = "The ScopeId of the Credential to delete.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The id of the Credential to be deleted", required = true) @PathParam("credentialId") EntityId credentialId) throws Exception { credentialService.delete(scopeId, credentialId); return returnOk(); }
/** * Queries the results with the given {@link CredentialQuery} parameter. * * @param scopeId * The {@link ScopeId} in which to search results. * @param query * The {@link CredentialQuery} to use to filter results. * @return The {@link CredentialListResult} of all the result matching the given {@link CredentialQuery} parameter. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialQuery", value = "Queries the Credentials", notes = "Queries the Credentials with the given CredentialQuery parameter returning all matching Credentials", response = CredentialListResult.class) @POST @Path("_query") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public CredentialListResult query( @ApiParam(value = "The ScopeId in which to search results.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The CredentialQuery to use to filter results.", required = true) CredentialQuery query) throws Exception { query.setScopeId(scopeId); return credentialService.query(query); }
/** * Returns the Credential specified by the "credentialId" path parameter. * * @param scopeId * The {@link ScopeId} of the requested {@link Credential}. * @param credentialId * The id of the requested Credential. * @return The requested Credential object. * @throws Exception * Whenever something bad happens. See specific {@link KapuaService} exceptions. * @since 1.0.0 */ @ApiOperation(nickname = "credentialFind", value = "Get a Credential", notes = "Returns the Credential specified by the \"credentialId\" path parameter.", response = Credential.class) @GET @Path("{credentialId}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Credential find( @ApiParam(value = "The ScopeId of the requested Credential.", required = true, defaultValue = DEFAULT_SCOPE_ID) @PathParam("scopeId") ScopeId scopeId, @ApiParam(value = "The id of the requested Credential", required = true) @PathParam("credentialId") EntityId credentialId) throws Exception { Credential credential = credentialService.find(scopeId, credentialId); if (credential == null) { throw new KapuaEntityNotFoundException(Credential.TYPE, credentialId); } return credential; }
credential = KapuaSecurityUtils.doPrivileged(() -> credentialService.findByApiKey(tokenApiKey)); } catch (AuthenticationException ae) { throw ae; credentialServiceConfig = KapuaSecurityUtils.doPrivileged(() -> credentialService.getConfigValues(account.getId())); boolean lockoutPolicyEnabled = (boolean) credentialServiceConfig.get("lockoutPolicy.enabled"); if (lockoutPolicyEnabled) {
try { credential = KapuaSecurityUtils.doPrivileged(() -> { CredentialListResult credentialList = credentialService.findByUserId(user.getScopeId(), user.getId()); credentialServiceConfig = KapuaSecurityUtils.doPrivileged(() -> credentialService.getConfigValues(account.getId())); boolean lockoutPolicyEnabled = (boolean) credentialServiceConfig.get("lockoutPolicy.enabled"); if (lockoutPolicyEnabled) {
public void attachUserCredentials(Account account, User user) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { CredentialCreator credentialCreator; credentialCreator = new CredentialFactoryImpl().newCreator(account.getId(), user.getId(), CredentialType.PASSWORD, "KeepCalm123.", CredentialStatus.ENABLED, null); try { credentialService.create(credentialCreator); } catch (KapuaException ke) { // skip } return null; }); }
public void attachUserCredentials(Account account, User user, String password) throws KapuaException { KapuaSecurityUtils.doPrivileged(() -> { CredentialCreator credentialCreator; credentialCreator = new CredentialFactoryImpl().newCreator(account.getId(), user.getId(), CredentialType.PASSWORD, password, CredentialStatus.ENABLED, null); try { credentialService.create(credentialCreator); } catch (KapuaException ke) { // skip } return null; }); }
/** * Create credentials for specific user, set users password. * It finds user by name and sets its password. * * @param testCredentials username and open password * @return created credential */ private Credential createCredentials(TestCredentials testCredentials) throws Exception { List<Credential> credentialList = new ArrayList<>(); KapuaSecurityUtils.doPrivileged(() -> { primeException(); try { User user = userService.findByName(testCredentials.getName()); Credential credential = credentialService.create(credentialCreatorCreator(user.getScopeId(), user.getId(), testCredentials.getPassword(), testCredentials.getStatus(), testCredentials.getExpirationDate())); credentialList.add(credential); } catch (KapuaException ke) { verifyException(ke); } return null; }); return credentialList.size() == 1 ? credentialList.get(0) : null; }
private User createBrokerUser(String baseName, Account account) throws KapuaException { // define UserCreator userCreator = userFactory.newCreator(account.getId(), baseName + "-broker"); userCreator.setUserType(UserType.INTERNAL); // FIXME: need to find out why this isn't DEVICE but INTERNAL userCreator.setDisplayName("Gateway User"); // create User user = userService.create(userCreator); // assign permissions AccessInfoCreator accessInfoCreator = accessInfoFactory.newCreator(user.getScopeId()); accessInfoCreator.setUserId(user.getId()); Set<Permission> permissions = new HashSet<>(); permissions.add(permissionFactory.newPermission(BrokerDomains.BROKER_DOMAIN, Actions.connect, user.getScopeId())); accessInfoCreator.setPermissions(permissions); accessInfoService.create(accessInfoCreator); // Create default password CredentialCreator credential = credentialFactory.newCreator(account.getId(), user.getId(), CredentialType.PASSWORD, baseName + "-password", CredentialStatus.ENABLED, null); credentialService.create(credential); return user; }