List of usage examples for org.springframework.util LinkedMultiValueMap getFirst
@Override
@Nullable
public V getFirst(K key)
From source file:io.isoft.reg.controller.HomeController.java
/** * Accepts a POST request with an Map message parameter, and creates a new Message object from the Map parameters. * @param map serialized LinkedMultiValueMap<String, String> object * @return a string with the result of the POST *///from w ww . jav a 2 s .c o m @RequestMapping(value = "sendmessagemap", method = RequestMethod.POST) public @ResponseBody String sendMessageMap(@RequestBody LinkedMultiValueMap<String, String> map) { Message message = new Message(); try { message.setId(Integer.parseInt(map.getFirst("id"))); } catch (NumberFormatException e) { message.setId(0); } message.setSubject(map.getFirst("subject")); message.setText(map.getFirst("text")); logger.info("Map message: " + message.toString()); return "Map message received! Your message: " + message.toString(); }
From source file:com.apress.prospringintegration.web.MultipartReceiver.java
@ServiceActivator public void handleMultipartRequest(LinkedMultiValueMap<String, Object> multipartRequest) { System.out.println("Received multipart request: " + multipartRequest); for (String elementName : multipartRequest.keySet()) { if (elementName.equals("name")) { LinkedList value = (LinkedList) multipartRequest.get("name"); String[] multiValues = (String[]) value.get(0); for (String name : multiValues) { System.out.println("Name: " + name); }//from w w w . j av a 2 s . co m } else if (elementName.equals("picture")) { System.out.println("Picture as UploadedMultipartFile: " + ((UploadedMultipartFile) multipartRequest.getFirst("picture")).getOriginalFilename()); } } }
From source file:org.slc.sli.api.resources.security.SamlFederationResource.java
/** * Authenticate SSO user./* ww w .ja v a2s . c om*/ * * @param attributes - SAML assertion attributes * @param realm - User's realm * @param targetEdOrg - Target edOrg name * @param inResponseTo - Assertion recipient * @param session - User session * @param requestUri - Request URI * * @return - SAML response from API */ protected Response authenticateUser(LinkedMultiValueMap<String, String> rawAttributes, Entity realm, String targetEdOrg, String inResponseTo, Entity session, URI requestUri) { // Apply attribute transforms. LinkedMultiValueMap<String, String> attributes = transformer.apply(realm, rawAttributes); String tenant = null; String sandboxTenant = null; // For developers coming from developer realm. String realmTenant = (String) realm.getBody().get("tenantId"); String samlTenant = attributes.getFirst("tenant"); Boolean isAdminRealm = (Boolean) realm.getBody().get("admin"); isAdminRealm = (isAdminRealm != null) ? isAdminRealm : Boolean.FALSE; Boolean isDevRealm = (Boolean) realm.getBody().get("developer"); isDevRealm = (isDevRealm != null) ? isDevRealm : Boolean.FALSE; if (isAdminRealm && sandboxEnabled) { // Sandbox mode using the SimpleIDP. // Reset isAdminRealm based on the value of the saml isAdmin attribute, since this same realm is used for impersonation and admin logins. isAdminRealm = Boolean.valueOf(attributes.getFirst("isAdmin")); // Accept the tenantId from the Sandbox-IDP, or if none then it's an admin user. if (isAdminRealm) { tenant = null; // Operator admin. } else { // Impersonation login; require tenant in the saml. if (samlTenant != null) { tenant = samlTenant; } else { LOG.error( "Attempted login by a user in sandbox mode but no tenant was specified in the saml message."); throw new APIAccessDeniedException("Invalid user configuration.", (String) realm.getBody().get("edOrg")); } } } else if (isAdminRealm) { // Prod mode, admin login. tenant = null; } else if (isDevRealm) { // Prod mode, developer login. tenant = null; sandboxTenant = samlTenant; samlTenant = null; } else { // Regular IDP login. tenant = realmTenant; } SLIPrincipal principal = createPrincipal(isAdminRealm, tenant, attributes, isDevRealm, targetEdOrg, realm, samlTenant, sandboxTenant); Map<String, Object> appSession = sessionManager.getAppSession(inResponseTo, session); String authorizationCode = (String) ((Map<String, Object>) appSession.get("code")).get("value"); auditSuccessfulLogin(principal, session, requestUri, authorizationCode, realm, appSession, tenant); return getLoginResponse(appSession, authorizationCode, requestUri, session.getEntityId()); }
From source file:org.slc.sli.api.resources.security.SamlFederationResource.java
/** * Create an SLIPrincipal instance for the user's login session. * * @param isAdminRealm - Indicates if user is using admin realm or not * @param tenant - User's tenant ID/* w w w. ja v a 2 s.c o m*/ * @param attributes - SAML assertion attributes * @param isDevRealm - Indicates if user is using developer realm or not * @param targetEdOrg - Target edOrg name * @param realm - User's realm * @param samlTenant - User's SAML tenant ID * @param sandboxTenant - User's sandbox tenant ID * * @return - Newly created SLIPrincipal instance */ protected SLIPrincipal createPrincipal(boolean isAdminRealm, String tenant, LinkedMultiValueMap<String, String> attributes, boolean isDevRealm, String targetEdOrg, Entity realm, String samlTenant, String sandboxTenant) { LOG.debug("Authenticating user is an admin: " + isAdminRealm); SLIPrincipal principal = users.locate(tenant, attributes.getFirst("userId"), attributes.getFirst("userType")); String userName = getUserNameFromEntity(principal.getEntity()); if (userName != null) { principal.setName(userName); } else { if (isAdminRealm || isDevRealm) { principal.setFirstName(attributes.getFirst("givenName")); principal.setLastName(attributes.getFirst("sn")); principal.setVendor(attributes.getFirst("vendor")); principal.setEmail(attributes.getFirst("mail")); } principal.setName(attributes.getFirst("userName")); } // Cache realm edOrg for security events. principal.setRealmEdOrg(targetEdOrg); principal.setRealm(realm.getEntityId()); principal.setEdOrg(attributes.getFirst("edOrg")); principal.setAdminRealm(attributes.getFirst("edOrg")); if (SLIPrincipal.NULL_ENTITY_ID.equals(principal.getEntity().getEntityId()) && !(isAdminRealm || isDevRealm)) { // If we couldn't find an Entity for the user and this isn't an admin realm, then we have no valid user. throw new APIAccessDeniedException("Invalid user.", realm); } if (!(isAdminRealm || isDevRealm) && !realmHelper.isUserAllowedLoginToRealm(principal.getEntity(), realm)) { throw new APIAccessDeniedException("User is not associated with realm.", realm); } setPrincipalRoles(principal, attributes, realm, tenant, isAdminRealm, isDevRealm); if (samlTenant != null) { principal.setTenantId(samlTenant); TenantContext.setTenantId(samlTenant); TenantContext.setIsSystemCall(false); NeutralQuery idQuery = new NeutralQuery(); idQuery.addCriteria(new NeutralCriteria("stateOrganizationId", NeutralCriteria.OPERATOR_EQUAL, principal.getEdOrg())); Entity edOrg = repo.findOne(EntityNames.EDUCATION_ORGANIZATION, idQuery); if (edOrg != null) { principal.setEdOrgId(edOrg.getEntityId()); } else { LOG.debug("Failed to find edOrg with stateOrganizationID {} and tenantId {}", principal.getEdOrg(), principal.getTenantId()); } } if ((sandboxTenant != null) && isDevRealm) { principal.setSandboxTenant(sandboxTenant); } return principal; }
From source file:org.springframework.integration.samples.multipart.MultipartReceiver.java
@SuppressWarnings("rawtypes") public void receive(LinkedMultiValueMap<String, Object> multipartRequest) { logger.info("Successfully received multipart request: " + multipartRequest); for (String elementName : multipartRequest.keySet()) { if (elementName.equals("company")) { LinkedList value = (LinkedList) multipartRequest.get("company"); String[] multiValues = (String[]) value.get(0); for (String companyName : multiValues) { logger.info(elementName + " - " + companyName); }/*from w ww . j a va2 s. c om*/ } else if (elementName.equals("company-logo")) { logger.info(elementName + " - as UploadedMultipartFile: " + ((UploadedMultipartFile) multipartRequest.getFirst("company-logo")) .getOriginalFilename()); } } }