/** * Creates a new credential instance * * @return */ public Credential newCredential() { return CREDENTIAL_FACTORY.newEntity(null); }
/** * Creates a new credential list result instance * * @return */ public CredentialListResult newCredentialListResult() { return CREDENTIAL_FACTORY.newListResult(); }
/** * Creates a new credential creator instance * * @return */ public CredentialCreator newCredentialCreator() { return CREDENTIAL_FACTORY.newCreator(null, null, null, null, null, null); }
private void deleteCredentialByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(accountId); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
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; }); }
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }
/** * 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); }
if (CredentialType.API_KEY.equals(infoCredential.getCredentialType())) { String fullApiKey = infoCredential.getCredentialKey();
public CredentialQuery newQuery() { return CREDENTIAL_FACTORY.newQuery(null); } }
private void deleteCredentialByAccountId(KapuaId scopeId, KapuaId accountId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(accountId); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
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; }); }
private long countExistingCredentials(CredentialType credentialType, KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); KapuaQuery<Credential> credentialQuery = credentialFactory.newQuery(scopeId); CredentialType ct = credentialType; QueryPredicate credentialTypePredicate = new AttributePredicateImpl<>(CredentialAttributes.CREDENTIAL_TYPE, ct); QueryPredicate userIdPredicate = new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId); QueryPredicate andPredicate = new AndPredicateImpl().and(credentialTypePredicate).and(userIdPredicate); credentialQuery.setPredicate(andPredicate); return count(credentialQuery); }
@Override public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) { // // Token data UsernamePasswordCredentials token = (UsernamePasswordCredentials) authenticationToken; String tokenUsername = token.getUsername(); String tokenPassword = token.getPassword(); // // Info data LoginAuthenticationInfo info = (LoginAuthenticationInfo) authenticationInfo; User infoUser = (User) info.getPrincipals().getPrimaryPrincipal(); Credential infoCredential = (Credential) info.getCredentials(); // // Match token with info boolean credentialMatch = false; if (tokenUsername.equals(infoUser.getName()) && CredentialType.PASSWORD.equals(infoCredential.getCredentialType()) && BCrypt.checkpw(tokenPassword, infoCredential.getCredentialKey())) { credentialMatch = true; // FIXME: if true cache token password for authentication performance improvement } return credentialMatch; }
public CredentialQuery newQuery() { return CREDENTIAL_FACTORY.newQuery(null); } }
/** * Creates a new credential creator instance * * @return */ public CredentialCreator newCredentialCreator() { return CREDENTIAL_FACTORY.newCreator(null, null, null, null, null, null); }
/** * Creates a new credential instance * * @return */ public Credential newCredential() { return CREDENTIAL_FACTORY.newEntity(null); }
/** * Creates a new credential list result instance * * @return */ public CredentialListResult newCredentialListResult() { return CREDENTIAL_FACTORY.newListResult(); }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }
@Override public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) { // // Token data UsernamePasswordCredentials token = (UsernamePasswordCredentials) authenticationToken; String tokenUsername = token.getUsername(); String tokenPassword = token.getPassword(); // // Info data LoginAuthenticationInfo info = (LoginAuthenticationInfo) authenticationInfo; User infoUser = (User) info.getPrincipals().getPrimaryPrincipal(); Credential infoCredential = (Credential) info.getCredentials(); // // Match token with info boolean credentialMatch = false; if (tokenUsername.equals(infoUser.getName()) && CredentialType.PASSWORD.equals(infoCredential.getCredentialType()) && BCrypt.checkpw(tokenPassword, infoCredential.getCredentialKey())) { credentialMatch = true; // FIXME: if true cache token password for authentication performance improvement } return credentialMatch; }
private void deleteCredentialByUserId(KapuaId scopeId, KapuaId userId) throws KapuaException { KapuaLocator locator = KapuaLocator.getInstance(); CredentialFactory credentialFactory = locator.getFactory(CredentialFactory.class); CredentialQuery query = credentialFactory.newQuery(scopeId); query.setPredicate(new AttributePredicateImpl<>(CredentialAttributes.USER_ID, userId)); CredentialListResult credentialsToDelete = query(query); for (Credential c : credentialsToDelete.getItems()) { delete(c.getScopeId(), c.getId()); } }