Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYNCOPE-1772] Adding MfaTrustedDevice to AuhtProfile #502

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.syncope.common.lib.wa.GoogleMfaAuthAccount;
import org.apache.syncope.common.lib.wa.GoogleMfaAuthToken;
import org.apache.syncope.common.lib.wa.ImpersonationAccount;
import org.apache.syncope.common.lib.wa.MfaTrustedDevice;
import org.apache.syncope.common.lib.wa.U2FDevice;
import org.apache.syncope.common.lib.wa.WebAuthnDeviceCredential;

Expand Down Expand Up @@ -95,6 +96,21 @@
return this;
}

public AuthProfileTO.Builder mfaTrustedDevice(final MfaTrustedDevice device) {
instance.getMfaTrustedDevices().add(device);
return this;
}

public AuthProfileTO.Builder mfaTrustedDevices(final MfaTrustedDevice... devices) {
instance.getMfaTrustedDevices().addAll(List.of(devices));
return this;
}

public AuthProfileTO.Builder mfaTrustedDevices(final Collection<MfaTrustedDevice> devices) {
instance.getMfaTrustedDevices().addAll(devices);
return this;
}

public AuthProfileTO.Builder credential(final WebAuthnDeviceCredential credential) {
instance.getWebAuthnDeviceCredentials().add(credential);
return this;
Expand Down Expand Up @@ -127,6 +143,8 @@

private final List<U2FDevice> u2fRegisteredDevices = new ArrayList<>();

private final List<MfaTrustedDevice> mfaTrustedDevices = new ArrayList<>();

private final List<WebAuthnDeviceCredential> webAuthnDeviceCredentials = new ArrayList<>();

@Override
Expand Down Expand Up @@ -172,6 +190,12 @@
return u2fRegisteredDevices;
}

@JacksonXmlElementWrapper(localName = "mfaTrustedDevices")
@JacksonXmlProperty(localName = "mfaTrustedDevice")
public List<MfaTrustedDevice> getMfaTrustedDevices() {
Dismissed Show dismissed Hide dismissed
return mfaTrustedDevices;
}

@JacksonXmlElementWrapper(localName = "credentials")
@JacksonXmlProperty(localName = "credential")
public List<WebAuthnDeviceCredential> getWebAuthnDeviceCredentials() {
Expand All @@ -187,6 +211,7 @@
append(googleMfaAuthTokens).
append(googleMfaAuthAccounts).
append(u2fRegisteredDevices).
append(mfaTrustedDevices).
append(webAuthnDeviceCredentials).
build();
}
Expand All @@ -210,6 +235,7 @@
append(googleMfaAuthTokens, other.googleMfaAuthTokens).
append(googleMfaAuthAccounts, other.googleMfaAuthAccounts).
append(u2fRegisteredDevices, other.u2fRegisteredDevices).
append(mfaTrustedDevices, other.mfaTrustedDevices).
append(webAuthnDeviceCredentials, other.webAuthnDeviceCredentials).
build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.syncope.common.lib.wa;

import java.time.ZonedDateTime;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.syncope.common.lib.BaseBean;

