Skip to content

Commit 9d74bf9

Browse files
author
Vladimir Kotal
authored
cleanup Sonar issues in authnz plugins (#3791)
* cleanup Sonar issues * fix javadoc * fix test * fix replace
1 parent 55582cc commit 9d74bf9

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

plugins/src/main/java/opengrok/auth/plugin/FalsePlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -30,17 +30,21 @@
3030
import org.opengrok.indexer.configuration.Project;
3131

3232
/**
33+
* Authorization plugin that returns false (not allowed) for all decisions.
34+
* This is mostly handy for testing or special cases when one needs to quickly disallow access.
3335
*
3436
* @author Krystof Tulinger
3537
*/
3638
public class FalsePlugin implements IAuthorizationPlugin {
3739

3840
@Override
3941
public void load(Map<String, Object> parameters) {
42+
// trivial plugin
4043
}
4144

4245
@Override
4346
public void unload() {
47+
// trivial plugin
4448
}
4549

4650
@Override

plugins/src/main/java/opengrok/auth/plugin/LdapFilterPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -144,7 +144,7 @@ public void fillSession(HttpServletRequest req, User user) {
144144
throw new AuthorizationException(ex);
145145
}
146146

147-
LOGGER.log(Level.FINER, "LDAP user {0} allowed on {2}",
147+
LOGGER.log(Level.FINER, "LDAP user {0} allowed on {1}",
148148
new Object[]{ldapUser, ldapProvider});
149149
updateSession(req, true);
150150
}
@@ -179,7 +179,7 @@ String expandFilter(String filter, LdapUser ldapUser, User user) {
179179
}
180180
}
181181

182-
filter = filter.replaceAll("\\\\%", "%");
182+
filter = filter.replace("\\%", "%");
183183

184184
return filter;
185185
}

plugins/src/main/java/opengrok/auth/plugin/LdapUserPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ String expandFilter(User user) {
138138

139139
filter = expandUserFilter(user, filter);
140140

141-
filter = filter.replaceAll("\\\\%", "%");
141+
filter = filter.replace("\\%", "%");
142142

143143
return filter;
144144
}

plugins/src/main/java/opengrok/auth/plugin/TruePlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -30,17 +30,21 @@
3030
import org.opengrok.indexer.configuration.Project;
3131

3232
/**
33+
* Authorization plugin that returns true (allowed) for all decisions.
34+
* This is mostly handy for testing or cases when one needs to explicitly allow a project/group.
3335
*
3436
* @author Krystof Tulinger
3537
*/
3638
public class TruePlugin implements IAuthorizationPlugin {
3739

3840
@Override
3941
public void load(Map<String, Object> parameters) {
42+
// trivial plugin
4043
}
4144

4245
@Override
4346
public void unload() {
47+
// trivial plugin
4448
}
4549

4650
@Override

plugins/src/main/java/opengrok/auth/plugin/UserPlugin.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -68,24 +68,25 @@ private IUserDecoder getDecoder(String name) throws ClassNotFoundException, NoSu
6868

6969
@Override
7070
public void load(Map<String, Object> parameters) {
71-
String decoder_name;
72-
if ((decoder_name = (String) parameters.get(DECODER_CLASS_PARAM)) == null) {
71+
String decoderName;
72+
if ((decoderName = (String) parameters.get(DECODER_CLASS_PARAM)) == null) {
7373
throw new NullPointerException(String.format("missing " +
7474
"parameter '%s' in %s configuration",
7575
DECODER_CLASS_PARAM, UserPlugin.class.getName()));
7676
}
7777

78-
LOGGER.log(Level.INFO, "loading decoder: {0}", decoder_name);
78+
LOGGER.log(Level.INFO, "loading decoder: {0}", decoderName);
7979
try {
80-
decoder = getDecoder(decoder_name);
80+
decoder = getDecoder(decoderName);
8181
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
8282
InvocationTargetException | InstantiationException e) {
83-
throw new RuntimeException("cannot load decoder " + decoder_name, e);
83+
throw new RuntimeException("cannot load decoder " + decoderName, e);
8484
}
8585
}
8686

8787
@Override
8888
public void unload() {
89+
// no state to free
8990
}
9091

9192
private User getUser(HttpServletRequest request) {

plugins/src/main/java/opengrok/auth/plugin/UserWhiteListPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import java.util.stream.Stream;
4242

4343
public class UserWhiteListPlugin implements IAuthorizationPlugin {
44-
private static final String className = UserWhiteListPlugin.class.getName();
45-
private static final Logger LOGGER = Logger.getLogger(className);
44+
private static final String CLASS_NAME = UserWhiteListPlugin.class.getName();
45+
private static final Logger LOGGER = Logger.getLogger(CLASS_NAME);
4646

4747
// configuration parameters
4848
static final String FILE_PARAM = "file";

plugins/src/main/java/opengrok/auth/plugin/ldap/FakeLdapFacade.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.TreeSet;
3131

3232
/**
33-
*
33+
* LDAP facade for testing.
3434
* @author Krystof Tulinger
3535
*/
3636
public class FakeLdapFacade extends AbstractLdapProvider {
@@ -45,12 +45,12 @@ public LdapSearchResult<Map<String, Set<String>>> lookupLdapContent(String dn, S
4545
if ("objectclass=*".equals(filter)) {
4646
List<String> v = Arrays.asList(values);
4747
if (v.isEmpty()) {
48-
map.put("mail", new TreeSet<>(Arrays.asList("[email protected]")));
49-
map.put("ou", new TreeSet<>(Arrays.asList("MI6")));
48+
map.put("mail", new TreeSet<>(List.of("[email protected]")));
49+
map.put("ou", new TreeSet<>(List.of("MI6")));
5050
} else {
5151
for (String x : v) {
5252
if (x.equals("uid")) {
53-
map.put("uid", new TreeSet<>(Arrays.asList("bondjame")));
53+
map.put("uid", new TreeSet<>(List.of("bondjame")));
5454
}
5555
}
5656
}
@@ -72,6 +72,6 @@ public boolean isConfigured() {
7272

7373
@Override
7474
public void close() {
75+
// No need to close anything as this is fake plugin.
7576
}
76-
7777
}

0 commit comments

Comments
 (0)