2015-04-22 13:20:28 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
2020-04-23 10:06:55 +02:00
|
|
|
*
|
2015-04-22 13:20:28 +02:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2020-04-23 10:06:55 +02:00
|
|
|
*
|
2015-04-22 13:20:28 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2020-04-23 10:06:55 +02:00
|
|
|
*
|
2015-04-22 13:20:28 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2014-08-04 00:24:57 +02:00
|
|
|
*/
|
|
|
|
package li.strolch.rest.filters;
|
|
|
|
|
|
|
|
import static li.strolch.rest.StrolchRestfulConstants.STROLCH_CERTIFICATE;
|
|
|
|
|
2022-12-15 20:25:57 +01:00
|
|
|
import jakarta.ws.rs.container.ContainerRequestContext;
|
|
|
|
import jakarta.ws.rs.container.ContainerResponseContext;
|
|
|
|
import jakarta.ws.rs.container.ContainerResponseFilter;
|
2023-03-14 09:18:15 +01:00
|
|
|
import jakarta.ws.rs.core.Response;
|
2022-12-15 20:25:57 +01:00
|
|
|
import jakarta.ws.rs.ext.Provider;
|
2014-08-04 00:24:57 +02:00
|
|
|
|
2016-06-26 11:38:41 +02:00
|
|
|
import li.strolch.privilege.model.Certificate;
|
2020-04-23 10:06:55 +02:00
|
|
|
import li.strolch.rest.RestfulStrolchComponent;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2014-08-04 00:24:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Reto Breitenmoser <reto.breitenmoser@4trees.ch>
|
|
|
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
|
|
*/
|
|
|
|
@Provider
|
2017-03-01 01:41:59 +01:00
|
|
|
public class AuthenticationResponseFilter implements ContainerResponseFilter {
|
2014-08-04 00:24:57 +02:00
|
|
|
|
2020-04-23 10:06:55 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(AuthenticationResponseFilter.class);
|
|
|
|
|
2014-08-04 00:24:57 +02:00
|
|
|
@Override
|
2020-11-26 11:10:21 +01:00
|
|
|
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
|
2014-08-04 00:24:57 +02:00
|
|
|
|
|
|
|
Certificate cert = (Certificate) requestContext.getProperty(STROLCH_CERTIFICATE);
|
2020-04-23 10:06:55 +02:00
|
|
|
if (cert == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cert.getUsage().isSingle()) {
|
|
|
|
logger.info("Invalidating single usage certificate for " + cert.getUsername());
|
|
|
|
RestfulStrolchComponent.getInstance().getSessionHandler().invalidate(cert);
|
2020-11-26 11:10:21 +01:00
|
|
|
} else if (cert.getUsage().isSetPassword()) {
|
2023-03-14 09:18:15 +01:00
|
|
|
// if not acceptable, then user can try again
|
|
|
|
if (responseContext.getStatusInfo().toEnum() != Response.Status.NOT_ACCEPTABLE) {
|
|
|
|
logger.info("Invalidating SET_PASSWORD usage certificate for " + cert.getUsername());
|
|
|
|
RestfulStrolchComponent.getInstance().getSessionHandler().invalidate(cert);
|
|
|
|
}
|
2014-08-04 00:24:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|