Example usage for org.apache.shiro.authc Authenticator Authenticator

List of usage examples for org.apache.shiro.authc Authenticator Authenticator

Introduction

In this page you can find the example usage for org.apache.shiro.authc Authenticator Authenticator.

Prototype

Authenticator

Source Link

Usage

From source file:org.openengsb.core.security.internal.RootSubjectHolder.java

License:Apache License

public static void init() {
    DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
    defaultSecurityManager.setAuthenticator(new Authenticator() {
        @Override/*w  w w .java 2 s  . c o  m*/
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws AuthenticationException {
            return new SimpleAuthenticationInfo(new Object(), null, "openengsb");
        }
    });
    Subject subject = defaultSecurityManager.createSubject(new DefaultSubjectContext());
    synchronized (rootSubject) {
        rootSubject.set(defaultSecurityManager.login(subject, null));
        rootSubject.notifyAll();
    }
}

From source file:org.openengsb.core.security.MethodInterceptorTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    RootSubjectHolder.init();/*from   ww w  .java 2 s . c  om*/
    DefaultSecurityManager sm = new DefaultSecurityManager();
    sm.setAuthenticator(new Authenticator() {
        @Override
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws AuthenticationException {
            return new SimpleAuthenticationInfo(
                    new SimplePrincipalCollection(authenticationToken.getPrincipal(), "openengsb"),
                    authenticationToken.getCredentials());
        }
    });
    SecurityUtils.setSecurityManager(sm);
    ThreadContext.bind(sm);

    interceptor = new SecurityInterceptor();
    authorizer = mock(AuthorizationDomain.class);
    when(authorizer.checkAccess(eq("admin"), any(MethodInvocation.class))).thenReturn(Access.GRANTED);

    interceptor.setAuthorizer(authorizer);

    service = (DummyService) secure(new DummyServiceImpl("42"));
    service2 = (DummyService) secure(new DummyServiceImpl("21"));
}

From source file:org.openengsb.core.services.MethodInterceptorTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    DefaultSecurityManager sm = new DefaultSecurityManager();
    sm.setAuthenticator(new Authenticator() {
        @Override//from  w  w w  .j ava2  s  .c om
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws AuthenticationException {
            return new SimpleAuthenticationInfo(
                    new SimplePrincipalCollection(authenticationToken.getPrincipal(), "openengsb"),
                    authenticationToken.getCredentials());
        }
    });
    SecurityUtils.setSecurityManager(sm);
    ThreadContext.bind(sm);

    interceptor = new SecurityInterceptor();
    authorizer = mock(AuthorizationDomain.class);
    when(authorizer.checkAccess(eq("admin"), any(MethodInvocation.class))).thenReturn(Access.GRANTED);

    interceptor.setAuthorizer(authorizer);

    service = (DummyService) secure(new DummyServiceImpl("42"));
    service2 = (DummyService) secure(new DummyServiceImpl("21"));
}

From source file:org.openengsb.ports.jms.JMSPortTest.java

License:Apache License

@Before
public void setup() {
    System.setProperty("org.apache.activemq.default.directory.prefix",
            tempFolder.getRoot().getAbsolutePath() + "/");
    setupKeys();/*w  w w  .ja va2 s  .c  o  m*/
    String num = UUID.randomUUID().toString();
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost" + num);
    jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplateFactory = new JMSTemplateFactory() {
        @Override
        public SimpleMessageListenerContainer createMessageListenerContainer() {
            return simpleMessageListenerConainer;
        }

        @Override
        public JmsTemplate createJMSTemplate(DestinationUrl destinationUrl) {
            return jmsTemplate;
        }
    };
    simpleMessageListenerConainer = new SimpleMessageListenerContainer();

    incomingPort = new JMSIncomingPort();
    incomingPort.setFactory(jmsTemplateFactory);
    incomingPort.setConnectionFactory(connectionFactory);
    RequestHandlerImpl requestHandlerImpl = new RequestHandlerImpl();
    requestHandlerImpl.setUtilsService(new DefaultOsgiUtilsService(bundleContext));
    handler = requestHandlerImpl;

    TestInterface mock2 = mock(TestInterface.class);
    registerServiceViaId(mock2, "test", TestInterface.class);
    when(mock2.method(anyString(), anyInt(), any(TestClass.class))).thenReturn(new TestClass("test"));

    Map<String, String> metaData = Maps.newHashMap(ImmutableMap.of("serviceId", "test"));
    MethodCall methodCall = new MethodCall("method", new Object[] { "123", 5, new TestClass("test"), },
            metaData);
    call = new MethodCallMessage(methodCall, "123");
    call.setDestination("host?receive");

    MethodResult result = new MethodResult(new TestClass("test"));
    result.setMetaData(metaData);
    methodReturn = new MethodResultMessage(result, "123");
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(Constants.PROVIDED_CLASSES_KEY, Password.class.getName());
    props.put(Constants.DELEGATION_CONTEXT_KEY,
            org.openengsb.core.api.Constants.DELEGATION_CONTEXT_CREDENTIALS);
    registerService(new ClassProviderImpl(bundle, Sets.newHashSet(Password.class.getName())), props,
            ClassProvider.class);
    DefaultSecurityManager securityManager = new DefaultSecurityManager();
    securityManager.setAuthenticator(new Authenticator() {
        @Override
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws org.apache.shiro.authc.AuthenticationException {
            return new SimpleAuthenticationInfo(authenticationToken.getPrincipal(),
                    authenticationToken.getCredentials(), "openengsb");
        }
    });
    SecurityUtils.setSecurityManager(securityManager);
}

From source file:org.openengsb.ui.admin.xlink.ToolChooserTest.java

License:Apache License

private void startSecurityManager() {
    DefaultSecurityManager sm = new DefaultSecurityManager();
    sm.setAuthenticator(new Authenticator() {
        @Override// w ww .  jav  a2  s. c  om
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws AuthenticationException {
            return new SimpleAuthenticationInfo(
                    new SimplePrincipalCollection(authenticationToken.getPrincipal(), "openengsb"),
                    authenticationToken.getCredentials());
        }
    });
    SecurityUtils.setSecurityManager(sm);
    ThreadContext.bind(sm);

    AuthorizationDomain authorizer = mock(AuthorizationDomain.class);
    when(authorizer.checkAccess(eq("admin"), any(MethodInvocation.class))).thenReturn(Access.GRANTED);

}