当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationUtil类代码示例

本文整理汇总了Java中ca.nrc.cadc.auth.AuthenticationUtil的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationUtil类的具体用法?Java AuthenticationUtil怎么用?Java AuthenticationUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationUtil类属于ca.nrc.cadc.auth包,在下文中一共展示了AuthenticationUtil类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetObservationListStsci

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Test
public void testGetObservationListStsci() {
    try {
        Subject s = AuthenticationUtil.getAnonSubject();
        Subject.doAs(s, new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                RepoClient repoC = new RepoClient(URI.create("ivo://mast.stsci.edu/caom2repo"), 8);

                List<ObservationState> list = repoC.getObservationList("HST", null, null, 5);
                Assert.assertEquals(list.size(), 6);

                return null;
            }
        });
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        Assert.fail("unexpected exception: " + unexpected);
    }
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:22,代码来源:RepoClientTest.java

示例2: testGetObservationListDenied

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Test
public void testGetObservationListDenied() {
    try {
        Subject s = AuthenticationUtil.getAnonSubject();
        Subject.doAs(s, new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                RepoClient repoC = new RepoClient(URI.create("ivo://cadc.nrc.ca/caom2repo"), 8);

                List<ObservationState> list = repoC.getObservationList("IRIS", null, null, 5);
                Assert.fail("expected exception, got results");

                return null;
            }
        });
    } catch (AccessControlException expected) {
        log.info("caught expected exception: " + expected);
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        Assert.fail("unexpected exception: " + unexpected);
    }
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:24,代码来源:RepoClientTest.java

示例3: testGet

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Test
public void testGet() {
    try {
        Subject s = AuthenticationUtil.getSubject(new NetrcAuthenticator(true));
        Subject.doAs(s, new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                RepoClient repoC = new RepoClient(URI.create("ivo://cadc.nrc.ca/caom2repo"), 8);

                ObservationResponse wr = repoC.get(new ObservationURI("IRIS", "f001h000"));
                Assert.assertNotNull(wr.observation);
                Assert.assertEquals(wr.observation.getID().toString(), "00000000-0000-0000-897c-013ac26a8f32");

                return null;
            }
        });
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        Assert.fail("unexpected exception: " + unexpected);
    }
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:23,代码来源:RepoClientTest.java

示例4: testGetObservationList

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Test
public void testGetObservationList() {
    try {
        Subject s = AuthenticationUtil.getSubject(new NetrcAuthenticator(true));
        Subject.doAs(s, new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                RepoClient repoC = new RepoClient(URI.create("ivo://cadc.nrc.ca/caom2repo"), 8);

                List<ObservationState> list = repoC.getObservationList("IRIS", null, null, 5);
                Assert.assertEquals(list.size(), 6);
                // Assert.assertEquals(URI.create("caom:IRIS/f001h000"),
                // list.get(0).getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f002h000"),
                // list.get(1).getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f003h000"),
                // list.get(2).getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f004h000"),
                // list.get(3).getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f005h000"),
                // list.get(4).getURI().getURI());

                return null;
            }
        });
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        Assert.fail("unexpected exception: " + unexpected);
    }
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:32,代码来源:RepoClientTest.java

示例5: testGetList

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Test
public void testGetList() {
    try {
        Subject s = AuthenticationUtil.getSubject(new NetrcAuthenticator(true));
        Subject.doAs(s, new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                RepoClient repoC = new RepoClient(URI.create("ivo://cadc.nrc.ca/caom2repo"), 8);

                List<ObservationResponse> list = repoC.getList("IRIS", null, null, 5);
                Assert.assertEquals(list.size(), 6);
                // Assert.assertEquals(URI.create("caom:IRIS/f001h000"),
                // list.get(0).getObservation().getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f002h000"),
                // list.get(1).getObservation().getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f003h000"),
                // list.get(2).getObservation().getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f004h000"),
                // list.get(3).getObservation().getURI().getURI());
                // Assert.assertEquals(URI.create("caom:IRIS/f005h000"),
                // list.get(4).getObservation().getURI().getURI());

                return null;
            }
        });
    } catch (Exception unexpected) {
        log.error("unexpected exception", unexpected);
        Assert.fail("unexpected exception: " + unexpected);
    }
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:32,代码来源:RepoClientTest.java

