Skip to content

Commit

Permalink
0.0.4-beta angular guard fixed to handle user 403
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Vale committed Apr 22, 2018
1 parent e0fe703 commit b2988a6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Login with username *admin* and password *administrator*.
Available tags can be found here: https://hub.docker.com/r/swarmbit/swarmmanager/tags/
* Star swarm manager, this command does not persist data.
```
$ docker run --name swarmmanager -p 3000:3080 -v /var/run/docker.sock:/var/run/docker.sock -d swarmbit/swarmmanager:0.0.3-beta
$ docker run --name swarmmanager -p 3000:3080 -v /var/run/docker.sock:/var/run/docker.sock -d swarmbit/swarmmanager:0.0.4-beta
```

* Start swarm manage with configuration and data directory.
```
$ docker run --name swarmmanager -p 80:3080 -p 443:3443 -e HTTPS=true -e DBPASS=password -v /var/run/docker.sock:/var/run/docker.sock -v /opt/swarmmanager/data:/data -v /opt/swarmmanager/config:/config -d swarmbit/swarmmanager:0.0.3-beta
$ docker run --name swarmmanager -p 80:3080 -p 443:3443 -e HTTPS=true -e DBPASS=password -v /var/run/docker.sock:/var/run/docker.sock -v /opt/swarmmanager/data:/data -v /opt/swarmmanager/config:/config -d swarmbit/swarmmanager:0.0.4-beta
```
* Swarm manager stores data /swarmmanagercontroller/data and reads the configuration from /config.
* Hosts directories can be mounted to persist data and to add configuration to swarm manager.
Expand All @@ -68,7 +68,7 @@ spring.data.mongodb.database=swarmmanager
```
* Run light image
```
$ docker run --name swarmmanagerlight -p 80:3080 -v /var/run/docker.sock:/var/run/docker.sock -v /opt/swarmmanager/config:/config -d swarmbit/swarmmanagerlight:0.0.2-beta
$ docker run --name swarmmanagerlight -p 80:3080 -v /var/run/docker.sock:/var/run/docker.sock -v /opt/swarmmanager/config:/config -d swarmbit/swarmmanagerlight:0.0.4-beta
```

## Project Maintainers
Expand Down
6 changes: 3 additions & 3 deletions mongo/DockerfileSwarmManagerDB
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG DBPASS=swarmmanager
COPY createSwarmManagerDB.js /scripts/createSwarmManagerDB.js
RUN sed -i -e 's/-DBPASS-/'$DBPASS'/g' /scripts/createSwarmManagerDB.js

RUN mkdir /data/swarmmanager
RUN mongod --fork --logpath /var/log/mongod.log --port 27017 --dbpath /data/swarmmanager && mongo /scripts/createSwarmManagerDB.js
RUN mkdir /log
RUN mongod --fork --logpath /log/mongod.log --port 27017 --dbpath /data && mongo /scripts/createSwarmManagerDB.js

ENTRYPOINT mongod --auth --port 27017 --dbpath /data/swarmmanager
ENTRYPOINT mongod --auth --port 27017 --dbpath /data
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.SignatureException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -84,7 +85,7 @@ Authentication getAuthentication(HttpServletRequest request) {
User user = userRepository.findByUsername(username);
return new UsernamePasswordAuthenticationToken(user.getUsername(), null, user.getAuthorities());
}
} catch (ExpiredJwtException e) {
} catch (ExpiredJwtException | SignatureException e) {
return null;
} catch (IllegalArgumentException e) {
if (!StringUtils.equals(e.getMessage(), "A signing key must be specified if the specified JWT is digitally signed.")) {
Expand Down
6 changes: 4 additions & 2 deletions swarmmanagerfrontend/src/app/guards/admin.guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { AuthService } from '../services/auth/auth.service';
import { CanActivate } from '@angular/router';
import { UserService } from '../services/user/user.service';
import { Observable } from 'rxjs';
@Injectable()
Expand All @@ -19,6 +18,9 @@ export class AdminGuard implements CanActivate {
observer.next(false);
}
observer.complete();
},
() => {
observer.complete();
});
});
}
Expand Down
6 changes: 4 additions & 2 deletions swarmmanagerfrontend/src/app/guards/visitor.guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { AuthService } from '../services/auth/auth.service';
import { CanActivate } from '@angular/router';
import { UserService } from '../services/user/user.service';
import { Observable } from 'rxjs';
@Injectable()
Expand All @@ -19,6 +18,9 @@ export class VisitorGuard implements CanActivate {
observer.next(false);
}
observer.complete();
},
() => {
observer.complete();
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AuthService } from '../services/auth/auth.service';
import { Injectable } from '@angular/core';
Expand All @@ -16,13 +16,11 @@ export class AuthInterceptor implements HttpInterceptor {
}
return next.handle(req).catch(
err => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401 || err.status === 403) {
AuthService.removeToken();
this.router.navigate(['/login']);
}
return Observable.throw(err);
}
});
}
}
16 changes: 6 additions & 10 deletions swarmmanagerfrontend/src/app/services/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ export class UserService {
}
).catch(
(err) => {
console.log(err);
if (err instanceof HttpErrorResponse) {
if (err.status === 401 || err.status === 403) {
this.router.navigate(['/login']);
}
} else {
if (err.status != 401 && err.status != 403) {
this.snackbarService.showError('Error loading user data, if the problem persists please contact the administrator.');
}
reject();
reject(err);
}
);
} else {
Expand Down Expand Up @@ -142,9 +137,10 @@ export class UserService {
user.roles = data.roles;
resolve(user);
},
(err: HttpErrorResponse) => {
this.snackbarService.showError('Error loading user data, if the problem persists please contact the administrator');
console.log('Error fetching user data: ' + err.message);
(err: any) => {
if (err) {
console.log('Error fetching user data: ' + err.message);
}
reject(err);
}
);
Expand Down

0 comments on commit b2988a6

Please sign in to comment.