/** * 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); }
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; }