Skip to content

Commit

Permalink
checkstyle security issue - nonstatic nested classes and use of Random()
Browse files Browse the repository at this point in the history
  • Loading branch information
SavvasMisaghMoayyed committed Dec 10, 2014
1 parent f91c38d commit ba3c069
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
*/
package org.jasig.cas.monitor;

import javax.validation.constraints.NotNull;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.validation.constraints.NotNull;

/**
* Describes a monitor that observes a pool of resources.
*
Expand Down Expand Up @@ -71,7 +70,7 @@ public void setMaxWait(final int time) {
**/
@Override
public PoolStatus observe() {
final Future<StatusCode> result = this.executor.submit(new Validator());
final Future<StatusCode> result = this.executor.submit(new Validator(this));
StatusCode code;
String description = null;
try {
Expand Down Expand Up @@ -116,11 +115,21 @@ public PoolStatus observe() {
*/
protected abstract int getActiveCount();

private static class Validator implements Callable<StatusCode> {
private final AbstractPoolMonitor monitor;

/**
* Instantiates a new Validator.
*
* @param monitor the monitor
*/
public Validator(final AbstractPoolMonitor monitor) {
this.monitor = monitor;
}

private class Validator implements Callable<StatusCode> {
@Override
public StatusCode call() throws Exception {
return checkPool();
return this.monitor.checkPool();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public final void setLogoutType(final LogoutType logoutType) {
}

@Override
public RegisteredService clone() {
public final RegisteredService clone() {
final AbstractRegisteredService clone = newInstance();
clone.copyFrom(this);
return clone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private String genPassword(final String psw, final String salt, final int iter)
}
}
@Entity(name="users")
public class UsersTable {
public static class UsersTable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private String getSqlInsertStatementToCreateUserAccount(final int i) {
}

@Entity(name="casusers")
public class UsersTable {
public static class UsersTable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private String getSqlInsertStatementToCreateUserAccount(final int i) {
}

@Entity(name="cassearchusers")
public class UsersTable {
public static class UsersTable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void verifyConcurrentServiceTicketGeneration() throws Exception {
try {
final List<ServiceTicketGenerator> generators = new ArrayList<ServiceTicketGenerator>(CONCURRENT_SIZE);
for (int i = 0; i < CONCURRENT_SIZE; i++) {
generators.add(new ServiceTicketGenerator(newTgt.getId()));
generators.add(new ServiceTicketGenerator(newTgt.getId(), this.jpaTicketRegistry, this.txManager));
}
final List<Future<String>> results = executor.invokeAll(generators);
for (Future<String> result : results) {
Expand Down Expand Up @@ -201,12 +201,16 @@ public ServiceTicket doInTransaction(final TransactionStatus status) {
});
}

class ServiceTicketGenerator implements Callable<String> {

private static class ServiceTicketGenerator implements Callable<String> {
private PlatformTransactionManager txManager;
private String parentTgtId;
private final JpaTicketRegistry jpaTicketRegistry;

public ServiceTicketGenerator(final String tgtId) {
public ServiceTicketGenerator(final String tgtId, final JpaTicketRegistry jpaTicketRegistry,
final PlatformTransactionManager txManager) {
parentTgtId = tgtId;
this.jpaTicketRegistry = jpaTicketRegistry;
this.txManager = txManager;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.jasig.cas.ticket.registry.support;

import org.jasig.cas.ticket.registry.JpaTicketRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
Expand Down Expand Up @@ -213,7 +214,7 @@ private LockingStrategy newLockTxProxy(final String appId, final String uniqueId
return (LockingStrategy) Proxy.newProxyInstance(
JpaLockingStrategy.class.getClassLoader(),
new Class[] {LockingStrategy.class},
new TransactionalLockInvocationHandler(lock));
new TransactionalLockInvocationHandler(lock, this.txManager));
}

private String getOwner(final String appId) {
Expand Down Expand Up @@ -252,11 +253,15 @@ private void testConcurrency(final ExecutorService executor, final LockingStrate
assertTrue("Release count should be <= 1 but was " + releaseCount, releaseCount <= 1);
}

class TransactionalLockInvocationHandler implements InvocationHandler {
private JpaLockingStrategy jpaLock;
private static class TransactionalLockInvocationHandler implements InvocationHandler {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final JpaLockingStrategy jpaLock;
private final PlatformTransactionManager txManager;

public TransactionalLockInvocationHandler(final JpaLockingStrategy lock) {
public TransactionalLockInvocationHandler(final JpaLockingStrategy lock,
final PlatformTransactionManager txManager) {
jpaLock = lock;
this.txManager = txManager;
}

public JpaLockingStrategy getLock() {
Expand Down Expand Up @@ -285,9 +290,9 @@ public Object doInTransaction(final TransactionStatus status) {

}

class Locker implements Callable<Boolean> {

private LockingStrategy lock;
private static class Locker implements Callable<Boolean> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final LockingStrategy lock;

public Locker(final LockingStrategy l) {
lock = l;
Expand All @@ -307,10 +312,9 @@ public Boolean call() throws Exception {
}
}


class Releaser implements Callable<Boolean> {

private LockingStrategy lock;
private static class Releaser implements Callable<Boolean> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final LockingStrategy lock;

public Releaser(final LockingStrategy l) {
lock = l;
Expand Down
6 changes: 6 additions & 0 deletions checkstyle-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ Checkstyle configuration based on Sun's conventions, compliant with CAS coding c
<property name="format" value="\(\w+\)\w+"/>
<property name="message" value="There are no spaces after cast."/>
</module>
<module name="RegexpSingleline">
<metadata name="net.sf.eclipsecs.core.comment" value="Non-static inner class"/>
<property name="severity" value="error"/>
<property name="format" value="\s+(private|public)*\s+(abstract\s)*class\s+\w+"/>
<property name="message" value="Non-static inner classes are a security compromise. Consider statics instead"/>
</module>
<module name="RegexpSingleline">
<metadata name="net.sf.eclipsecs.core.comment" value="Missing @since tag"/>
<property name="severity" value="error"/>
Expand Down

0 comments on commit ba3c069

Please sign in to comment.