@Before public void setUp() throws Exception { logger = new ConsoleAuditLogger(); ace = mock(AuditableAccessControlEntry.class); console = System.out; System.setOut(new PrintStream(bytes)); }
@Test public void nonAuditableAceIsIgnored() { AccessControlEntry ace = mock(AccessControlEntry.class); logger.logIfNeeded(true, ace); assertThat(bytes.size()).isZero(); }
@Before public void setup() { myCache = new EhCacheBasedAclCache(cache, new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_USER"))); ObjectIdentity identity = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(100)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); acl = new AclImpl(identity, Long.valueOf(1), aclAuthorizationStrategy, new ConsoleAuditLogger()); }
@Test public void failureIsntLoggedIfAceDoesntRequireFailureAudit() throws Exception { when(ace.isAuditFailure()).thenReturn(false); logger.logIfNeeded(false, ace); assertThat(bytes.size()).isZero(); }
protected EhCacheBasedAclCache aclCache() { return new EhCacheBasedAclCache(getCache(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_USER"))); }
@Test public void successIsLoggedIfAceRequiresSuccessAudit() throws Exception { when(ace.isAuditSuccess()).thenReturn(true); logger.logIfNeeded(true, ace); assertThat(bytes.toString()).startsWith("GRANTED due to ACE"); }
@Test(expected = IllegalArgumentException.class) public void constructorRejectsNullParameters() throws Exception { new EhCacheBasedAclCache(null, new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger()), new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_USER"))); }
@Test public void successIsNotLoggedIfAceDoesntRequireSuccessAudit() throws Exception { when(ace.isAuditSuccess()).thenReturn(false); logger.logIfNeeded(true, ace); assertThat(bytes.size()).isZero(); }
@Test public void putInCacheAclWithParent() throws Exception { Authentication auth = new TestingAuthenticationToken("user", "password", "ROLE_GENERAL"); auth.setAuthenticated(true); SecurityContextHolder.getContext().setAuthentication(auth); ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2)); AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl( new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger()); acl.setParent(parentAcl); myCache.putInCache(acl); verify(cache, times(4)).put(element.capture()); List<Element> allValues = element.getAllValues(); assertThat(allValues.get(0).getKey()).isEqualTo(parentAcl.getObjectIdentity()); assertThat(allValues.get(0).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(1).getKey()).isEqualTo(parentAcl.getId()); assertThat(allValues.get(1).getObjectValue()).isEqualTo(parentAcl); assertThat(allValues.get(2).getKey()).isEqualTo(acl.getObjectIdentity()); assertThat(allValues.get(2).getObjectValue()).isEqualTo(acl); assertThat(allValues.get(3).getKey()).isEqualTo(acl.getId()); assertThat(allValues.get(3).getObjectValue()).isEqualTo(acl); }
@Test public void failureIsLoggedIfAceRequiresFailureAudit() throws Exception { when(ace.isAuditFailure()).thenReturn(true); logger.logIfNeeded(false, ace); assertThat(bytes.toString()).startsWith("DENIED due to ACE"); } }
@Before public void initializeBeans() { strategy = new BasicLookupStrategy(getDataSource(), aclCache(), aclAuthStrategy(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger())); strategy.setPermissionFactory(new DefaultPermissionFactory()); }
new ConsoleAuditLogger()); "ROLE_TWO"), new SimpleGrantedAuthority("ROLE_THREE")); Acl acl2 = new AclImpl(identity, new Long(1), aclAuthorizationStrategy2, new ConsoleAuditLogger());
new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); AuditLogger auditLogger = new ConsoleAuditLogger(); aclAuthorizationStrategy, new ConsoleAuditLogger());
@Before public void initializeBeans() { super.initializeBeans(); uuidEnabledStrategy = new BasicLookupStrategy(getDataSource(), aclCache(), aclAuthStrategy(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger())); uuidEnabledStrategy.setPermissionFactory(new DefaultPermissionFactory()); uuidEnabledStrategy.setAclClassIdSupported(true); uuidEnabledStrategy.setConversionService(new DefaultConversionService()); }
new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority( "ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL")); AuditLogger auditLogger = new ConsoleAuditLogger();
new ConsoleAuditLogger()); parentAcl.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(auth), true); MutableAcl childAcl = new AclImpl(identity, 2, aclAuthorizationStrategy, new ConsoleAuditLogger()); new ConsoleAuditLogger()); parentAcl = new AclImpl(identity, 1, aclAuthorizationStrategy, new ConsoleAuditLogger()); rootParentAcl.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(auth), true);
new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()), null, null, false, new PrincipalSid(auth)); try {
aclAuthorizationStrategy, new ConsoleAuditLogger()); aclFirstDeny.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(auth), false); aclAuthorizationStrategy, new ConsoleAuditLogger()); aclFirstAllow.insertAce(0, BasePermission.ADMINISTRATION, new PrincipalSid(auth), true); aclAuthorizationStrategy, new ConsoleAuditLogger()); try { aclAuthorizationStrategy.securityCheck(aclNoACE,
@Bean AuditLogger createAuditLogger() { return new ConsoleAuditLogger(); }
@Bean public PermissionGrantingStrategy permissionGrantingStrategy() { return new DefaultPermissionGrantingStrategy( new ConsoleAuditLogger() ); }