List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:de.uniba.wiai.kinf.pw.projects.lillytab.reasoner.ConsistencyInfo.java
public void addCulprits(final IABoxNode<I, L, K, R> node, final Collection<? extends IDLTerm<I, L, K, R>> culprits) { final IABox<I, L, K, R> abox = node.getABox(); final TermEntryFactory<I, L, K, R> termEntryFactory = abox.getTermEntryFactory(); final Collection<TermEntry<I, L, K, R>> culpritEntries = ExtractorCollection.decorate(culprits, new Transformer<IDLTerm<I, L, K, R>, TermEntry<I, L, K, R>>() { @Override//from w ww . j a v a 2 s .c o m public TermEntry<I, L, K, R> transform(IDLTerm<I, L, K, R> input) { return termEntryFactory.getEntry(node, input); } }); addCulpritEntries(abox, Collections.singleton(culpritEntries)); }
From source file:net.shibboleth.idp.oidc.client.userinfo.authn.SpringSecurityAuthenticationTokenFactory.java
/** * Build authentication authentication./*from ww w. jav a 2 s .c o m*/ * * @param profileRequestContext the profile request context * @return the authentication */ public static Authentication buildAuthentication(final ProfileRequestContext profileRequestContext) { final SubjectContext principal = profileRequestContext.getSubcontext(SubjectContext.class); if (principal == null || principal.getPrincipalName() == null) { throw new OIDCException("No SubjectContext found in the profile request context"); } /** * Grab the authentication context class ref and classify it as an authority to be used later * by custom token services to generate acr and amr claims. * * MitreID connect can only work with SimpleGrantedAuthority. So here we are creating specific authority * instances first and then converting them to SimpleGrantedAuthority. The role could be parsed later to * locate and reconstruct the actual instance. */ final Set<GrantedAuthority> authorities = new LinkedHashSet<>(); authorities.add(new SimpleGrantedAuthority(OIDCConstants.ROLE_USER)); final AuthenticationContext authCtx = profileRequestContext.getSubcontext(AuthenticationContext.class); if (authCtx != null) { LOG.debug("Found an authentication context in the profile request context"); final RequestedPrincipalContext principalContext = authCtx .getSubcontext(RequestedPrincipalContext.class); if (principalContext != null && principalContext.getMatchingPrincipal() != null) { LOG.debug("Found requested principal context context with matching principal {}", principalContext.getMatchingPrincipal().getName()); final AuthenticationClassRefAuthority authority = new AuthenticationClassRefAuthority( principalContext.getMatchingPrincipal().getName()); LOG.debug("Adding authority {}", authority.getAuthority()); authorities.add(new SimpleGrantedAuthority(authority.toString())); } if (authCtx.getAuthenticationResult() != null) { final AuthenticationMethodRefAuthority authority = new AuthenticationMethodRefAuthority( authCtx.getAuthenticationResult().getAuthenticationFlowId()); LOG.debug("Adding authority {}", authority.getAuthority()); authorities.add(new SimpleGrantedAuthority(authority.toString())); } } /** * Note that Spring Security loses the details object when it attempts to grab onto the authentication * object that is combined, when codes are asking to create access tokens. */ final User user = new User(principal.getPrincipalName(), UUID.randomUUID().toString(), Collections.singleton(new SimpleGrantedAuthority(OIDCConstants.ROLE_USER))); LOG.debug("Created user details object for {} with authorities {}", user.getUsername(), user.getAuthorities()); final SpringSecurityAuthenticationToken authenticationToken = new SpringSecurityAuthenticationToken( profileRequestContext, authorities); LOG.debug("Final authentication token authorities are {}", authorities); authenticationToken.setAuthenticated(true); authenticationToken.setDetails(user); return authenticationToken; }
From source file:de.escalon.hypermedia.spring.sample.test.DummyEventControllerExposed.java
@RequestMapping("/query") public HttpEntity<Resources<FooResource>> findList(@Input(include = { "offset", "size" }) Pageable pageable, @RequestParam(required = false) Integer foo1, @RequestParam(required = false) Integer foo2) { FooResource fooResource = new FooResource(pageable); fooResource.add(//w ww .jav a 2 s .c om AffordanceBuilder.linkTo(methodOn(this.getClass()).findList(null, null, null)).withRel("template")); return new HttpEntity<Resources<FooResource>>( new Resources<FooResource>(Collections.singleton(fooResource))); }
From source file:com.googlecode.jmxtrans.model.output.kafka.DefaultResultSerializer.java
@Nonnull @Override//from w w w . ja va2 s . com public Collection<String> serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (isNumeric(value)) { return Collections.singleton(createJsonMessage(server, query, result, result.getValuePath(), value)); } else { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return Collections.emptyList(); } }
From source file:org.jasig.services.persondir.support.rule.StringFormatAttributeRule.java
@Override public Set<IPersonAttributes> evaluate(final Map<String, List<Object>> userInfo) { // Assertions. if (userInfo == null) { final String msg = "Argument 'userInfo' cannot be null."; throw new IllegalArgumentException(msg); }/*w ww . j a v a 2 s. c o m*/ if (!appliesTo(userInfo)) { final String msg = "May not evaluate. This rule does not apply."; throw new IllegalArgumentException(msg); } final Object[] args = new Object[formatArguments.size()]; for (int i = 0; i < formatArguments.size(); i++) { final String key = formatArguments.get(i); final List<Object> values = userInfo.get(key); args[i] = values.isEmpty() ? null : values.get(0); } final String outputAttributeValue = String.format(this.formatString, args); final Map<String, List<Object>> rslt = new HashMap<String, List<Object>>(); rslt.put(this.outputAttribute, Arrays.asList(new Object[] { outputAttributeValue })); final String username = this.usernameAttributeProvider.getUsernameFromQuery(userInfo); final IPersonAttributes person = new NamedPersonImpl(username, rslt); return Collections.singleton(person); }
From source file:ddf.catalog.registry.transformer.RegistryTransformer.java
@Override public Metacard transform(InputStream inputStream, String id) throws IOException, CatalogTransformerException { MetacardImpl metacard;//from w ww. j ava 2 s. c o m try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(1000000)) { try { IOUtils.copy(inputStream, fileBackedOutputStream); } catch (IOException e) { throw new CatalogTransformerException( "Unable to transform from CSW RIM Service Record to Metacard. Error reading input stream.", e); } finally { IOUtils.closeQuietly(inputStream); } try (InputStream inputStreamCopy = fileBackedOutputStream.asByteSource().openStream()) { metacard = (MetacardImpl) unmarshal(inputStreamCopy); } catch (ParserException e) { throw new CatalogTransformerException( "Unable to transform from CSW RIM Service Record to Metacard. Parser exception caught", e); } catch (RegistryConversionException e) { throw new CatalogTransformerException( "Unable to transform from CSW RIM Service Record to Metacard. Conversion exception caught", e); } if (metacard == null) { throw new CatalogTransformerException( "Unable to transform from CSW RIM Service Record to Metacard."); } else if (StringUtils.isNotEmpty(id)) { metacard.setAttribute(Metacard.ID, id); } String xml = CharStreams .toString(fileBackedOutputStream.asByteSource().asCharSource(Charsets.UTF_8).openStream()); metacard.setAttribute(Metacard.METADATA, xml); metacard.setTags(Collections.singleton(RegistryConstants.REGISTRY_TAG)); } catch (IOException e) { throw new CatalogTransformerException( "Unable to transform from CSW RIM Service Record to Metacard. Error using file-backed stream.", e); } return metacard; }
From source file:ca.uhn.fhir.rest.method.SummaryEnumParameter.java
private static Set<SummaryEnum> toCollectionOrNull(SummaryEnum theFromCode) { if (theFromCode == null) { return null; }// w w w . j a v a 2 s . c om return Collections.singleton(theFromCode); }
From source file:io.klerch.alexa.state.handler.AlexaSessionStateHandler.java
/** * {@inheritDoc}// w w w . j a va 2 s. c om */ @Override public void writeValue(final AlexaStateObject stateObject) throws AlexaStateException { Validate.notNull(stateObject, "State object must not be null."); writeValues(Collections.singleton(stateObject)); }
From source file:com.qcadoo.mes.integration.efcSimple.IntegrationEnovaViewHook.java
private Set<Long> getSelectedIdsFromForm(final ViewDefinitionState viewDefinitionState) { FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference("form"); Preconditions.checkState(form.getEntityId() != null, "No record"); return Collections.singleton(form.getEntityId()); }
From source file:com.cloudbees.jenkins.support.impl.AboutJenkins.java
@NonNull @Override/*from w w w .ja va 2 s . c o m*/ public Set<Permission> getRequiredPermissions() { // Was originally READ, but a lot of the details here could be considered sensitive: return Collections.singleton(Jenkins.ADMINISTER); }