Skip to content

Commit 808ee62

Browse files
committed
Minor improvements to the credentials management app
1 parent d6d8ea4 commit 808ee62

File tree

21 files changed

+193
-101
lines changed

21 files changed

+193
-101
lines changed

app/credentials-management/src/main/java/org/phoebus/applications/credentialsmanagement/CredentialsManagementController.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,28 @@
5353
*/
5454
public class CredentialsManagementController {
5555

56+
@SuppressWarnings("unused")
5657
@FXML
5758
private Node parent;
5859

60+
@SuppressWarnings("unused")
5961
@FXML
6062
private TableView<ServiceItem> tableView;
63+
@SuppressWarnings("unused")
6164
@FXML
6265
private TableColumn<ServiceItem, Void> actionButtonColumn;
66+
@SuppressWarnings("unused")
6367
@FXML
6468
private TableColumn<ServiceItem, String> usernameColumn;
69+
@SuppressWarnings("unused")
6570
@FXML
6671
private TableColumn<ServiceItem, String> passwordColumn;
72+
@SuppressWarnings("unused")
6773
@FXML
6874
private Button clearAllCredentialsButton;
69-
75+
@SuppressWarnings("unused")
7076
@FXML
71-
private TableColumn scopeColumn;
77+
private TableColumn<ServiceItem, String> scopeColumn;
7278

7379
private final SimpleBooleanProperty listEmpty = new SimpleBooleanProperty(true);
7480
private final ObservableList<ServiceItem> serviceItems =
@@ -84,10 +90,11 @@ public CredentialsManagementController(List<ServiceAuthenticationProvider> authe
8490
this.secureStore = secureStore;
8591
}
8692

93+
@SuppressWarnings("unused")
8794
@FXML
8895
public void initialize() {
8996

90-
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
97+
tableView.getStylesheets().add(getClass().getResource("/css/credentials-management-style.css").toExternalForm());
9198
clearAllCredentialsButton.disableProperty().bind(listEmpty);
9299
Callback<TableColumn<ServiceItem, Void>, TableCell<ServiceItem, Void>> actionColumnCellFactory = new Callback<>() {
93100
@Override
@@ -129,9 +136,12 @@ public void updateItem(Void o, boolean empty) {
129136
usernameColumn.setCellFactory(c -> new UsernameTableCell());
130137
passwordColumn.setCellFactory(c -> new PasswordTableCell());
131138

139+
scopeColumn.setStyle( "-fx-alignment: CENTER-LEFT;");
140+
132141
updateTable();
133142
}
134143

144+
@SuppressWarnings("unused")
135145
@FXML
136146
public void logOutFromAll() {
137147
try {
@@ -181,19 +191,19 @@ private void updateTable() {
181191
// Match saved tokens with an authentication provider, where applicable
182192
List<ServiceItem> serviceItems = savedTokens.stream().map(token -> {
183193
ServiceAuthenticationProvider provider =
184-
authenticationProviders.stream().filter(p-> p.getAuthenticationScope().equals(token.getAuthenticationScope())).findFirst().orElse(null);
194+
authenticationProviders.stream().filter(p-> p.getAuthenticationScope().getScope().equals(token.getAuthenticationScope().getScope())).findFirst().orElse(null);
185195
return new ServiceItem(provider, token.getUsername(), token.getPassword());
186196
}).collect(Collectors.toList());
187197
// Also need to add ServiceItems for providers not matched with a saved token, i.e. for logged-out services
188198
authenticationProviders.forEach(p -> {
189199
Optional<ServiceItem> serviceItem =
190200
serviceItems.stream().filter(si ->
191-
p.getAuthenticationScope().equals(si.getAuthenticationScope())).findFirst();
201+
p.getAuthenticationScope().getScope().equals(si.getAuthenticationScope().getScope())).findFirst();
192202
if(serviceItem.isEmpty()){
193203
serviceItems.add(new ServiceItem(p));
194204
}
195205
});
196-
serviceItems.sort(Comparator.comparing(ServiceItem::getAuthenticationScope));
206+
serviceItems.sort(Comparator.comparing(i -> i.getAuthenticationScope().getDisplayName()));
197207
Platform.runLater(() -> {
198208
this.serviceItems.setAll(serviceItems);
199209
listEmpty.set(savedTokens.isEmpty());
@@ -241,7 +251,13 @@ public AuthenticationScope getAuthenticationScope() {
241251
@SuppressWarnings("unused")
242252
public String getScope(){
243253
return serviceAuthenticationProvider != null ?
244-
serviceAuthenticationProvider.getAuthenticationScope().getName() : "";
254+
serviceAuthenticationProvider.getAuthenticationScope().getScope() : "";
255+
}
256+
257+
@SuppressWarnings("unused")
258+
public String getDisplayName(){
259+
return serviceAuthenticationProvider != null ?
260+
serviceAuthenticationProvider.getAuthenticationScope().getDisplayName() : "";
245261
}
246262

247263
public String getPassword(){
@@ -260,7 +276,8 @@ public boolean isLoginAction(){
260276
return loginAction;
261277
}
262278
}
263-
private class UsernameTableCell extends TableCell<ServiceItem, String>{
279+
280+
private static class UsernameTableCell extends TableCell<ServiceItem, String>{
264281
private final TextField textField = new TextField();
265282

266283
public UsernameTableCell(){

app/credentials-management/src/main/java/org/phoebus/applications/credentialsmanagement/CredentialsManagementStage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public CredentialsManagementStage(List<ServiceAuthenticationProvider> authentica
6161
try {
6262
fxmlLoader.load();
6363
Scene scene = new Scene(fxmlLoader.getRoot());
64-
scene.getStylesheets().add(getClass().getResource("/css/credentials-management-style.css").toExternalForm());
6564
setTitle(Messages.Title);
6665
setScene(scene);
6766
} catch (Exception exception) {

app/credentials-management/src/main/resources/css/credentials-management-style.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
}
1212

1313
.table-view .table-cell{
14-
-fx-font-weight: bold;
15-
-fx-font-size: 14px;
14+
-fx-font-size: 12px;
15+
}
16+
17+
.table-view .column-header > .label{
18+
-fx-alignment: CENTER-LEFT;
19+
-fx-padding: 5px 3px 3px 3px;
1620
}
1721

1822
.button-style{

app/credentials-management/src/main/resources/org/phoebus/applications/credentialsmanagement/CredentialsManagement.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<columns>
4343
<TableColumn fx:id="scopeColumn" prefWidth="${parent.width * 0.2}" text="%Scope">
4444
<cellValueFactory>
45-
<PropertyValueFactory property="scope" />
45+
<PropertyValueFactory property="displayName" />
4646
</cellValueFactory>
4747
</TableColumn>
4848
<TableColumn fx:id="usernameColumn" editable="true" prefWidth="${parent.width * 0.3}" text="%UserName">
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2025 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.applications.logbook.authentication;
6+
7+
import org.phoebus.security.tokens.AuthenticationScope;
8+
9+
public class OlogAuthenticationScope implements AuthenticationScope {
10+
11+
@Override
12+
public String getScope() {
13+
return "logbook";
14+
}
15+
16+
@Override
17+
public String getDisplayName() {
18+
return "Logbook";
19+
}
20+
}

app/logbook/olog/client-es/src/main/java/org/phoebus/applications/logbook/authentication/OlogServiceAuthenticationProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
public class OlogServiceAuthenticationProvider implements ServiceAuthenticationProvider {
2929

30+
private final AuthenticationScope ologAuthenticationScope;
31+
32+
public OlogServiceAuthenticationProvider(){
33+
ologAuthenticationScope = new OlogAuthenticationScope();
34+
}
35+
3036
@Override
3137
public void authenticate(String username, String password){
3238
try {
@@ -45,6 +51,6 @@ public void logout(String token) {
4551

4652
@Override
4753
public AuthenticationScope getAuthenticationScope() {
48-
return AuthenticationScope.LOGBOOK;
54+
return ologAuthenticationScope;
4955
}
5056
}

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogHttpClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.DeserializationFeature;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
1111
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
12+
import org.phoebus.applications.logbook.authentication.OlogAuthenticationScope;
1213
import org.phoebus.logbook.Attachment;
1314
import org.phoebus.logbook.LogClient;
1415
import org.phoebus.logbook.LogEntry;
@@ -112,7 +113,7 @@ public OlogHttpClient build() {
112113
private ScopedAuthenticationToken getCredentialsFromSecureStore() {
113114
try {
114115
SecureStore secureStore = new SecureStore();
115-
return secureStore.getScopedAuthenticationToken(AuthenticationScope.LOGBOOK);
116+
return secureStore.getScopedAuthenticationToken(new OlogAuthenticationScope());
116117
} catch (Exception e) {
117118
Logger.getLogger(OlogHttpClient.class.getName()).log(Level.WARNING, "Unable to instantiate SecureStore", e);
118119
return null;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2025 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.olog.api;
6+
7+
import org.phoebus.security.tokens.AuthenticationScope;
8+
9+
public class OlogAuthenticationScope implements AuthenticationScope {
10+
11+
@Override
12+
public String getScope() {
13+
return "logbook";
14+
}
15+
16+
@Override
17+
public String getDisplayName() {
18+
return "Logbook";
19+
}
20+
}

app/logbook/olog/client/src/main/java/org/phoebus/olog/api/OlogClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public OlogClientBuilder password(String password) {
123123
private ScopedAuthenticationToken getCredentialsFromSecureStore() {
124124
try {
125125
SecureStore secureStore = new SecureStore();
126-
return secureStore.getScopedAuthenticationToken(AuthenticationScope.LOGBOOK);
126+
return secureStore.getScopedAuthenticationToken(new OlogAuthenticationScope());
127127
} catch (Exception e) {
128128
Logger.getLogger(OlogClient.class.getName()).log(Level.WARNING, "Unable to instantiate SecureStore", e);
129129
return null;

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javafx.util.Callback;
4040
import javafx.util.Duration;
4141
import javafx.util.StringConverter;
42+
import org.phoebus.applications.logbook.authentication.OlogAuthenticationScope;
4243
import org.phoebus.framework.jobs.JobManager;
4344
import org.phoebus.logbook.LogClient;
4445
import org.phoebus.logbook.LogEntry;
@@ -202,7 +203,7 @@ public void initialize() {
202203
contextMenu.setOnShowing(e -> {
203204
try {
204205
SecureStore store = new SecureStore();
205-
ScopedAuthenticationToken scopedAuthenticationToken = store.getScopedAuthenticationToken(AuthenticationScope.LOGBOOK);
206+
ScopedAuthenticationToken scopedAuthenticationToken = store.getScopedAuthenticationToken(new OlogAuthenticationScope());
206207
userHasSignedIn.set(scopedAuthenticationToken != null);
207208
} catch (Exception ex) {
208209
logger.log(Level.WARNING, "Secure Store file not found.", ex);

0 commit comments

Comments
 (0)