org.springframework.mobile.device.Device Java Examples
The following examples show how to use
org.springframework.mobile.device.Device.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _AuthenticationRestController.java From generator-spring-rest-jwt with MIT License | 6 votes |
@RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST) public ResponseEntity<?> createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest, Device device) throws AuthenticationException { // Perform the security final Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); final String token = jwtTokenUtil.generateToken(userDetails, device); // Return the token return ResponseEntity.ok(new JwtAuthenticationResponse(token)); }
Example #2
Source File: AccessSourceDeviceManage.java From bbs with GNU Affero General Public License v3.0 | 6 votes |
/** * 访问设备 * @param request * @return pc:电脑 wap:移动设备 */ public String accessDevices(HttpServletRequest request) { SystemSetting systemSetting = settingService.findSystemSetting_cache(); if(systemSetting.getSupportAccessDevice() != null){ if(systemSetting.getSupportAccessDevice().equals(2)){ return "pc";//电脑端 }else if(systemSetting.getSupportAccessDevice().equals(3)){ return "wap";//移动设备 } } Device device = deviceResolver.resolveDevice(request); if(device.isNormal()){ return "pc";//电脑 }else{ return "wap";//移动设备 } }
Example #3
Source File: MobileAdaptiveController.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@RequestMapping(value={"/hms/desktop", "/hms/mobile","/hms/tablet"}) public String showAdaptive(SitePreference spf, Device device, Model model) { switch(spf){ case MOBILE: model.addAttribute("siteType", "Mobile Version"); return "mobile"; case NORMAL: model.addAttribute("siteType", "Desktop Version"); return "desktop"; case TABLET: model.addAttribute("siteType", "Tablet Version"); return "tablet"; } return "mobile"; }
Example #4
Source File: AuthenticationRestController.java From tour-of-heros-api-security-zerhusen with MIT License | 6 votes |
@RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST) public ResponseEntity<?> createAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest, Device device) throws AuthenticationException { // Perform the security final Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); final String token = jwtTokenUtil.generateToken(userDetails, device); // Return the token return ResponseEntity.ok(new JwtAuthenticationResponse(token)); }
Example #5
Source File: TokenHelper.java From springboot-jwt-starter with MIT License | 6 votes |
public String refreshToken(String token, Device device) { String refreshedToken; Date a = timeProvider.now(); try { final Claims claims = this.getAllClaimsFromToken(token); claims.setIssuedAt(a); refreshedToken = Jwts.builder() .setClaims(claims) .setExpiration(generateExpirationDate(device)) .signWith( SIGNATURE_ALGORITHM, SECRET ) .compact(); } catch (Exception e) { refreshedToken = null; } return refreshedToken; }
Example #6
Source File: AuthController.java From microservices-sample-project with Apache License 2.0 | 6 votes |
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<JwtResponse> createAuthenticationToken( @ModelAttribute JwtAuthenticationDto jwtAuthenticationDto, Device device) throws Exception { // Checking username|email and password Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken( jwtAuthenticationDto.getUsername(), jwtAuthenticationDto.getPassword())); SecurityContextHolder.getContext().setAuthentication(authentication); UserDetails userDetails = userDetailsService.loadUserByUsername(jwtAuthenticationDto.getUsername()); String token = jwtTokenUtil.generateToken(userDetails, device); Date expiration = jwtTokenUtil.getExpirationDateFromToken(token); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); return makeResponse(new JwtResponse(token, dateFormat.format(expiration))); }
Example #7
Source File: AuthenticationController.java From springboot-jwt-starter with MIT License | 6 votes |
@RequestMapping(value = "/login", method = RequestMethod.POST) public ResponseEntity<?> createAuthenticationToken( @RequestBody JwtAuthenticationRequest authenticationRequest, HttpServletResponse response, Device device ) throws AuthenticationException, IOException { // Perform the security final Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); // Inject into security context SecurityContextHolder.getContext().setAuthentication(authentication); // token creation User user = (User)authentication.getPrincipal(); String jws = tokenHelper.generateToken( user.getUsername(), device); int expiresIn = tokenHelper.getExpiredIn(device); // Return the token return ResponseEntity.ok(new UserTokenState(jws, expiresIn)); }
Example #8
Source File: TestJWT.java From xmanager with Apache License 2.0 | 6 votes |
private String getToken(User user){ return jwtTokenUtil.generateToken(user, new Device() { @Override public boolean isNormal() { return false; } @Override public boolean isMobile() { return false; } @Override public boolean isTablet() { return false; } @Override public DevicePlatform getDevicePlatform() { return null; } }); }
Example #9
Source File: AuthenticationController.java From springboot-jwt-starter with MIT License | 6 votes |
@RequestMapping(value = "/refresh", method = RequestMethod.POST) public ResponseEntity<?> refreshAuthenticationToken( HttpServletRequest request, HttpServletResponse response, Principal principal ) { String authToken = tokenHelper.getToken( request ); Device device = deviceProvider.getCurrentDevice(request); if (authToken != null && principal != null) { // TODO check user password last update String refreshedToken = tokenHelper.refreshToken(authToken, device); int expiresIn = tokenHelper.getExpiredIn(device); return ResponseEntity.ok(new UserTokenState(refreshedToken, expiresIn)); } else { UserTokenState userTokenState = new UserTokenState(); return ResponseEntity.accepted().body(userTokenState); } }
Example #10
Source File: LoginAction.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public String execute() throws Exception { Device device = deviceResolver.resolveDevice( ServletActionContext.getRequest() ); ServletActionContext.getResponse().addHeader( "Login-Page", "true" ); if ( device.isMobile() || device.isTablet() ) { return "mobile"; } availableLocales = new ArrayList<>( resourceBundleManager.getAvailableLocales() ); return "standard"; }
Example #11
Source File: AuthenticationController.java From spring-security-mybatis-demo with Apache License 2.0 | 6 votes |
@RequestMapping(value = "${jwt.route.authentication.path}/personal", method = RequestMethod.POST) public ResponseEntity<?> createPersonalAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest, Device device) throws AuthenticationException { authenticationRequest.setUsername(authenticationRequest.getPhone()); // Perform the security Authentication authentication = null; try { authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); } catch (AuthenticationException e) { System.out.println(e.getMessage()); } SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token final UserDetails userDetails = userDetailsService.loadUserByPhone(authenticationRequest.getPhone()); final String token = jwtTokenUtil.generateToken(userDetails, device); // Return the token return ResponseEntity.ok(new JwtAuthenticationResponse(token)); }
Example #12
Source File: AuthenticationController.java From spring-security-mybatis-demo with Apache License 2.0 | 6 votes |
@RequestMapping(value = "${jwt.route.authentication.path}/company", method = RequestMethod.POST) public ResponseEntity<?> createCompanyAuthenticationToken(@RequestBody JwtAuthenticationRequest authenticationRequest, Device device) throws AuthenticationException { authenticationRequest.setUsername(authenticationRequest.getEmail()); // Perform the security Authentication authentication = null; try { authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); } catch (AuthenticationException e) { System.out.println(e.getMessage()); } SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token final UserDetails userDetails = userDetailsService.loadUserByEmail(authenticationRequest.getEmail()); final String token = jwtTokenUtil.generateToken(userDetails, device); // Return the token return ResponseEntity.ok(new JwtAuthenticationResponse(token)); }
Example #13
Source File: JwtTokenUtil.java From tour-of-heros-api-security-zerhusen with MIT License | 5 votes |
public String generateToken(UserDetails userDetails, Device device) { Map<String, Object> claims = new HashMap<>(); claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); claims.put(CLAIM_KEY_AUDIENCE, generateAudience(device)); claims.put(CLAIM_KEY_CREATED, new Date()); return generateToken(claims); }
Example #14
Source File: TokenHelper.java From springboot-jwt-starter with MIT License | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #15
Source File: TokenUtils.java From Cerberus with MIT License | 5 votes |
private String generateAudience(Device device) { String audience = this.AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = this.AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #16
Source File: TokenHelper.java From springboot-jwt-starter with MIT License | 5 votes |
public String generateToken(String username, Device device) { String audience = generateAudience(device); return Jwts.builder() .setIssuer( APP_NAME ) .setSubject(username) .setAudience(audience) .setIssuedAt(timeProvider.now()) .setExpiration(generateExpirationDate(device)) .signWith( SIGNATURE_ALGORITHM, SECRET ) .compact(); }
Example #17
Source File: TokenUtils.java From Cerberus with MIT License | 5 votes |
public String generateToken(UserDetails userDetails, Device device) { Map<String, Object> claims = new HashMap<String, Object>(); claims.put("sub", userDetails.getUsername()); claims.put("audience", this.generateAudience(device)); claims.put("created", this.generateCurrentDate()); return this.generateToken(claims); }
Example #18
Source File: IndexController.java From tutorials with MIT License | 5 votes |
@GetMapping("/") public String greeting(Device device) { String deviceType = "browser"; String platform = "browser"; String viewName = "index"; if (device.isNormal()) { deviceType = "browser"; } else if (device.isMobile()) { deviceType = "mobile"; viewName = "mobile/index"; } else if (device.isTablet()) { deviceType = "tablet"; viewName = "tablet/index"; } platform = device.getDevicePlatform().name(); if (platform.equalsIgnoreCase("UNKNOWN")) { platform = "browser"; } LOGGER.info("Client Device Type: " + deviceType + ", Platform: " + platform); return viewName; }
Example #19
Source File: JwtTokenUtil.java From microservices-sample-project with Apache License 2.0 | 5 votes |
public String generateToken(UserDetails userDetails, Device device) { Map<String, Object> claims = new HashMap<>(); claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); claims.put(CLAIM_KEY_AUDIENCE, generateAudience(device)); claims.put(CLAIM_KEY_CREATED, new Date()); return generateToken(claims); }
Example #20
Source File: JwtTokenUtil.java From microservices-sample-project with Apache License 2.0 | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #21
Source File: _JwtTokenUtil.java From generator-spring-rest-jwt with MIT License | 5 votes |
public String generateToken(UserDetails userDetails, Device device) { Map<String, Object> claims = new HashMap<>(); claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); claims.put(CLAIM_KEY_AUDIENCE, generateAudience(device)); claims.put(CLAIM_KEY_CREATED, new Date()); return generateToken(claims); }
Example #22
Source File: JwtTokenUtil.java From tour-of-heros-api-security-zerhusen with MIT License | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #23
Source File: _JwtTokenUtil.java From generator-spring-rest-jwt with MIT License | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #24
Source File: JwtTokenUtil.java From xmanager with Apache License 2.0 | 5 votes |
public String generateToken(User user, Device device) { Map<String, Object> claims = new HashMap<>(); claims.put(CLAIM_KEY_USERNAME, user.getLoginName()); claims.put(CLAIM_KEY_AUDIENCE, generateAudience(device)); final Date createdDate = timeProvider.now(); claims.put(CLAIM_KEY_CREATED, createdDate); return doGenerateToken(claims); }
Example #25
Source File: JwtTokenUtil.java From spring-security-mybatis-demo with Apache License 2.0 | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #26
Source File: JwtTokenUtil.java From xmanager with Apache License 2.0 | 5 votes |
private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (device.isNormal()) { audience = AUDIENCE_WEB; } else if (device.isTablet()) { audience = AUDIENCE_TABLET; } else if (device.isMobile()) { audience = AUDIENCE_MOBILE; } return audience; }
Example #27
Source File: AuthenticationController.java From spring-security-mybatis-demo with Apache License 2.0 | 4 votes |
@RequestMapping("${jwt.route.authentication.path}/hello") public ResponseEntity<?> hello (@RequestBody JwtAuthenticationRequest authenticationRequest , Device device) { return ResponseEntity.ok("hello"); }
Example #28
Source File: Devices.java From wallride with Apache License 2.0 | 4 votes |
private Device resolveDevice() { return deviceResolver.resolveDevice(((IWebContext) context).getRequest()); }
Example #29
Source File: JwtTokenUtil.java From spring-security-mybatis-demo with Apache License 2.0 | 4 votes |
public String generateToken(UserDetails userDetails, Device device) { Map<String, Object> claims = new HashMap<>(); return doGenerateToken(claims, userDetails.getUsername(), generateAudience(device)); }
Example #30
Source File: MappedRedirectStrategy.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void sendRedirect( HttpServletRequest request, HttpServletResponse response, String url ) throws IOException { // --------------------------------------------------------------------- // Check if redirect should be skipped - for cookie authentication only // --------------------------------------------------------------------- String authOnly = (String) request.getAttribute( PARAM_AUTH_ONLY ); if ( "true".equals( authOnly ) ) { return; } // --------------------------------------------------------------------- // Ignore certain ajax requests // --------------------------------------------------------------------- for ( String key : redirectMap.keySet() ) { if ( url.contains(key) ) { url = url.replaceFirst( key, redirectMap.get( key ) ); } } // --------------------------------------------------------------------- // Redirect to mobile start pages // --------------------------------------------------------------------- Device device = deviceResolver.resolveDevice( request ); if ( (device.isMobile() || device.isTablet()) ) { url = getRootPath( request ) + "/"; } log.debug( "Redirecting to " + url ); super.sendRedirect( request, response, url ); }