marioosh.net

mini blog / notes

@PreAuthorize with use Spring Expression Language (SpEL) and service method call

public interface EventRepository extends JpaRepository<Event, Long> {   @PreAuthorize("@securityService.canSave(#event,principal)") Event save(@Param("event") Event event);   }   @Service("securityService") public class SecurityService {   public boolean canSave(Event event, UserDetails principal) { // some logic here } }public interface EventRepository extends JpaRepository<Event, Long> { @PreAuthorize("@securityService.canSave(#event,principal)") Event save(@Param("event") Event event); } @Service("securityService") public class SecurityService { public boolean canSave(Event Read more about @PreAuthorize with use Spring Expression Language (SpEL) and service method call[…]

AsyncPipe example

@Component({ … }) export class TestingComponent implements OnInit { units: any; constructor(private restService:RestService) { } ngOnInit() { this.units = this.restService.getUnits(); } }@Component({ … }) export class TestingComponent implements OnInit { units: any; constructor(private restService:RestService) { } ngOnInit() { this.units = this.restService.getUnits(); } } Template <ng-template #loading>Loading…</ng-template> <div *ngIf="units|async as units; else loading"> <span *ngFor="let unit Read more about AsyncPipe example[…]

async.js – download multiple files from multiple urls to first success

var async = require(’async’);   var files = [’file1′,’file2′,’file3’]; var urls = [’url1′,’url2′,’url3’];   var down = function(url, file, callback) { setTimeout(function(){ var r = Math.random() >= 0.5; console.log(’— end ‘+file+’, ‘+url+’, ‘+r); callback(r); }, 1000); };   async.concat(files, function(file, callback){ async.someSeries(urls, function(url, callback1){ down(url, file, function(isOk){ callback1(null, isOk); }); }, function(err, r){ callback(err, r); Read more about async.js – download multiple files from multiple urls to first success[…]

SSH Tunneling with plink or ssh

To make local port 1234 forwarding to remote hostA port 21: plink -v -C -N -L 1234:hostA:21 user@hostB ssh -L 1234:hostA:21 user@hostB Now You can connect to localhost:1234 to access hostA:21 by tunnel created with hostB. To accept connection from other hosts (not local only): plink -v -C -N -L 0.0.0.0:1234:hostA:21 user@hostB ssh -L 0.0.0.0:1234:hostA:21 user@hostB

HTTPS Redirect with exclude

Example how to redirect to HTTPS, but excluding .well-know/* directory. <VirtualHost *:80> ServerAlias domain.net RedirectMatch 301 ^/((?!\.well-known).*)$ https://domain.net/$1 </VirtualHost><VirtualHost *:80> ServerAlias domain.net RedirectMatch 301 ^/((?!\.well-known).*)$ https://domain.net/$1 </VirtualHost>