public class MfaTrustedDevice implements BaseBean {

private static final long serialVersionUID = 5120423450725182470L;

private long id;

private String name;

private String deviceFingerprint;

private String recordKey;

private ZonedDateTime recordDate;

private ZonedDateTime expirationDate;

public long getId() {
return id;
}

public void setId(final long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public String getDeviceFingerprint() {
return deviceFingerprint;
}

public void setDeviceFingerprint(final String deviceFingerprint) {
this.deviceFingerprint = deviceFingerprint;
}

public ZonedDateTime getRecordDate() {
return recordDate;
}

public void setRecordDate(final ZonedDateTime recordDate) {
this.recordDate = recordDate;
}

public String getRecordKey() {
return recordKey;
}

public void setRecordKey(final String recordKey) {
this.recordKey = recordKey;
}

public ZonedDateTime getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(final ZonedDateTime expirationDate) {
this.expirationDate = expirationDate;
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.append(id)
.append(name)
.append(deviceFingerprint)
.append(recordDate)
.append(recordKey)
.append(expirationDate)
.toHashCode();
}

@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
MfaTrustedDevice other = (MfaTrustedDevice) obj;
return new EqualsBuilder()
.append(this.id, other.id)
.append(this.name, other.name)
.append(this.deviceFingerprint, other.deviceFingerprint)
.append(this.recordDate, other.recordDate)
.append(this.recordKey, other.recordKey)
.append(this.expirationDate, other.expirationDate)
.isEquals();
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.append("name", name)
.append("deviceFingerprint", deviceFingerprint)
.append("recordDate", recordDate)
.append("recordKey", recordKey)
.append("expirationDate", expirationDate)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.syncope.common.rest.api.beans;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.OffsetDateTime;
import javax.ws.rs.QueryParam;

public class MfaTrustedDeviceQuery extends AbstractQuery {

private static final long serialVersionUID = -7381828286332101171L;

public static class Builder extends AbstractQuery.Builder<MfaTrustedDeviceQuery, MfaTrustedDeviceQuery.Builder> {

@Override
protected MfaTrustedDeviceQuery newInstance() {
return new MfaTrustedDeviceQuery();
}

public MfaTrustedDeviceQuery.Builder id(final Long id) {
getInstance().setId(id);
return this;
}

public MfaTrustedDeviceQuery.Builder recordKey(final String recordKey) {
getInstance().setRecordKey(recordKey);
return this;
}

public MfaTrustedDeviceQuery.Builder principal(final String principal) {
getInstance().setPrincipal(principal);
return this;
}

public MfaTrustedDeviceQuery.Builder expirationDate(final OffsetDateTime date) {
getInstance().setExpirationDate(date);
return this;
}

public MfaTrustedDeviceQuery.Builder recordDate(final OffsetDateTime date) {
getInstance().setRecordDate(date);
return this;
}
}

private Long id;

private String recordKey;

private OffsetDateTime expirationDate;

private OffsetDateTime recordDate;

private String principal;

@Parameter(name = "id", in = ParameterIn.QUERY, schema =
@Schema(implementation = Long.class))
public Long getId() {
return id;
}

@QueryParam("id")
public void setId(final Long id) {
this.id = id;
}

@Parameter(name = "recordKey", in = ParameterIn.QUERY, schema =
@Schema(implementation = String.class))
public String getRecordKey() {
return recordKey;
}

@QueryParam("recordKey")
public void setRecordKey(final String recordKey) {
this.recordKey = recordKey;
}

@Parameter(name = "expirationDate", in = ParameterIn.QUERY, schema =
@Schema(implementation = OffsetDateTime.class))
public OffsetDateTime getExpirationDate() {
return expirationDate;
}

@QueryParam("expirationDate")
public void setExpirationDate(final OffsetDateTime expirationDate) {
this.expirationDate = expirationDate;
}

@Parameter(name = "recordDate", in = ParameterIn.QUERY, schema =
@Schema(implementation = OffsetDateTime.class))
public OffsetDateTime getRecordDate() {
return recordDate;
}

@QueryParam("recordDate")
public void setRecordDate(final OffsetDateTime recordDate) {
this.recordDate = recordDate;
}

@Parameter(name = "principal", in = ParameterIn.QUERY, schema =
@Schema(implementation = String.class))
public String getPrincipal() {
return principal;
}

@QueryParam("principal")
public void setPrincipal(final String principal) {
this.principal = principal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.syncope.common.rest.api.service.wa;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.constraints.NotNull;
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.wa.MfaTrustedDevice;
import org.apache.syncope.common.rest.api.RESTHeaders;
import org.apache.syncope.common.rest.api.beans.MfaTrustedDeviceQuery;
import org.apache.syncope.common.rest.api.service.JAXRSService;

@Tag(name = "WA")
@SecurityRequirements({
@SecurityRequirement(name = "BasicAuthentication"),
@SecurityRequirement(name = "Bearer") })
@Path("wa/mfaTrustedDevice")
public interface MfaTrustStorageService extends JAXRSService {
Dismissed Show dismissed Hide dismissed

@GET
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
PagedResult<MfaTrustedDevice> search(@BeanParam MfaTrustedDeviceQuery query);

@POST
@Path("{principal}")
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
void create(@NotNull @PathParam("principal") String principal, @NotNull MfaTrustedDevice device);

@DELETE
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
void delete(@BeanParam MfaTrustedDeviceQuery query);
}
Loading