001// Generated by delombok at Mon Oct 12 23:00:28 BST 2020 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020package org.apache.isis.extensions.secman.api.user; 021 022import java.util.Collection; 023import java.util.Optional; 024import java.util.function.Consumer; 025import javax.annotation.Nullable; 026import org.apache.isis.applib.value.Password; 027import org.apache.isis.extensions.secman.api.role.ApplicationRole; 028import org.apache.isis.extensions.secman.api.tenancy.ApplicationTenancy; 029import lombok.NonNull; 030 031public interface ApplicationUserRepository<U extends ApplicationUser> { 032 /** 033 * @return detached entity 034 */ 035 U newApplicationUser(); 036 037 Optional<U> findByUsername(String username); 038 039 U findOrCreateUserByUsername(String username); 040 041 Collection<U> allUsers(); 042 043 Collection<U> find(String search); 044 045 Collection<U> findByAtPath(String atPath); 046 047 Collection<U> findByRole(ApplicationRole role); 048 049 Collection<U> findByTenancy(ApplicationTenancy tenancy); 050 051 /** 052 * auto-complete support 053 054 * @param search 055 */ 056 Collection<U> findMatching(String search); 057 058 void enable(ApplicationUser user); 059 060 void disable(ApplicationUser user); 061 062 boolean isAdminUser(ApplicationUser user); 063 064 boolean isPasswordFeatureEnabled(ApplicationUser holder); 065 066 boolean updatePassword(ApplicationUser user, String password); 067 068 U newUser(String username, AccountType accountType, Consumer<U> beforePersist); 069 070 default U newLocalUser(@NonNull String username, @Nullable Password password, @NonNull ApplicationUserStatus status) { 071 if (username == null) { 072 throw new java.lang.NullPointerException("username is marked non-null but is null"); 073 } 074 if (status == null) { 075 throw new java.lang.NullPointerException("status is marked non-null but is null"); 076 } 077 return newUser(username, AccountType.LOCAL, user -> { 078 user.setStatus(status); 079 if (password != null) { 080 updatePassword(user, password.getPassword()); 081 } 082 }); 083 } 084 085 default U newDelegateUser(String username, ApplicationUserStatus status) { 086 return newUser(username, AccountType.DELEGATED, user -> { 087 user.setStatus(status); 088 }); 089 } 090}