[Minor] Code cleanup

This commit is contained in:
Robert von Burg 2016-02-10 20:33:27 +01:00
parent d5491e4f0d
commit 461eef4b23
15 changed files with 57 additions and 57 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
target/
.classpath
.project
.settings/
.settings/

View File

@ -677,7 +677,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
}
// create new user
Set<String> newRoles = new HashSet<String>(currentRoles);
Set<String> newRoles = new HashSet<>(currentRoles);
newRoles.remove(roleName);
User newUser = new User(existingUser.getUserId(), existingUser.getUsername(), existingUser.getPassword(),
existingUser.getFirstname(), existingUser.getLastname(), existingUser.getUserState(), newRoles,
@ -973,7 +973,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
// create new set of privileges with out the to removed privilege
Set<String> privilegeNames = existingRole.getPrivilegeNames();
Map<String, IPrivilege> newPrivileges = new HashMap<String, IPrivilege>(privilegeNames.size() - 1);
Map<String, IPrivilege> newPrivileges = new HashMap<>(privilegeNames.size() - 1);
for (String name : privilegeNames) {
IPrivilege privilege = existingRole.getPrivilege(name);
if (!privilege.getName().equals(privilegeName))
@ -1053,8 +1053,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
List<Certificate> sessions = this.privilegeContextMap.values().stream().map(p -> p.getCertificate())
.filter(c -> !c.getUserState().isSystem()).collect(Collectors.toList());
try (OutputStream outputStream = AesCryptoHelper.wrapEncrypt(this.secretKey,
new FileOutputStream(this.persistSessionsPath))) {
try (FileOutputStream fout = new FileOutputStream(this.persistSessionsPath);
OutputStream outputStream = AesCryptoHelper.wrapEncrypt(this.secretKey, fout)) {
CertificateStubsDomWriter writer = new CertificateStubsDomWriter(sessions, outputStream);
writer.write();
@ -1083,8 +1083,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
"Sessions data file is not a file but exists at " + this.persistSessionsPath.getAbsolutePath());
List<CertificateStub> certificateStubs;
try (InputStream inputStream = AesCryptoHelper.wrapDecrypt(this.secretKey,
new FileInputStream(this.persistSessionsPath))) {
try (FileInputStream fin = new FileInputStream(this.persistSessionsPath);
InputStream inputStream = AesCryptoHelper.wrapDecrypt(this.secretKey, fin)) {
CertificateStubsSaxReader reader = new CertificateStubsSaxReader(inputStream);
certificateStubs = reader.read();
@ -1199,8 +1199,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
private PrivilegeContext buildPrivilegeContext(Certificate certificate, User user) {
Set<String> userRoles = user.getRoles();
Map<String, IPrivilege> privileges = new HashMap<String, IPrivilege>();
Map<String, PrivilegePolicy> policies = new HashMap<String, PrivilegePolicy>();
Map<String, IPrivilege> privileges = new HashMap<>();
Map<String, PrivilegePolicy> policies = new HashMap<>();
// get a cache of the privileges and policies for this user
for (String roleName : userRoles) {

View File

@ -58,14 +58,14 @@ public class XmlPersistenceHandler implements PersistenceHandler {
@Override
public List<User> getAllUsers() {
synchronized (this.userMap) {
return new LinkedList<User>(this.userMap.values());
return new LinkedList<>(this.userMap.values());
}
}
@Override
public List<Role> getAllRoles() {
synchronized (this.roleMap) {
return new LinkedList<Role>(this.roleMap.values());
return new LinkedList<>(this.roleMap.values());
}
}
@ -138,7 +138,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
public void initialize(Map<String, String> paramsMap) {
// copy parameter map
this.parameterMap = Collections.unmodifiableMap(new HashMap<String, String>(paramsMap));
this.parameterMap = Collections.unmodifiableMap(new HashMap<>(paramsMap));
// get and validate base bath
String basePath = this.parameterMap.get(XmlConstants.XML_PARAM_BASE_PATH);

View File

@ -77,9 +77,9 @@ public class BootstrapConfigurationHelper {
throw new RuntimeException("Could not create path " + pathF.getAbsolutePath());
}
Map<String, String> parameterMap = new HashMap<String, String>();
Map<String, String> encryptionHandlerParameterMap = new HashMap<String, String>();
Map<String, String> persistenceHandlerParameterMap = new HashMap<String, String>();
Map<String, String> parameterMap = new HashMap<>();
Map<String, String> encryptionHandlerParameterMap = new HashMap<>();
Map<String, String> persistenceHandlerParameterMap = new HashMap<>();
// TODO ask other questions...
parameterMap.put("autoPersistOnPasswordChange", "true");

View File

@ -61,7 +61,7 @@ public class PasswordCreaterUI {
JLabel hash = new JLabel("Hash:", SwingConstants.RIGHT);
String[] digests = new String[] { "MD2", "MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512" };
final JComboBox<String> digestCombo = new JComboBox<String>(digests);
final JComboBox<String> digestCombo = new JComboBox<>(digests);
digestCombo.setSelectedIndex(3);
final JPasswordField passwordField = new JPasswordField();
final JTextField hashField = new JTextField(150);

View File

@ -59,8 +59,8 @@ public class PrivilegeInitializationHelper {
}
// delegate using input stream
try {
return initializeFromXml(new FileInputStream(privilegeXmlFile));
try (FileInputStream fin = new FileInputStream(privilegeXmlFile)) {
return initializeFromXml(fin);
} catch (Exception e) {
String msg = "Failed to load configuration from {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, privilegeXmlFile.getAbsolutePath());

View File

@ -51,8 +51,8 @@ public class PrivilegeContext {
Map<String, PrivilegePolicy> policies) {
this.userRep = userRep;
this.certificate = certificate;
this.privileges = Collections.unmodifiableMap(new HashMap<String, IPrivilege>(privileges));
this.policies = Collections.unmodifiableMap(new HashMap<String, PrivilegePolicy>(policies));
this.privileges = Collections.unmodifiableMap(new HashMap<>(privileges));
this.policies = Collections.unmodifiableMap(new HashMap<>(policies));
}
public UserRep getUserRep() {

View File

@ -46,7 +46,7 @@ public class PrivilegeContainerModel {
* Default constructor
*/
public PrivilegeContainerModel() {
this.policies = new HashMap<String, Class<PrivilegePolicy>>();
this.policies = new HashMap<>();
}
/**

View File

@ -109,8 +109,8 @@ public final class PrivilegeImpl implements IPrivilege {
*/
@Override
public PrivilegeRep asPrivilegeRep() {
return new PrivilegeRep(this.name, this.policy, this.allAllowed, new HashSet<String>(this.denyList),
new HashSet<String>(this.allowList));
return new PrivilegeRep(this.name, this.policy, this.allAllowed, new HashSet<>(this.denyList),
new HashSet<>(this.allowList));
}
/**

View File

@ -86,7 +86,7 @@ public final class Role {
}
// build privileges from rep
Map<String, IPrivilege> privilegeMap = new HashMap<String, IPrivilege>(roleRep.getPrivileges().size());
Map<String, IPrivilege> privilegeMap = new HashMap<>(roleRep.getPrivileges().size());
for (PrivilegeRep privilege : roleRep.getPrivileges()) {
privilegeMap.put(privilege.getName(), new PrivilegeImpl(privilege));
}
@ -136,7 +136,7 @@ public final class Role {
* @return a {@link RoleRep} which is a representation of this object used to serialize and view on clients
*/
public RoleRep asRoleRep() {
List<PrivilegeRep> privileges = new ArrayList<PrivilegeRep>();
List<PrivilegeRep> privileges = new ArrayList<>();
for (Entry<String, IPrivilege> entry : this.privilegeMap.entrySet()) {
privileges.add(entry.getValue().asPrivilegeRep());
}

View File

@ -116,7 +116,7 @@ public final class User {
if (roles == null)
this.roles = Collections.emptySet();
else
this.roles = Collections.unmodifiableSet(new HashSet<String>(roles));
this.roles = Collections.unmodifiableSet(new HashSet<>(roles));
if (locale == null)
this.locale = Locale.getDefault();
@ -126,7 +126,7 @@ public final class User {
if (propertyMap == null)
this.propertyMap = Collections.emptyMap();
else
this.propertyMap = Collections.unmodifiableMap(new HashMap<String, String>(propertyMap));
this.propertyMap = Collections.unmodifiableMap(new HashMap<>(propertyMap));
}
/**
@ -234,7 +234,7 @@ public final class User {
*/
public UserRep asUserRep() {
return new UserRep(this.userId, this.username, this.firstname, this.lastname, this.userState,
new HashSet<String>(this.roles), this.locale, new HashMap<String, String>(this.propertyMap));
new HashSet<>(this.roles), this.locale, new HashMap<>(this.propertyMap));
}
/**

View File

@ -32,7 +32,7 @@ import ch.eitchnet.privilege.model.internal.PrivilegeContainerModel;
*/
public class PrivilegeConfigSaxReader extends DefaultHandler {
private Deque<ElementParser> buildersStack = new ArrayDeque<ElementParser>();
private Deque<ElementParser> buildersStack = new ArrayDeque<>();
private PrivilegeContainerModel containerModel;
@ -143,7 +143,7 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
// <Parameter name="autoPersistOnPasswordChange" value="true" />
private Map<String, String> parameterMap = new HashMap<String, String>();
private Map<String, String> parameterMap = new HashMap<>();
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)

View File

@ -47,7 +47,7 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
protected static final Logger logger = LoggerFactory.getLogger(PrivilegeModelSaxReader.class);
private Deque<ElementParser> buildersStack = new ArrayDeque<ElementParser>();
private Deque<ElementParser> buildersStack = new ArrayDeque<>();
private List<User> users;
private List<Role> roles;
@ -55,8 +55,8 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
private boolean insideUser;
public PrivilegeModelSaxReader() {
this.users = new ArrayList<User>();
this.roles = new ArrayList<Role>();
this.users = new ArrayList<>();
this.roles = new ArrayList<>();
}
/**
@ -147,7 +147,7 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
}
private void init() {
this.privileges = new HashMap<String, IPrivilege>();
this.privileges = new HashMap<>();
this.text = null;
@ -155,8 +155,8 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
this.privilegeName = null;
this.privilegePolicy = null;
this.allAllowed = false;
this.denyList = new HashSet<String>();
this.allowList = new HashSet<String>();
this.denyList = new HashSet<>();
this.allowList = new HashSet<>();
}
@Override
@ -201,8 +201,8 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
this.privilegeName = null;
this.privilegePolicy = null;
this.allAllowed = false;
this.denyList = new HashSet<String>();
this.allowList = new HashSet<String>();
this.denyList = new HashSet<>();
this.allowList = new HashSet<>();
} else if (qName.equals(XmlConstants.XML_ROLE)) {
@ -245,7 +245,7 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
Map<String, String> parameters;
public UserParser() {
this.userRoles = new HashSet<String>();
this.userRoles = new HashSet<>();
}
@Override
@ -307,7 +307,7 @@ public class PrivilegeModelSaxReader extends DefaultHandler {
// <Property name="organizationalUnit" value="Development" />
public Map<String, String> parameterMap = new HashMap<String, String>();
public Map<String, String> parameterMap = new HashMap<>();
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

View File

@ -622,7 +622,7 @@ public class PrivilegeTest extends AbstractPrivilegeTest {
// testAddUserTedAsBob
login(BOB, ArraysHelper.copyOf(PASS_BOB));
// let's add a new user ted
HashSet<String> roles = new HashSet<String>();
HashSet<String> roles = new HashSet<>();
roles.add(ROLE_USER);
userRep = new UserRep(null, TED, "Ted", "Newman", UserState.ENABLED, roles, null,
new HashMap<String, String>());
@ -738,7 +738,7 @@ public class PrivilegeTest extends AbstractPrivilegeTest {
// let's add a new user bob
UserRep userRep = new UserRep(null, BOB, "Bob", "Newman", UserState.NEW,
new HashSet<String>(Arrays.asList(ROLE_MY)), null, new HashMap<String, String>());
new HashSet<>(Arrays.asList(ROLE_MY)), null, new HashMap<String, String>());
Certificate certificate = this.ctx.getCertificate();
privilegeHandler.addUser(certificate, userRep, null);
logger.info("Added user " + BOB);

View File

@ -131,9 +131,9 @@ public class XmlTest {
@Test
public void canWriteConfig() {
Map<String, String> parameterMap = new HashMap<String, String>();
Map<String, String> encryptionHandlerParameterMap = new HashMap<String, String>();
Map<String, String> persistenceHandlerParameterMap = new HashMap<String, String>();
Map<String, String> parameterMap = new HashMap<>();
Map<String, String> encryptionHandlerParameterMap = new HashMap<>();
Map<String, String> persistenceHandlerParameterMap = new HashMap<>();
parameterMap.put("autoPersistOnPasswordChange", "true");
encryptionHandlerParameterMap.put("hashAlgorithm", "SHA-256");
@ -189,7 +189,7 @@ public class XmlTest {
assertEquals("en_gb", admin.getLocale().toString());
assertThat(admin.getRoles(), containsInAnyOrder("PrivilegeAdmin", "AppUser"));
Map<String, String> properties = admin.getProperties();
assertEquals(new HashSet<String>(Arrays.asList("organization", "organizationalUnit")), properties.keySet());
assertEquals(new HashSet<>(Arrays.asList("organization", "organizationalUnit")), properties.keySet());
assertEquals("eitchnet.ch", properties.get("organization"));
assertEquals("Development", properties.get("organizationalUnit"));
@ -233,7 +233,7 @@ public class XmlTest {
// AppUser
Role appUser = findRole("AppUser", roles);
assertEquals("AppUser", appUser.getName());
assertEquals(new HashSet<String>(Arrays.asList("ch.eitchnet.privilege.test.model.TestRestrictable")),
assertEquals(new HashSet<>(Arrays.asList("ch.eitchnet.privilege.test.model.TestRestrictable")),
appUser.getPrivilegeNames());
IPrivilege testRestrictable = appUser.getPrivilege("ch.eitchnet.privilege.test.model.TestRestrictable");
@ -320,31 +320,31 @@ public class XmlTest {
Set<String> userRoles;
Map<String, IPrivilege> privilegeMap;
List<User> users = new ArrayList<User>();
propertyMap = new HashMap<String, String>();
List<User> users = new ArrayList<>();
propertyMap = new HashMap<>();
propertyMap.put("prop1", "value1");
userRoles = new HashSet<String>();
userRoles = new HashSet<>();
userRoles.add("role1");
users.add(new User("1", "user1", "blabla", "Bob", "White", UserState.DISABLED, userRoles, Locale.ENGLISH,
propertyMap));
propertyMap = new HashMap<String, String>();
propertyMap = new HashMap<>();
propertyMap.put("prop2", "value2");
userRoles = new HashSet<String>();
userRoles = new HashSet<>();
userRoles.add("role2");
users.add(new User("2", "user2", "haha", "Leonard", "Sheldon", UserState.ENABLED, userRoles, Locale.ENGLISH,
propertyMap));
List<Role> roles = new ArrayList<Role>();
List<Role> roles = new ArrayList<>();
Set<String> list = Collections.emptySet();
privilegeMap = new HashMap<String, IPrivilege>();
privilegeMap = new HashMap<>();
privilegeMap.put("priv1", new PrivilegeImpl("priv1", "DefaultPrivilege", true, list, list));
roles.add(new Role("role1", privilegeMap));
privilegeMap = new HashMap<String, IPrivilege>();
Set<String> denyList = new HashSet<String>();
privilegeMap = new HashMap<>();
Set<String> denyList = new HashSet<>();
denyList.add("myself");
Set<String> allowList = new HashSet<String>();
Set<String> allowList = new HashSet<>();
allowList.add("other");
privilegeMap.put("priv2", new PrivilegeImpl("priv2", "DefaultPrivilege", false, denyList, allowList));
roles.add(new Role("role2", privilegeMap));