Example usage for org.apache.shiro SecurityUtils setSecurityManager

List of usage examples for org.apache.shiro SecurityUtils setSecurityManager

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils setSecurityManager.

Prototype

public static void setSecurityManager(SecurityManager securityManager) 

Source Link

Document

Sets a VM (static) singleton SecurityManager, specifically for transparent use in the #getSubject() getSubject() implementation.

Usage

From source file:org.obm.provisioning.CommonDomainEndPointEnvTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    server.start();//ww  w. j av a2 s .c o m
    serverPort = server.getConnectors()[0].getLocalPort();
    baseUrl = "http://localhost:" + serverPort + ProvisioningService.PROVISIONING_URL_PREFIX;

    SecurityUtils.setSecurityManager(new DefaultWebSecurityManager(realm));
    RestAssured.baseURI = baseUrl + "/" + domain.getUuid().get();
    RestAssured.port = serverPort;
}

From source file:org.obm.provisioning.ProvisioningContextListener.java

License:Open Source License

@Override
public void contextInitialized(ServletContextEvent sce) {
    try {// www.ja  va  2s.co m
        injector = createInjector(sce.getServletContext());
        SecurityManager securityManager = injector.getInstance(SecurityManager.class);
        SecurityUtils.setSecurityManager(securityManager);
    } catch (Exception e) {
        Throwables.propagate(e);
    }
}

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

License:Apache License

private void setupSecurityManager() {
    OpenEngSBSecurityManager openEngSBSecurityManager = new OpenEngSBSecurityManager();
    OpenEngSBShiroAuthenticator authenticator = new OpenEngSBShiroAuthenticator();
    authenticator.setAuthenticator(authManager);
    openEngSBSecurityManager.setAuthenticator(authenticator);
    SecurityUtils.setSecurityManager(openEngSBSecurityManager);
}

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

License:Apache License

public void init() {
    SecurityUtils.setSecurityManager(this);
}

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

License:Apache License

@Before
public void setUp() throws Exception {
    RootSubjectHolder.init();/*from www  . j ava 2s  .c  o m*/
    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.internal.deployer.connector.ConnectorDeployerServiceTest.java

License:Apache License

private void setupSecurityManager() throws AuthenticationException {
    AuthenticationDomain authManager = mock(AuthenticationDomain.class);
    when(authManager.authenticate(anyString(), any(Credentials.class)))
            .thenAnswer(new Answer<Authentication>() {
                @Override//from   w  w  w  . j  a  v  a  2 s.co m
                public Authentication answer(InvocationOnMock invocation) throws Throwable {
                    String username = (String) invocation.getArguments()[0];
                    Credentials credentials = (Credentials) invocation.getArguments()[1];
                    return new Authentication(username, credentials);
                }
            });
    OpenEngSBSecurityManager openEngSBSecurityManager = new OpenEngSBSecurityManager();
    OpenEngSBShiroAuthenticator authenticator = new OpenEngSBShiroAuthenticator();
    authenticator.setAuthenticator(authManager);
    openEngSBSecurityManager.setAuthenticator(authenticator);
    SecurityUtils.setSecurityManager(openEngSBSecurityManager);
}

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//  w  w  w  .j  ava  2s .  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();/*from   w w  w  .  j a v a2  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  w w.  j a v  a2  s  . c  o m*/
        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);

}

From source file:org.openiot.security.client.AccessControlUtilRest.java

License:Open Source License

AccessControlUtilRest(String moduleName, String configDir) {
    String key = null;/*w  w  w  . jav a 2  s. com*/
    String secret = null;

    IniSecurityManagerFactory factory = null;
    if (moduleName != null) {
        if (configDir != null) {
            String iniFilePath = configDir + "/rest-client-" + moduleName + ".ini";
            Path path = Paths.get(iniFilePath);
            if (!Files.exists(path) || Files.isDirectory(path)) {
                logger.warn("The configuration file {} is not found.", iniFilePath);
            } else {
                factory = new IniSecurityManagerFactory("file:" + iniFilePath);
            }
        }
        PropertyManagement props = new PropertyManagement();
        key = props.getProperty("casOauthClient.key." + moduleName, null);
        secret = props.getProperty("casOauthClient.secret." + moduleName, null);
    }
    if (factory == null) {
        logger.info("Falling back to the rest-client.ini in the class path");
        String confFilePath = "classpath:rest-client.ini";
        factory = new IniSecurityManagerFactory(confFilePath);
    }

    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    if (key != null && secret != null) {
        CasOAuthWrapperClientRest bean = (CasOAuthWrapperClientRest) factory.getBeans().get("casOauthClient");
        bean.setKey(key);
        bean.setSecret(secret);
    } else if (moduleName != null) {
        logger.warn(
                "casOauthClient.key.{} or/and casOauthClient.secret.{} is not set in the global properties file",
                moduleName, moduleName);
    }

}