Search in sources :

Example 1 with UserId

use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.

the class RoleUITest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    MetaStorage storage = conquery.getMetaStorage();
    Role mandator = new Role("testMandatorName", "testMandatorLabel", storage);
    RoleId mandatorId = mandator.getId();
    User user = new User("testUser@test.de", "testUserName", storage);
    UserId userId = user.getId();
    try {
        ConqueryPermission permission = DatasetPermission.onInstance(Ability.READ.asSet(), new DatasetId("testDatasetId"));
        storage.addRole(mandator);
        storage.addUser(user);
        // override permission object, because it might have changed by the subject
        // owning the permission
        mandator.addPermission(permission);
        user.addRole(mandator);
        URI classBase = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), RoleUIResource.class, "getRole").buildFromMap(Map.of(ROLE_ID, mandatorId.toString()));
        Response response = conquery.getClient().target(classBase).request().get();
        assertThat(response.getStatus()).isEqualTo(200);
        // Check for Freemarker Errors
        assertThat(response.readEntity(String.class).toLowerCase()).doesNotContain(List.of("freemarker", "debug"));
    } finally {
        storage.removeRole(mandatorId);
        storage.removeUser(userId);
    }
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Response(javax.ws.rs.core.Response) ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) RoleUIResource(com.bakdata.conquery.resources.admin.ui.RoleUIResource) RoleId(com.bakdata.conquery.models.identifiable.ids.specific.RoleId) URI(java.net.URI) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)

Example 2 with UserId

use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.

the class UserAuthenticationManagementProcessor method tryRegister.

public boolean tryRegister(ProtoUser pUser) {
    final UserId id = pUser.createId();
    User user = storage.getUser(id);
    if (user == null) {
        log.warn("Unable to add new user {}. Probably already existed.", pUser);
        return false;
    }
    log.trace("Added the user {} to the authorization storage", id);
    if (AuthorizationHelper.registerForAuthentication(realm, user, pUser.getCredentials(), false)) {
        log.trace("Added the user {} to the realm {}", id, realm.getName());
        return true;
    }
    log.trace("Failed to add added the user {} to the realm {}", id, realm.getName());
    return false;
}
Also used : ProtoUser(com.bakdata.conquery.apiv1.auth.ProtoUser) User(com.bakdata.conquery.models.auth.entities.User) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId)

Example 3 with UserId

use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.

the class IntrospectionDelegatingRealm method doGetAuthenticationInfo.

@Override
@SneakyThrows
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(TOKEN_CLASS.isAssignableFrom(token.getClass()))) {
        log.trace("Incompatible token. Expected {}, got {}", TOKEN_CLASS, token.getClass());
        return null;
    }
    log.trace("Token has expected format!");
    TokenIntrospectionSuccessResponse successResponse = tokenCache.get((BearerToken) token);
    log.trace("Got an successful token introspection response.");
    UserId userId = extractId(successResponse);
    User user = getUserOrThrowUnknownAccount(storage, userId);
    return new ConqueryAuthenticationInfo(user, token, this, true);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) TokenIntrospectionSuccessResponse(com.nimbusds.oauth2.sdk.TokenIntrospectionSuccessResponse) SneakyThrows(lombok.SneakyThrows)

Example 4 with UserId

use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.

the class ConqueryTokenRealm method doGetAuthenticationInfo.

@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(TOKEN_CLASS.isAssignableFrom(token.getClass()))) {
        log.trace("Incompatible token. Expected {}, got {}", TOKEN_CLASS, token.getClass());
        return null;
    }
    log.trace("Token has expected format: {}\tWas: {} ", TOKEN_CLASS, token.getClass());
    DecodedJWT decodedToken = null;
    try {
        decodedToken = jwtConfig.getTokenVerifier(this).verify((String) token.getCredentials());
    } catch (TokenExpiredException e) {
        log.trace("The provided token is expired.");
        throw new ExpiredCredentialsException(e);
    } catch (SignatureVerificationException | InvalidClaimException e) {
        log.trace("The provided token was not successfully verified against its signature or claims.");
        throw new IncorrectCredentialsException(e);
    } catch (JWTVerificationException e) {
        log.trace("The provided token could not be verified.", e);
        throw new AuthenticationException(e);
    } catch (Exception e) {
        log.trace("Unable to decode token", e);
        throw new AuthenticationException(e);
    }
    log.trace("Received valid token.");
    String username = decodedToken.getSubject();
    UserId userId = UserId.Parser.INSTANCE.parse(username);
    final User user = getUserOrThrowUnknownAccount(storage, userId);
    return new ConqueryAuthenticationInfo(user, token, this, true);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) InvalidClaimException(com.auth0.jwt.exceptions.InvalidClaimException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) InvalidClaimException(com.auth0.jwt.exceptions.InvalidClaimException) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) SignatureVerificationException(com.auth0.jwt.exceptions.SignatureVerificationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 5 with UserId

use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.

the class UserIdTokenExtractor method apply.

/**
 * Tries to extract a plain {@link UserId} from the request to submit it for the authentication process.
 */
@Override
public AuthenticationToken apply(ContainerRequestContext requestContext) {
    // Check if the developer passed a UserId under whose the Request should be
    // executed
    // Check the Authorization header for a String which can be parsed as a UserId
    String uid = requestContext.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
    if (uid != null) {
        uid = uid.replaceFirst("^Bearer ", "");
    } else {
        // Check also the query parameter "access_token" for a UserId
        uid = requestContext.getUriInfo().getQueryParameters().getFirst(UID_QUERY_STRING_PARAMETER);
    }
    UserId userId = null;
    if (StringUtils.isEmpty(uid)) {
        // If nothing was found execute the request as the default user
        userId = defaultUser.getId();
        return new DevelopmentToken(userId, uid);
    }
    try {
        userId = UserId.Parser.INSTANCE.parse(uid);
        log.trace("Parsed UserId: {}", userId);
        return new DevelopmentToken(userId, uid);
    } catch (Exception e) {
        log.trace("Unable to extract a valid user id.");
        return null;
    }
}
Also used : UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId)

Aggregations

UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)19 User (com.bakdata.conquery.models.auth.entities.User)10 Test (org.junit.jupiter.api.Test)10 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)4 ConqueryAuthenticationInfo (com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)4 Date (java.util.Date)4 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)3 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)3 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)3 Jackson (com.bakdata.conquery.io.jackson.Jackson)3 StoreMappings (com.bakdata.conquery.io.storage.StoreMappings)3 IterationStatistic (com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic)3 XodusStoreFactory (com.bakdata.conquery.models.config.XodusStoreFactory)3 Dataset (com.bakdata.conquery.models.datasets.Dataset)3 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)3 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)3 Files (com.google.common.io.Files)3 Validators (io.dropwizard.jersey.validation.Validators)3 File (java.io.File)3 IOException (java.io.IOException)3