List of usage examples for org.apache.shiro.env DefaultEnvironment DefaultEnvironment
public DefaultEnvironment()
From source file:org.apache.activemq.shiro.authc.AuthenticationFilterTest.java
License:Apache License
@Test public void testRemoveAuthenticationWithLogoutThrowable() throws Exception { final boolean[] invoked = new boolean[1]; Broker broker = new BrokerPluginSupport() { @Override//from ww w . ja va 2 s . co m public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { invoked[0] = true; } }; DefaultEnvironment env = new DefaultEnvironment(); filter.setNext(broker); filter.setEnvironment(env); Subject subject = new SubjectAdapter() { @Override public void logout() { throw new RuntimeException("Simulated failure."); } }; ConnectionContext ctx = new ConnectionContext(); ConnectionInfo info = new ConnectionInfo(); SubjectConnectionReference conn = new SubjectConnectionReference(ctx, info, env, subject); SubjectSecurityContext ssc = new SubjectSecurityContext(conn); ctx.setSecurityContext(ssc); filter.removeConnection(ctx, info, null); assertTrue(invoked[0]); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenAlreadyRequired() { Subject subject = new SubjectAdapter() { @Override/*from ww w .ja v a 2 s. c o m*/ public boolean isAuthenticated() { return true; } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertFalse(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenAnonymousAllowedAnonymousSubject() { policy.setAnonymousAccessAllowed(true); Subject subject = new SubjectAdapter() { @Override/*from w ww .j a va 2s. c om*/ public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("anonymous", "iniRealm"); } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertFalse(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenAnonymousAllowedAndNotAnonymousSubject() { policy.setAnonymousAccessAllowed(true); Subject subject = new SubjectAdapter() { @Override/* www. ja va 2 s .co m*/ public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("system", "iniRealm"); } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertFalse(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenSystemConnectionAndSystemSubject() { Subject subject = new SubjectAdapter() { @Override//w w w.ja v a 2s . com public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("system", "iniRealm"); } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertFalse(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenSystemConnectionRequiresAuthentication() { policy.setVmConnectionAuthenticationRequired(true); Subject subject = new SubjectAdapter() { @Override//from www.j av a 2s . c om public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("system", "iniRealm"); } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertTrue(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAuthenticationRequiredWhenSystemConnectionDoesNotRequireAuthenticationAndNotSystemAccount() { Subject subject = new SubjectAdapter() { @Override//from ww w.j a v a2 s . co m public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("foo", "iniRealm"); } }; SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(), new DefaultEnvironment(), subject); assertTrue(policy.isAuthenticationRequired(sc)); }
From source file:org.apache.activemq.shiro.authc.DefaultAuthenticationPolicyTest.java
License:Apache License
@Test public void testIsAssumeIdentityWithSystemConnection() { ConnectionContext ctx = new ConnectionContext(); Connection connection = new Connection() { @Override/*from w w w. jav a 2 s . c o m*/ public Connector getConnector() { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void dispatchSync(Command message) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void dispatchAsync(Command command) { //To change body of implemented methods use File | Settings | File Templates. } @Override public Response service(Command command) { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void serviceException(Throwable error) { //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isSlow() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isBlocked() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isConnected() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isActive() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public int getDispatchQueueSize() { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public ConnectionStatistics getStatistics() { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isManageable() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public String getRemoteAddress() { return "vm://localhost"; } @Override public void serviceExceptionAsync(IOException e) { //To change body of implemented methods use File | Settings | File Templates. } @Override public String getConnectionId() { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isNetworkConnection() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean isFaultTolerantConnection() { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public void updateClient(ConnectionControl control) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void start() throws Exception { //To change body of implemented methods use File | Settings | File Templates. } @Override public void stop() throws Exception { //To change body of implemented methods use File | Settings | File Templates. } @Override public int getActiveTransactionCount() { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public Long getOldestActiveTransactionDuration() { return null; //To change body of implemented methods use File | Settings | File Templates. } }; ctx.setConnection(connection); SubjectConnectionReference sc = new SubjectConnectionReference(ctx, new ConnectionInfo(), new DefaultEnvironment(), new SubjectAdapter()); assertTrue(policy.isAssumeIdentity(sc)); }
From source file:org.apache.activemq.shiro.ConnectionReferenceTest.java
License:Apache License
@Test(expected = IllegalArgumentException.class) public void testNoConnectionContext() { new ConnectionReference(null, new ConnectionInfo(), new DefaultEnvironment()); }
From source file:org.apache.activemq.shiro.ConnectionReferenceTest.java
License:Apache License
@Test(expected = IllegalArgumentException.class) public void testNoConnectionInfo() { new ConnectionReference(new ConnectionContext(), null, new DefaultEnvironment()); }