Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add endpoint to fetch the roles of an authenticated user: Fixes #1187" #1250

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
@Produces(MediaType.APPLICATION_JSON)
@Tag(name = "user", description = "Manage users")
public interface UserService {

@GET
@Path("roles")
@Blocking
List<String> getRoles();

@GET
@Path("search")
@Blocking
Expand Down
4 changes: 0 additions & 4 deletions horreum-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-admin-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security-properties-file</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ private static UserData toUserInfo(UserRepresentation rep) {
return new UserData(rep.getId(), rep.getUsername(), rep.getFirstName(), rep.getLastName(), rep.getEmail());
}

@Override public List<String> getRoles() {
if (identity.isAnonymous()) {
throw ServiceException.forbidden("Please log in and try again");
}
var representations = keycloak.realm(realm).users().search(identity.getPrincipal().getName(), true);
if (representations.isEmpty()) {
throw ServiceException.notFound("Username not found");
}
var roles = keycloak.realm(realm).users().get(representations.get(0).getId()).roles().getAll().getRealmMappings();
return roles.stream().map(RoleRepresentation::getName).collect(Collectors.toList());
}

@Override
public List<UserData> searchUsers(String query) {
if (identity.isAnonymous()) {
Expand Down
7 changes: 0 additions & 7 deletions horreum-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,3 @@ horreum.dev-services.enabled=true
quarkus.datasource.devservices.enabled=false
quarkus.datasource.migration.devservices.enabled=false
quarkus.keycloak.devservices.enabled=false

## Add a dummy administrator in dev mode with name "user" and password "secret" with Basic HTTP authentication
%dev.quarkus.http.auth.basic=true
%dev.quarkus.security.users.embedded.enabled=true
%dev.quarkus.security.users.embedded.plain-text=true
%dev.quarkus.security.users.embedded.users.user=secret
%dev.quarkus.security.users.embedded.roles.user=admin
20 changes: 7 additions & 13 deletions horreum-web/src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {AppContextType} from "./context/@types/appContextTypes";
import {Button, Form, FormGroup, Modal, Spinner, TextInput} from "@patternfly/react-core";
import {userApi} from "./api";
import store from "./store";
import {BASIC_AUTH, UPDATE_ROLES, AFTER_LOGOUT, STORE_PROFILE, UPDATE_DEFAULT_TEAM} from "./auth";
import {BASIC_AUTH, UPDATE_ROLES, AFTER_LOGOUT} from "./auth";

type LoginModalProps = {
username: string
Expand Down Expand Up @@ -38,18 +38,12 @@ export default function LoginModal(props: LoginModalProps) {
onClick={() => {
setCreating(true)
store.dispatch({type: BASIC_AUTH, username, password});

userApi.getRoles()
.then(roles => {
alerting.dispatchInfo("LOGIN", "Log in successful", "Successful log in of user " + username, 3000)
store.dispatch({type: UPDATE_ROLES, authenticated: true, roles: roles});
userApi.searchUsers(username!).then(
userData => store.dispatch({type: STORE_PROFILE, profile: userData.filter(u => u.username == username).at(0)}),
error => alerting.dispatchInfo("LOGIN", "Unable to get user profile", error, 30000))
userApi.defaultTeam().then(
response => store.dispatch({ type: UPDATE_DEFAULT_TEAM, team: response }),
error => alerting.dispatchInfo("LOGIN", "Cannot retrieve default team", error, 30000)
)

// TODO: instead of fetching userdata, should be fetching the user roles instead
userApi.info([username || ''])
.then(userdata => {
alerting.dispatchInfo("LOGIN", "Log in successful", "Successful log in of user " + userdata[0].username, 3000)
store.dispatch({type: UPDATE_ROLES, authenticated: true, roles: [/* TODO: the roles fetched */]});
},
error => {
alerting.dispatchInfo("LOGIN", "Failed to authenticate", error, 30000)
Expand Down
1 change: 0 additions & 1 deletion horreum-web/src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const authMiddleware: Middleware = {
url: ctx.url,
init: {
...ctx.init,
credentials: "omit", // this prevents the browser from showing the native auth dialog
headers: {...ctx.init.headers, Authorization: "Basic " + basicAuthToken},
},
})
Expand Down
2 changes: 1 addition & 1 deletion horreum-web/src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function initKeycloak(state: State) {
}
})
}
store.dispatch({ type: INIT, keycloak: oidc ? keycloak : undefined, initPromise: initPromise })
store.dispatch({ type: INIT, keycloak: keycloak, initPromise: initPromise })
})
.catch(noop)
}
Loading