Search in sources :

Example 26 with User

use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.

the class AdminProcessor method getPermissionOverviewAsCSV.

/**
 * Renders the permission overview for certain {@link User} in form of a CSV.
 */
public String getPermissionOverviewAsCSV(Collection<User> users) {
    StringWriter sWriter = new StringWriter();
    CsvWriter writer = config.getCsv().createWriter(sWriter);
    List<String> scope = config.getAuthorizationRealms().getOverviewScope();
    // Header
    writeAuthOverviewHeader(writer, scope);
    // Body
    for (User user : users) {
        writeAuthOverviewUser(writer, scope, user, storage, config);
    }
    return sWriter.toString();
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) StringWriter(java.io.StringWriter) CsvWriter(com.univocity.parsers.csv.CsvWriter)

Example 27 with User

use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.

the class UIProcessor method getAuthOverview.

public FEAuthOverview getAuthOverview() {
    Collection<FEAuthOverview.OverviewRow> overview = new TreeSet<>();
    for (User user : getStorage().getAllUsers()) {
        Collection<Group> userGroups = AuthorizationHelper.getGroupsOf(user, getStorage());
        List<Role> effectiveRoles = user.getRoles().stream().map(getStorage()::getRole).collect(Collectors.toList());
        userGroups.forEach(g -> effectiveRoles.addAll(g.getRoles().stream().map(getStorage()::getRole).collect(Collectors.toList())));
        overview.add(FEAuthOverview.OverviewRow.builder().user(user).groups(userGroups).effectiveRoles(effectiveRoles).build());
    }
    return FEAuthOverview.builder().overview(overview).build();
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User)

Example 28 with User

use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.

the class ExcelRenderer method setMetaData.

/**
 * Include meta data in the xlsx such as the title, owner/author, tag and the name of this instance.
 */
private <E extends ManagedExecution<?> & SingleTableResult> void setMetaData(E exec) {
    final POIXMLProperties.CoreProperties coreProperties = workbook.getXSSFWorkbook().getProperties().getCoreProperties();
    coreProperties.setTitle(exec.getLabelWithoutAutoLabelSuffix());
    final User owner = exec.getOwner();
    coreProperties.setCreator(owner != null ? owner.getLabel() : config.getApplicationName());
    coreProperties.setKeywords(String.join(" ", exec.getTags()));
    final POIXMLProperties.ExtendedProperties extendedProperties = workbook.getXSSFWorkbook().getProperties().getExtendedProperties();
    extendedProperties.setApplication(config.getApplicationName());
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) POIXMLProperties(org.apache.poi.ooxml.POIXMLProperties)

Example 29 with User

use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.

the class JwtPkceVerifyingRealm method doGetAuthenticationInfo.

