use of org.apache.syncope.common.rest.api.service.UserSelfService in project syncope by apache.
the class JWTITCase method noneSignature.
@Test
public void noneSignature() throws ParseException {
// Get an initial token
SyncopeClient localClient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
AccessTokenService accessTokenService = localClient.getService(AccessTokenService.class);
Response response = accessTokenService.login();
String token = response.getHeaderString(RESTHeaders.TOKEN);
assertNotNull(token);
JwsJwtCompactConsumer consumer = new JwsJwtCompactConsumer(token);
String tokenId = consumer.getJwtClaims().getTokenId();
// Create a new token using the Id of the first token
JwtClaims jwtClaims = new JwtClaims();
jwtClaims.setTokenId(tokenId);
jwtClaims.setSubject(consumer.getJwtClaims().getSubject());
jwtClaims.setIssuedAt(consumer.getJwtClaims().getIssuedAt());
jwtClaims.setIssuer(consumer.getJwtClaims().getIssuer());
jwtClaims.setExpiryTime(consumer.getJwtClaims().getExpiryTime());
jwtClaims.setNotBefore(consumer.getJwtClaims().getNotBefore());
JwsHeaders jwsHeaders = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.NONE);
JwtToken jwtToken = new JwtToken(jwsHeaders, jwtClaims);
JwsJwtCompactProducer producer = new JwsJwtCompactProducer(jwtToken);
JwsSignatureProvider jwsSignatureProvider = new NoneJwsSignatureProvider();
String signed = producer.signWith(jwsSignatureProvider);
SyncopeClient jwtClient = clientFactory.create(signed);
UserSelfService jwtUserSelfService = jwtClient.getService(UserSelfService.class);
try {
jwtUserSelfService.read();
fail("Failure expected on no signature");
} catch (AccessControlException ex) {
// expected
}
}
use of org.apache.syncope.common.rest.api.service.UserSelfService in project syncope by apache.
the class JWTITCase method tokenValidation.
@Test
public void tokenValidation() throws ParseException {
// Get an initial token
SyncopeClient localClient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
AccessTokenService accessTokenService = localClient.getService(AccessTokenService.class);
Response response = accessTokenService.login();
String token = response.getHeaderString(RESTHeaders.TOKEN);
assertNotNull(token);
JwsJwtCompactConsumer consumer = new JwsJwtCompactConsumer(token);
String tokenId = consumer.getJwtClaims().getTokenId();
// Create a new token using the Id of the first token
Date now = new Date();
long currentTime = now.getTime() / 1000L;
Calendar expiry = Calendar.getInstance();
expiry.setTime(now);
expiry.add(Calendar.MINUTE, 5);
JwtClaims jwtClaims = new JwtClaims();
jwtClaims.setTokenId(tokenId);
jwtClaims.setSubject(ADMIN_UNAME);
jwtClaims.setIssuedAt(currentTime);
jwtClaims.setIssuer(JWT_ISSUER);
jwtClaims.setExpiryTime(expiry.getTime().getTime() / 1000L);
jwtClaims.setNotBefore(currentTime);
JwsHeaders jwsHeaders = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.HS512);
JwtToken jwtToken = new JwtToken(jwsHeaders, jwtClaims);
JwsJwtCompactProducer producer = new JwsJwtCompactProducer(jwtToken);
JwsSignatureProvider jwsSignatureProvider = new HmacJwsSignatureProvider(JWS_KEY.getBytes(), SignatureAlgorithm.HS512);
String signed = producer.signWith(jwsSignatureProvider);
SyncopeClient jwtClient = clientFactory.create(signed);
UserSelfService jwtUserSelfService = jwtClient.getService(UserSelfService.class);
jwtUserSelfService.read();
}
use of org.apache.syncope.common.rest.api.service.UserSelfService in project syncope by apache.
the class SyncopeClient method self.
public Pair<Map<String, Set<String>>, UserTO> self() {
// Explicitly disable header value split because it interferes with JSON deserialization below
UserSelfService service = getService(UserSelfService.class);
WebClient.getConfig(WebClient.client(service)).getRequestContext().put(HEADER_SPLIT_PROPERTY, false);
Response response = service.read();
if (response.getStatusInfo().getStatusCode() != Response.Status.OK.getStatusCode()) {
Exception ex = exceptionMapper.fromResponse(response);
if (ex != null) {
throw (RuntimeException) ex;
}
}
try {
return Pair.of(OBJECT_MAPPER.readValue(response.getHeaderString(RESTHeaders.OWNED_ENTITLEMENTS), new TypeReference<Map<String, Set<String>>>() {
}), response.readEntity(UserTO.class));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
Aggregations