示例6: init

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
private void init() {
    Subject s = AuthenticationUtil.getCurrentSubject();
    AuthMethod meth = AuthenticationUtil.getAuthMethodFromCredentials(s);
    if (meth == null) {
        meth = AuthMethod.ANON;
    }
    this.baseServiceURL = rc.getServiceURL(this.resourceID, Standards.CAOM2REPO_OBS_23, meth);
    if (baseServiceURL == null) {
        throw new RuntimeException("not found: " + resourceID + " + " + Standards.CAOM2REPO_OBS_23 + " + " + meth);
    }
    log.debug("observation list URL: " + baseServiceURL.toString());
    log.debug("AuthMethod:  " + meth);
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:14,代码来源:RepoClient.java

示例7: initDel

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
private void initDel() {
    Subject s = AuthenticationUtil.getCurrentSubject();
    AuthMethod meth = AuthenticationUtil.getAuthMethodFromCredentials(s);
    if (meth == null) {
        meth = AuthMethod.ANON;
    }
    this.baseDeletionURL = rc.getServiceURL(resourceID, Standards.CAOM2REPO_DEL_23, meth);
    if (baseDeletionURL == null) {
        throw new RuntimeException("not found: " + resourceID + " + " + Standards.CAOM2REPO_DEL_23 + " + " + meth);
    }
    log.debug("deletion list URL: " + baseDeletionURL.toString());
    log.debug("AuthMethod:  " + meth);
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:14,代码来源:RepoClient.java

示例8: get

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
public ObservationResponse get(ObservationURI uri) {
    init();
    if (uri == null) {
        throw new IllegalArgumentException("uri cannot be null");
    }

    ObservationState os = new ObservationState(uri);

    // see comment above in getList
    Subject subjectForWorkerThread = AuthenticationUtil.getCurrentSubject();
    Worker wt = new Worker(os, subjectForWorkerThread, baseServiceURL.toExternalForm());
    return wt.getObservation();
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:14,代码来源:RepoClient.java

示例9: toURL

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Override
public URL toURL(URI uri) {
    if (!SCHEME.equals(uri.getScheme())) {
        throw new IllegalArgumentException("invalid scheme in " + uri);
    }

    try {
        Subject subject = AuthenticationUtil.getCurrentSubject();
        AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(subject);
        if (authMethod == null) {
            authMethod = AuthMethod.ANON;
        }
        RegistryClient rc = new RegistryClient();
        Capabilities caps = rc.getCapabilities(DATA_RESOURCE_ID);
        Capability dataCap = caps.findCapability(Standards.DATA_10);
        URI securityMethod = Standards.getSecurityMethod(authMethod);
        Interface ifc = dataCap.findInterface(securityMethod);
        if (ifc == null) {
            throw new IllegalArgumentException("No interface for security method " + securityMethod);
        }
        String baseDataURL = ifc.getAccessURL().getURL().toString();
        URL url = new URL(baseDataURL + "/MAST/" + uri.getSchemeSpecificPart());
        log.debug(uri + " --> " + url);
        return url;
    } catch (MalformedURLException ex) {
        throw new RuntimeException("BUG", ex);
    } catch (Throwable t) {
        String message = "Failed to convert to data URL";
        throw new RuntimeException(message, t);
    }
}
 
开发者ID:opencadc,项目名称:caom2,代码行数:32,代码来源:CadcMastResolver.java

示例10: toURL

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
@Override
public URL toURL(URI uri) {
    if (!SCHEME.equals(uri.getScheme())) {
        throw new IllegalArgumentException("invalid scheme in " + uri);
    }

    try {
        String path = getPath(uri);
        
        // check if authMethod has been set
        AuthMethod am = this.authMethod;
        if (am == null) {
            am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject());
        }
        if (am == null) {
            am = AuthMethod.ANON;
        }
        
        RegistryClient rc = new RegistryClient();
        URL serviceURL = rc.getServiceURL(new URI(DATA_URI), Standards.DATA_10, am);
        URL url = this.toURL(serviceURL, path);
        log.debug(uri + " --> " + url);
        return url;
    } catch (MalformedURLException ex) {
        throw new RuntimeException("BUG", ex);
    } catch (URISyntaxException bug) {
        throw new RuntimeException("BUG - failed to create data web service URI", bug);
    }
}
 
开发者ID:opencadc,项目名称:caom2,代码行数:30,代码来源:AdResolver.java

示例11: getList

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
public List<ObservationResponse> getList(String collection, Date startDate, Date end, Integer numberOfObservations)
        throws InterruptedException, ExecutionException {
    init();

    // startDate = null;
    // end = df.parse("2017-06-20T09:03:15.360");
    List<ObservationResponse> list = new ArrayList<>();

    List<ObservationState> stateList = getObservationList(collection, startDate, end, numberOfObservations);

    // Create tasks for each file
    List<Callable<ObservationResponse>> tasks = new ArrayList<>();

    // the current subject usually gets propagated into a thread pool, but
    // gets attached
    // when the thread is created so we explicitly pass it it and do another
    // Subject.doAs in
    // case
    // thread pool management is changed
    Subject subjectForWorkerThread = AuthenticationUtil.getCurrentSubject();
    for (ObservationState os : stateList) {
        tasks.add(new Worker(os, subjectForWorkerThread, baseServiceURL.toExternalForm()));
    }

    ExecutorService taskExecutor = null;
    try {
        // Run tasks in a fixed thread pool
        taskExecutor = Executors.newFixedThreadPool(nthreads);
        List<Future<ObservationResponse>> futures;

        futures = taskExecutor.invokeAll(tasks);

        for (Future<ObservationResponse> f : futures) {
            ObservationResponse res = null;
            res = f.get();

            if (f.isDone()) {
                list.add(res);
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        log.error("Error when executing thread in ThreadPool: " + e.getMessage() + " caused by: " + e.getCause().toString());
        throw e;
    } finally {
        if (taskExecutor != null) {
            taskExecutor.shutdown();
        }
    }

    return list;
}
 
开发者ID:opencadc,项目名称:caom2db,代码行数:52,代码来源:RepoClient.java

示例12: createURL

import ca.nrc.cadc.auth.AuthenticationUtil; //导入依赖的package包/类
protected String createURL(URI uri) {
    // Temporary: because the VOSpace client doesn't support
    // cutouts through document posting, create cutout urls
    // using synctrans
    try {
        // check if authMethod has been set
        AuthMethod am = this.authMethod;
        if (am == null) {
            am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject());
        }
        if (am == null) {
            am = AuthMethod.ANON;
        }
        
        URI vuri = getVOSURI(uri);
        RegistryClient registryClient = new RegistryClient();
        URL baseURL = registryClient.getServiceURL(getServiceURI(vuri), Standards.VOSPACE_SYNC_21, am);

        String scheme = baseURL.getProtocol();
        String protocol = null;
        if (scheme.equalsIgnoreCase("http")) {
            protocol = PROTOCOL_HTTP_GET;
        } else {
            protocol = PROTOCOL_HTTPS_GET;
        }

        StringBuilder query = new StringBuilder();
        query.append(baseURL);

        query.append("?");
        query.append("TARGET=").append(NetUtil.encode(vuri.toString()));
        query.append("&");
        query.append("DIRECTION=").append(NetUtil.encode(pullFromVoSpaceValue));
        query.append("&");
        query.append("PROTOCOL=").append(NetUtil.encode(protocol));

        return query.toString();
    } catch (Throwable t) {
        throw new RuntimeException("failed to convert " + uri, t);
    }
}
 
开发者ID:opencadc,项目名称:caom2,代码行数:42,代码来源:VOSpaceResolver.java


注:本文中的ca.nrc.cadc.auth.AuthenticationUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。