@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    Optional<JwtPkceVerifyingRealmFactory.IdpConfiguration> idpConfigurationOpt = idpConfigurationSupplier.get();
    if (idpConfigurationOpt.isEmpty()) {
        log.warn("Unable to start authentication, because idp configuration is not available.");
        return null;
    }
    JwtPkceVerifyingRealmFactory.IdpConfiguration idpConfiguration = idpConfigurationOpt.get();
    log.trace("Creating token verifier");
    TokenVerifier<AccessToken> verifier = TokenVerifier.create(((BearerToken) token).getToken(), AccessToken.class).withChecks(new TokenVerifier.RealmUrlCheck(idpConfiguration.getIssuer()), TokenVerifier.SUBJECT_EXISTS_CHECK, activeVerifier).withChecks(tokenChecks).publicKey(idpConfiguration.getPublicKey()).audience(allowedAudience);
    String subject;
    log.trace("Verifying token");
    AccessToken accessToken = null;
    try {
        verifier.verify();
        accessToken = verifier.getToken();
    } catch (VerificationException e) {
        log.trace("Verification failed", e);
        throw new IncorrectCredentialsException(e);
    }
    subject = accessToken.getSubject();
    if (subject == null) {
        // Should not happen, as sub is mandatory in an access_token
        throw new UnsupportedTokenException("Unable to extract a subject from the provided token.");
    }
    log.trace("Authentication successfull for subject {}", subject);
    UserId userId = new UserId(subject);
    User user = storage.getUser(userId);
    if (user != null) {
        log.trace("Successfully authenticated user {}", userId);
        return new ConqueryAuthenticationInfo(user, token, this, true);
    }
    // Try alternative ids
    List<UserId> alternativeIds = new ArrayList<>();
    for (String alternativeIdClaim : alternativeIdClaims) {
        Object altId = accessToken.getOtherClaims().get(alternativeIdClaim);
        if (!(altId instanceof String)) {
            log.trace("Found no value for alternative id claim {}", alternativeIdClaim);
            continue;
        }
        userId = new UserId((String) altId);
        user = storage.getUser(userId);
        if (user != null) {
            log.trace("Successfully mapped subject {} using user id {}", subject, userId);
            return new ConqueryAuthenticationInfo(user, token, this, true);
        }
    }
    throw new UnknownAccountException("The user id was unknown: " + subject);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ArrayList(java.util.ArrayList) UnsupportedTokenException(org.apache.shiro.authc.pam.UnsupportedTokenException) JwtPkceVerifyingRealmFactory(com.bakdata.conquery.models.config.auth.JwtPkceVerifyingRealmFactory) AccessToken(org.keycloak.representations.AccessToken) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) VerificationException(org.keycloak.common.VerificationException)

Example 30 with User

use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.

the class AuthorizationController method flatCopyUser.

/**
 * Creates a copy of an existing user. The copied user has the same effective permissions as the original user
 * at the time of copying, but these are flatted. This means that the original user might hold certain permissions
 * through inheritance from roles or groups, the copy will hold the permissions directly.
 * @param originUser The user to make a flat copy of
 * @param namePrefix The prefix for the id of the new copied user
 * @return A flat copy of the referenced user
 */
public static User flatCopyUser(@NonNull User originUser, String namePrefix, @NonNull MetaStorage storage) {
    final UserId originUserId = originUser.getId();
    if (Strings.isNullOrEmpty(namePrefix)) {
        throw new IllegalArgumentException("There must be a prefix");
    }
    // Find a new user id that is not used yet
    String name = null;
    do {
        name = namePrefix + UUID.randomUUID() + originUserId.getName();
    } while (storage.getUser(new UserId(name)) != null);
    // Retrieve original user and its effective permissions
    // Copy inherited permissions
    Set<ConqueryPermission> copiedPermission = new HashSet<>();
    copiedPermission.addAll(originUser.getEffectivePermissions());
    // Give read permission to all executions the original user owned
    copiedPermission.addAll(storage.getAllExecutions().stream().filter(originUser::isOwner).map(exc -> exc.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
    // Give read permission to all form configs the original user owned
    copiedPermission.addAll(storage.getAllFormConfigs().stream().filter(originUser::isOwner).map(conf -> conf.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
    // Create copied user
    User copy = new User(name, originUser.getLabel(), storage);
    storage.addUser(copy);
    copy.updatePermissions(copiedPermission);
    return copy;
}
Also used : ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) ProtoUser(com.bakdata.conquery.apiv1.auth.ProtoUser) User(com.bakdata.conquery.models.auth.entities.User) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) HashSet(java.util.HashSet)

Aggregations

User (com.bakdata.conquery.models.auth.entities.User)49 Test (org.junit.jupiter.api.Test)17 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)14 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)14 Dataset (com.bakdata.conquery.models.datasets.Dataset)11 UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)10 Group (com.bakdata.conquery.models.auth.entities.Group)8 Role (com.bakdata.conquery.models.auth.entities.Role)8 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)8 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)7 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)5 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)5 ConqueryAuthenticationInfo (com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)5 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConqueryPermission (com.bakdata.conquery.models.auth.permissions.ConqueryPermission)4 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Query (com.bakdata.conquery.apiv1.query.Query)3 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)3