Skip to content

Commit d08f1ba

Browse files
committed
Auto format all files
1 parent 8779d28 commit d08f1ba

File tree

75 files changed

+20090
-16986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+20090
-16986
lines changed

src/main/java/org/phoebus/channelfinder/Application.java

Lines changed: 79 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
package org.phoebus.channelfinder;
1212

13+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
14+
import io.swagger.v3.oas.annotations.servers.Server;
1315
import java.io.File;
1416
import java.io.FileOutputStream;
1517
import java.io.IOException;
@@ -19,9 +21,6 @@
1921
import java.util.ServiceLoader;
2022
import java.util.logging.Level;
2123
import java.util.logging.Logger;
22-
23-
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
24-
import io.swagger.v3.oas.annotations.servers.Server;
2524
import org.phoebus.channelfinder.example.PopulateService;
2625
import org.phoebus.channelfinder.processors.ChannelProcessor;
2726
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,95 +37,95 @@
3837
import org.springframework.util.FileCopyUtils;
3938

4039
@EnableAutoConfiguration
41-
@ComponentScan(basePackages="org.phoebus.channelfinder")
40+
@ComponentScan(basePackages = "org.phoebus.channelfinder")
4241
@EnableScheduling
43-
@OpenAPIDefinition(
44-
servers = {
45-
@Server(url = "/")
46-
}
47-
)
42+
@OpenAPIDefinition(servers = {@Server(url = "/")})
4843
@SpringBootApplication
4944
public class Application implements ApplicationRunner {
5045

51-
static final Logger logger = Logger.getLogger(Application.class.getName());
46+
static final Logger logger = Logger.getLogger(Application.class.getName());
5247

53-
public static void main(String[] args){
54-
// Set the java truststore used by channelfinder
55-
configureTruststore();
56-
SpringApplication.run(Application.class, args);
57-
}
48+
public static void main(String[] args) {
49+
// Set the java truststore used by channelfinder
50+
configureTruststore();
51+
SpringApplication.run(Application.class, args);
52+
}
5853

59-
/**
60-
* Set the default ssl trust store
61-
*/
62-
private static void configureTruststore() {
63-
if (System.getProperty("javax.net.ssl.trustStore") == null) {
64-
logger.log(Level.INFO, "using default javax.net.ssl.trustStore");
65-
try (InputStream in = Application.class.getResourceAsStream("/keystore/cacerts")) {
66-
// read input
67-
File tempFile= File.createTempFile("cf-", "-truststore");
68-
FileOutputStream out = new FileOutputStream(tempFile);
69-
FileCopyUtils.copy(in, out);
70-
tempFile.deleteOnExit();
71-
System.setProperty("javax.net.ssl.trustStore", tempFile.getAbsolutePath());
72-
} catch (IOException e) {
73-
logger.log(Level.SEVERE, "failed to configure channelfinder truststore", e);
74-
}
75-
}
76-
if (System.getProperty("javax.net.ssl.trustStorePassword") == null) {
77-
logger.log(Level.INFO, "using default javax.net.ssl.trustStorePassword");
78-
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
79-
}
54+
/** Set the default ssl trust store */
55+
private static void configureTruststore() {
56+
if (System.getProperty("javax.net.ssl.trustStore") == null) {
57+
logger.log(Level.INFO, "using default javax.net.ssl.trustStore");
58+
try (InputStream in = Application.class.getResourceAsStream("/keystore/cacerts")) {
59+
// read input
60+
File tempFile = File.createTempFile("cf-", "-truststore");
61+
FileOutputStream out = new FileOutputStream(tempFile);
62+
FileCopyUtils.copy(in, out);
63+
tempFile.deleteOnExit();
64+
System.setProperty("javax.net.ssl.trustStore", tempFile.getAbsolutePath());
65+
} catch (IOException e) {
66+
logger.log(Level.SEVERE, "failed to configure channelfinder truststore", e);
67+
}
68+
}
69+
if (System.getProperty("javax.net.ssl.trustStorePassword") == null) {
70+
logger.log(Level.INFO, "using default javax.net.ssl.trustStorePassword");
71+
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
8072
}
73+
}
8174

82-
@Autowired
83-
PopulateService service;
75+
@Autowired PopulateService service;
8476

85-
public void run(ApplicationArguments args) throws Exception {
86-
if(args.containsOption("demo-data")) {
87-
int numberOfCells = args.getOptionValues("demo-data").stream().mapToInt(Integer::valueOf).max().orElse(1);
88-
logger.log(Level.INFO, "Populating the channelfinder service with demo data");
89-
service.createDB(numberOfCells);
90-
}
91-
if(args.containsOption("cleanup")) {
92-
int numberOfCells = args.getOptionValues("cleanup").stream().mapToInt(Integer::valueOf).max().orElse(1);
93-
// This is kind of a hack, the create Db is being called to reset the channels and then deleting them
94-
logger.log(Level.INFO, "Populating the channelfinder service with demo data first, then deleting them");
95-
service.createDB(numberOfCells);
96-
logger.log(Level.INFO, "Cleaning up the populated demo data");
97-
service.cleanupDB();
98-
}
77+
public void run(ApplicationArguments args) throws Exception {
78+
if (args.containsOption("demo-data")) {
79+
int numberOfCells =
80+
args.getOptionValues("demo-data").stream().mapToInt(Integer::valueOf).max().orElse(1);
81+
logger.log(Level.INFO, "Populating the channelfinder service with demo data");
82+
service.createDB(numberOfCells);
9983
}
100-
101-
/**
102-
* List of {@link ChannelProcessor} implementations called when new channels are created or existing channels are updated
103-
*
104-
* @return A list of {@link ChannelProcessor}s, if any have been registered over SPI.
105-
*/
106-
@Bean
107-
public List<ChannelProcessor> channelProcessors() {
108-
List<ChannelProcessor> processors = new ArrayList<>();
109-
ServiceLoader<ChannelProcessor> loader = ServiceLoader.load(ChannelProcessor.class);
110-
loader.stream().forEach(p -> {
111-
ChannelProcessor notifier = p.get();
112-
processors.add(notifier);
113-
});
114-
return processors;
84+
if (args.containsOption("cleanup")) {
85+
int numberOfCells =
86+
args.getOptionValues("cleanup").stream().mapToInt(Integer::valueOf).max().orElse(1);
87+
// This is kind of a hack, the create Db is being called to reset the channels and then
88+
// deleting them
89+
logger.log(
90+
Level.INFO,
91+
"Populating the channelfinder service with demo data first, then deleting them");
92+
service.createDB(numberOfCells);
93+
logger.log(Level.INFO, "Cleaning up the populated demo data");
94+
service.cleanupDB();
11595
}
96+
}
11697

117-
/**
118-
* {@link TaskExecutor} used when calling {@link ChannelProcessor}s.
119-
*
120-
* @return A {@link TaskExecutor}
121-
*/
122-
@Bean
123-
public TaskExecutor taskExecutor() {
124-
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
125-
taskExecutor.setCorePoolSize(3);
126-
taskExecutor.setMaxPoolSize(10);
127-
taskExecutor.setQueueCapacity(25);
98+
/**
99+
* List of {@link ChannelProcessor} implementations called when new channels are created or
100+
* existing channels are updated
101+
*
102+
* @return A list of {@link ChannelProcessor}s, if any have been registered over SPI.
103+
*/
104+
@Bean
105+
public List<ChannelProcessor> channelProcessors() {
106+
List<ChannelProcessor> processors = new ArrayList<>();
107+
ServiceLoader<ChannelProcessor> loader = ServiceLoader.load(ChannelProcessor.class);
108+
loader.stream()
109+
.forEach(
110+
p -> {
111+
ChannelProcessor notifier = p.get();
112+
processors.add(notifier);
113+
});
114+
return processors;
115+
}
128116

129-
return taskExecutor;
130-
}
117+
/**
118+
* {@link TaskExecutor} used when calling {@link ChannelProcessor}s.
119+
*
120+
* @return A {@link TaskExecutor}
121+
*/
122+
@Bean
123+
public TaskExecutor taskExecutor() {
124+
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
125+
taskExecutor.setCorePoolSize(3);
126+
taskExecutor.setMaxPoolSize(10);
127+
taskExecutor.setQueueCapacity(25);
131128

129+
return taskExecutor;
130+
}
132131
}

src/main/java/org/phoebus/channelfinder/AuthorizationService.java

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Collections;
77
import java.util.List;
88
import java.util.stream.Collectors;
9-
109
import org.phoebus.channelfinder.entity.Channel;
1110
import org.phoebus.channelfinder.entity.Property;
1211
import org.phoebus.channelfinder.entity.Tag;
@@ -18,102 +17,101 @@
1817
@Service
1918
public class AuthorizationService {
2019

21-
public static List<String> admin_groups;
22-
public static List<String> channel_groups;
23-
public static List<String> property_groups;
24-
public static List<String> tag_groups;
20+
public static List<String> admin_groups;
21+
public static List<String> channel_groups;
22+
public static List<String> property_groups;
23+
public static List<String> tag_groups;
2524

26-
@Value("${admin-groups:cf-admins}")
27-
void initializeAdminRoles(String groups) {
28-
AuthorizationService.admin_groups = Arrays.asList(groups.split(",")).stream().map(g ->
29-
"ROLE_" + g.trim().toUpperCase()
30-
).collect(Collectors.toList());
31-
}
32-
@Value("${channel-groups:cf-channels}")
33-
void initializeChannelModRoles(String groups) {
34-
AuthorizationService.channel_groups = Arrays.asList(groups.split(",")).stream().map(g ->
35-
"ROLE_" + g.trim().toUpperCase()
36-
).collect(Collectors.toList());
37-
}
38-
@Value("${property-groups:cf-properties}")
39-
void initializePropertyRoles(String groups) {
40-
AuthorizationService.property_groups = Arrays.asList(groups.split(",")).stream().map(g ->
41-
"ROLE_" + g.trim().toUpperCase()
42-
).collect(Collectors.toList());
43-
}
44-
@Value("${tag-groups:cf-tags}")
45-
void initializeTagRoles(String groups) {
46-
AuthorizationService.tag_groups = Arrays.asList(groups.split(",")).stream().map(g ->
47-
"ROLE_" + g.trim().toUpperCase()
48-
).collect(Collectors.toList());
49-
}
25+
@Value("${admin-groups:cf-admins}")
26+
void initializeAdminRoles(String groups) {
27+
AuthorizationService.admin_groups =
28+
Arrays.asList(groups.split(",")).stream()
29+
.map(g -> "ROLE_" + g.trim().toUpperCase())
30+
.collect(Collectors.toList());
31+
}
5032

51-
public enum ROLES {
52-
CF_ADMIN(admin_groups),
53-
CF_CHANNEL(channel_groups),
54-
CF_PROPERTY(property_groups),
55-
CF_TAG(tag_groups);
33+
@Value("${channel-groups:cf-channels}")
34+
void initializeChannelModRoles(String groups) {
35+
AuthorizationService.channel_groups =
36+
Arrays.asList(groups.split(",")).stream()
37+
.map(g -> "ROLE_" + g.trim().toUpperCase())
38+
.collect(Collectors.toList());
39+
}
5640

57-
private final List<String> groups;
41+
@Value("${property-groups:cf-properties}")
42+
void initializePropertyRoles(String groups) {
43+
AuthorizationService.property_groups =
44+
Arrays.asList(groups.split(",")).stream()
45+
.map(g -> "ROLE_" + g.trim().toUpperCase())
46+
.collect(Collectors.toList());
47+
}
5848

59-
private ROLES(List<String> groups) {
60-
this.groups = groups;
61-
}
62-
}
49+
@Value("${tag-groups:cf-tags}")
50+
void initializeTagRoles(String groups) {
51+
AuthorizationService.tag_groups =
52+
Arrays.asList(groups.split(",")).stream()
53+
.map(g -> "ROLE_" + g.trim().toUpperCase())
54+
.collect(Collectors.toList());
55+
}
6356

64-
public boolean isAuthorizedOwner(Authentication authentication, Tag data) {
65-
ArrayList<String> auth = new ArrayList<>();
66-
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
67-
for(GrantedAuthority a: auths)
68-
auth.add(a.getAuthority());
69-
70-
if(!Collections.disjoint(auth,ROLES.CF_ADMIN.groups))
71-
return true;
72-
if(authentication.getName().equals(data.getOwner()) || auth.contains("ROLE_" + data.getOwner().trim().toUpperCase()))
73-
return true;
74-
return false;
75-
}
57+
public enum ROLES {
58+
CF_ADMIN(admin_groups),
59+
CF_CHANNEL(channel_groups),
60+
CF_PROPERTY(property_groups),
61+
CF_TAG(tag_groups);
7662

77-
public boolean isAuthorizedOwner(Authentication authentication, Property data) {
78-
ArrayList<String> auth = new ArrayList<>();
79-
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
80-
for(GrantedAuthority a: auths)
81-
auth.add(a.getAuthority());
82-
83-
if(!Collections.disjoint(auth,ROLES.CF_ADMIN.groups))
84-
return true;
85-
if(authentication.getName().equals(data.getOwner()) || auth.contains("ROLE_" + data.getOwner().trim().toUpperCase()))
86-
return true;
87-
return false;
88-
}
63+
private final List<String> groups;
8964

90-
public boolean isAuthorizedOwner(Authentication authentication, Channel data) {
91-
ArrayList<String> auth = new ArrayList<>();
92-
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
93-
for(GrantedAuthority a: auths)
94-
auth.add(a.getAuthority());
95-
96-
if(!Collections.disjoint(auth,ROLES.CF_ADMIN.groups))
97-
return true;
98-
if(authentication.getName().equals(data.getOwner()) || auth.contains("ROLE_" + data.getOwner().trim().toUpperCase()))
99-
return true;
100-
return false;
65+
private ROLES(List<String> groups) {
66+
this.groups = groups;
10167
}
68+
}
10269

103-
public boolean isAuthorizedRole(Authentication authentication, ROLES expectedRole) {
104-
ArrayList<String> auth = new ArrayList<>();
105-
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
106-
for(GrantedAuthority a: auths)
107-
auth.add(a.getAuthority());
108-
109-
if(!Collections.disjoint(auth,ROLES.CF_ADMIN.groups))
110-
return true;
111-
else if(!Collections.disjoint(auth,ROLES.CF_CHANNEL.groups) && expectedRole != ROLES.CF_ADMIN)
112-
return true;
113-
else if(!Collections.disjoint(auth,ROLES.CF_PROPERTY.groups) && (expectedRole == ROLES.CF_PROPERTY || expectedRole == ROLES.CF_TAG))
114-
return true;
115-
else if(!Collections.disjoint(auth,ROLES.CF_TAG.groups) && expectedRole == ROLES.CF_TAG)
116-
return true;
117-
return false;
118-
}
70+
public boolean isAuthorizedOwner(Authentication authentication, Tag data) {
71+
ArrayList<String> auth = new ArrayList<>();
72+
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
73+
for (GrantedAuthority a : auths) auth.add(a.getAuthority());
74+
75+
if (!Collections.disjoint(auth, ROLES.CF_ADMIN.groups)) return true;
76+
if (authentication.getName().equals(data.getOwner())
77+
|| auth.contains("ROLE_" + data.getOwner().trim().toUpperCase())) return true;
78+
return false;
79+
}
80+
81+
public boolean isAuthorizedOwner(Authentication authentication, Property data) {
82+
ArrayList<String> auth = new ArrayList<>();
83+
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
84+
for (GrantedAuthority a : auths) auth.add(a.getAuthority());
85+
86+
if (!Collections.disjoint(auth, ROLES.CF_ADMIN.groups)) return true;
87+
if (authentication.getName().equals(data.getOwner())
88+
|| auth.contains("ROLE_" + data.getOwner().trim().toUpperCase())) return true;
89+
return false;
90+
}
91+
92+
public boolean isAuthorizedOwner(Authentication authentication, Channel data) {
93+
ArrayList<String> auth = new ArrayList<>();
94+
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
95+
for (GrantedAuthority a : auths) auth.add(a.getAuthority());
96+
97+
if (!Collections.disjoint(auth, ROLES.CF_ADMIN.groups)) return true;
98+
if (authentication.getName().equals(data.getOwner())
99+
|| auth.contains("ROLE_" + data.getOwner().trim().toUpperCase())) return true;
100+
return false;
101+
}
102+
103+
public boolean isAuthorizedRole(Authentication authentication, ROLES expectedRole) {
104+
ArrayList<String> auth = new ArrayList<>();
105+
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
106+
for (GrantedAuthority a : auths) auth.add(a.getAuthority());
107+
108+
if (!Collections.disjoint(auth, ROLES.CF_ADMIN.groups)) return true;
109+
else if (!Collections.disjoint(auth, ROLES.CF_CHANNEL.groups) && expectedRole != ROLES.CF_ADMIN)
110+
return true;
111+
else if (!Collections.disjoint(auth, ROLES.CF_PROPERTY.groups)
112+
&& (expectedRole == ROLES.CF_PROPERTY || expectedRole == ROLES.CF_TAG)) return true;
113+
else if (!Collections.disjoint(auth, ROLES.CF_TAG.groups) && expectedRole == ROLES.CF_TAG)
114+
return true;
115+
return false;
116+
}
119117
}

0 commit comments

Comments
 (0)